public
Fork of patmcnally/utility_scripts
Description: Some utility scripts (the stuff I keep in ~/bin)
Clone URL: git://github.com/patrickelder/utility_scripts.git
utility_scripts / railify
100755 121 lines (96 sloc) 3.033 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env ruby
 
# Generate a rails app (using EDGE rails), set up a git repo for it, install GemsOnRails,
# haml, rspec, and make_resourceful
#
# USAGE: $0 some_app_name
#
# See http://github.com/foca/utility_scripts/ for the latest version
# Released under a WTFP license (http://sam.zoy.org/wtfpl/)
 
#RAILS_GIT_CHECKOUT = '/Users/patrickelder/Projects/Rails/git_clones/rails'
 
 
module Helpers
  LINE = 80
 
  def announcing(msg)
    print msg
    begin
      yield
    rescue
      print "." * (LINE - msg.size - 8)
      puts "\e[31m[FAILED]\e[0m"
      Process.exit
      return
    end
    print "." * (LINE - msg.size - 6)
    puts "\e[32m[DONE]\e[0m"
  end
 
  def silent(command)
    unless(system("#{command} &> /dev/null"))
      raise "Command Failed"
    end
  end
 
  def templates
    { :gitignore => %w[config/database.yml tmp/* log/*.log db/*.sqlite3] * "\n" }
  end
 
  def gitci(message)
   silent 'git add .'
   silent "git commit -m '#{message}'"
  end
 
  def braid(repo, dir, type="git")
    silent "braid add #{repo} --type #{type} #{dir}"
    silent "git merge braid/track"
  end
 
  def rake(task, args={})
    args = args.map {|name,value| "#{name.to_s.upcase}=#{value}"}.join(" ")
    silent "rake #{task} #{args}"
  end
 
  def gitsub(repo, dir)
    silent "git submodule add #{repo} #{dir}"
  end
 
end
 
if __FILE__ == $0
  include Helpers
 
  app_name = ARGV.first
 
  #announcing "Updating EDGE rails (git pull)" do
  # Dir.chdir(RAILS_GIT_CHECKOUT) { silent "git pull" }
  #end
 
  announcing "Creating application layout" do
    silent "rails -d mysql '#{app_name}'"
  end
 
  Dir.chdir(app_name) do
    announcing "Setting up rails app" do
      silent "rm public/images/rails.png"
    end
 
    announcing "Creating databases" do
      rake "db:create"
      rake "db:create", :rails_env => "test"
    end
 
    announcing "Configuring git repo" do
      silent "git init"
      File.open(".gitignore", "w") {|f| f << templates[:gitignore] }
      gitci "Basic rails app structure"
    end
 
    #announcing "Freezing rails" do
    # rake "rails:freeze:gems"
    # silent "git submodule add git://github.com/rails/rails.git vendor/rails"
    # silent "git submodule init"
    #end
 
    announcing "Installing BackgrounDRB" do
      silent "git submodule add git://github.com/gnufied/backgroundrb.git vendor/plugins/backgroundrb"
      silent "git submodule init"
      gitci "Installed backgroundrb"
    end
    
    announcing "Initializing BackgrounDRB" do
      silent "rake backgroundrb:setup"
      gitci "Initialized backgroundrb"
    end
    
    announcing "Installing RSpec" do
      silent "git submodule add git://github.com/dchelimsky/rspec.git vendor/plugins/rspec"
      silent "git submodule add git://github.com/dchelimsky/rspec-rails.git vendor/plugins/rspec-rails"
      silent "git submodule init"
      gitci "Installed rspec plugin"
    end
 
    announcing "Generating RSpec base files" do
      silent "script/generate rspec"
      gitci "Added RSpec base files"
    end
 
  end
end