foca / utility_scripts
- Source
- Commits
- Network (5)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
utility_scripts / railify
| af63fa36 » | foca | 2008-03-23 | 1 | #!/usr/bin/env ruby | |
| 2 | |||||
| 3 | # Generate a rails app (using EDGE rails), set up a git repo for it, install GemsOnRails, | ||||
| 4f5b41a0 » | foca | 2008-03-23 | 4 | # haml, rspec, and make_resourceful | |
| af63fa36 » | foca | 2008-03-23 | 5 | # | |
| 6 | # USAGE: $0 some_app_name | ||||
| f8cb62c1 » | foca | 2008-03-24 | 7 | # | |
| 8 | # See http://github.com/foca/utility_scripts/ for the latest version | ||||
| 9 | # Released under a WTFP license (http://sam.zoy.org/wtfpl/) | ||||
| af63fa36 » | foca | 2008-03-23 | 10 | ||
| 11 | RAILS_SVN_CHECKOUT = '/Users/foca/Rails/_rails' | ||||
| 12 | |||||
| 13 | module Helpers | ||||
| 82b1a549 » | foca | 2008-03-24 | 14 | LINE = 80 | |
| af63fa36 » | foca | 2008-03-23 | 15 | ||
| 16 | def announcing(msg) | ||||
| 17 | print msg | ||||
| 18 | yield | ||||
| 19 | print "." * (LINE - msg.size - 6) | ||||
| 20 | puts "\e[32m[DONE]\e[0m" | ||||
| 21 | end | ||||
| 22 | |||||
| 23 | def silent(command) | ||||
| 24 | system "#{command} &> /dev/null" | ||||
| 25 | end | ||||
| 26 | |||||
| 27 | def templates | ||||
| 28 | { :gitignore => %w[config/database.yml tmp/* log/*.log db/*.sqlite3 db/schema.rb public/stylesheets/application.css] * "\n", | ||||
| 29 | :routes => ["ActionController::Routing::Routes.draw do |map|", "end"] * "\n" } | ||||
| 30 | end | ||||
| 31 | |||||
| 32 | def git(message) | ||||
| 33 | silent "git add ." | ||||
| 34 | silent "git commit -m '#{message}'" | ||||
| 35 | end | ||||
| 36 | |||||
| 37 | def braid(repo, dir, type="svn") | ||||
| 38 | silent "braid add #{repo} --type #{type} #{dir}" | ||||
| 39 | silent "git merge braid/track" | ||||
| 40 | end | ||||
| 41 | |||||
| 42 | def rake(task, args={}) | ||||
| 9cbd966a » | foca | 2008-03-24 | 43 | args = args.map {|name,value| "#{name.to_s.upcase}=#{value}"}.join(" ") | |
| af63fa36 » | foca | 2008-03-23 | 44 | silent "rake #{task} #{args}" | |
| 45 | end | ||||
| 46 | end | ||||
| 47 | |||||
| 48 | if __FILE__ == $0 | ||||
| 49 | include Helpers | ||||
| 50 | |||||
| 51 | app_name = ARGV.first | ||||
| 52 | |||||
| 53 | announcing "Fetching EDGE rails" do | ||||
| 54 | Dir.chdir(RAILS_SVN_CHECKOUT) { silent "svn update" } | ||||
| 55 | end | ||||
| 56 | |||||
| 57 | announcing "Creating application layout" do | ||||
| 58 | silent "ruby #{RAILS_SVN_CHECKOUT}/railties/bin/rails #{app_name}" | ||||
| 59 | end | ||||
| 60 | |||||
| 61 | Dir.chdir(app_name) do | ||||
| 62 | announcing "Setting up rails app" do | ||||
| 63 | silent "rm README" | ||||
| 64 | silent "rm public/index.html" | ||||
| 65 | silent "rm log/*.log" | ||||
| 66 | silent "rm public/images/rails.png" | ||||
| 67 | silent "cp config/database.{,sample.}yml" | ||||
| 68 | silent "rm -r test" | ||||
| 69 | File.open("config/routes.rb", "w") {|f| f << templates[:routes] } | ||||
| 70 | end | ||||
| 71 | |||||
| 72 | announcing "Creating databases" do | ||||
| 73 | rake "db:create" | ||||
| 74 | rake "db:create", :rails_env => "test" | ||||
| 75 | end | ||||
| 76 | |||||
| 77 | announcing "Configuring git repo" do | ||||
| 78 | silent "git init" | ||||
| 79 | File.open(".gitignore", "w") {|f| f << templates[:gitignore] } | ||||
| 80 | silent "touch {tmp,log}/.gitignore" | ||||
| 81 | git "Basic rails app structure" | ||||
| 82 | end | ||||
| 83 | |||||
| 84 | announcing "Freezing rails" do | ||||
| 85 | braid "http://dev.rubyonrails.org/svn/rails/trunk", "vendor/rails" | ||||
| 86 | end | ||||
| 87 | |||||
| 88 | announcing "Installing GemsOnrails" do | ||||
| 89 | silent "gemsonrails" | ||||
| 90 | git "Froze GemsOnRails plugin" | ||||
| 91 | end | ||||
| 92 | |||||
| 93 | announcing "Installing haml" do | ||||
| 94 | silent "haml --rails ." | ||||
| 95 | rake "gems:freeze", :gem => "haml" | ||||
| 96 | git "Froze haml gem and plugin" | ||||
| 97 | end | ||||
| 98 | |||||
| 99 | announcing "Installing RSpec" do | ||||
| 100 | braid "http://rspec.rubyforge.org/svn/trunk/rspec", "vendor/plugins/rspec" | ||||
| 101 | braid "http://rspec.rubyforge.org/svn/trunk/rspec_on_rails", "vendor/plugins/rspec_on_rails" | ||||
| 102 | end | ||||
| 103 | |||||
| 104 | announcing "Generating RSpec base files" do | ||||
| 105 | silent "script/generate rspec" | ||||
| 106 | git "Added RSpec base files" | ||||
| 107 | end | ||||
| 108 | |||||
| 109 | announcing "Installing make_resourceful" do | ||||
| 110 | braid "http://svn.hamptoncatlin.com/make_resourceful/trunk", "vendor/plugins/make_resourceful" | ||||
| 111 | end | ||||
| 112 | end | ||||
| 113 | |||||
| 114 | end | ||||
