forked from foca/utility_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
railify
executable file
·116 lines (93 loc) · 3.02 KB
/
railify
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
#!/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_SVN_CHECKOUT = '/Users/foca/Rails/_rails'
module Helpers
LINE = 80
def announcing(msg)
print msg
yield
print "." * (LINE - msg.size - 6)
puts "\e[32m[DONE]\e[0m"
end
def silent(command)
system "#{command} &> /dev/null"
end
def templates
{ :gitignore => %w[config/database.yml tmp/* log/*.log db/*.sqlite3 db/schema.rb public/stylesheets/application.css] * "\n",
:routes => ["ActionController::Routing::Routes.draw do |map|", "end"] * "\n" }
end
def git(message)
silent "git add ."
silent "git commit -m '#{message}'"
end
def braid(repo, dir, type="svn")
silent "braid add #{repo} --type #{type} #{dir}"
silent "git merge braid/track"
end
def rake(task, args={})
args = args.inject("") do |list, (name, value)|
list << "#{name.to_s.upcase}=#{value}"
end
silent "rake #{task} #{args}"
end
end
if __FILE__ == $0
include Helpers
app_name = ARGV.first
announcing "Fetching EDGE rails" do
Dir.chdir(RAILS_SVN_CHECKOUT) { silent "svn update" }
end
announcing "Creating application layout" do
silent "ruby #{RAILS_SVN_CHECKOUT}/railties/bin/rails #{app_name}"
end
Dir.chdir(app_name) do
announcing "Setting up rails app" do
silent "rm README"
silent "rm public/index.html"
silent "rm log/*.log"
silent "rm public/images/rails.png"
silent "cp config/database.{,sample.}yml"
silent "rm -r test"
File.open("config/routes.rb", "w") {|f| f << templates[:routes] }
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] }
silent "touch {tmp,log}/.gitignore"
git "Basic rails app structure"
end
announcing "Freezing rails" do
braid "http://dev.rubyonrails.org/svn/rails/trunk", "vendor/rails"
end
announcing "Installing GemsOnrails" do
silent "gemsonrails"
git "Froze GemsOnRails plugin"
end
announcing "Installing haml" do
silent "haml --rails ."
rake "gems:freeze", :gem => "haml"
git "Froze haml gem and plugin"
end
announcing "Installing RSpec" do
braid "http://rspec.rubyforge.org/svn/trunk/rspec", "vendor/plugins/rspec"
braid "http://rspec.rubyforge.org/svn/trunk/rspec_on_rails", "vendor/plugins/rspec_on_rails"
end
announcing "Generating RSpec base files" do
silent "script/generate rspec"
git "Added RSpec base files"
end
announcing "Installing make_resourceful" do
braid "http://svn.hamptoncatlin.com/make_resourceful/trunk", "vendor/plugins/make_resourceful"
end
end
end