Created
January 6, 2010 15:48
-
-
Save robmckinnon/270345 to your computer and use it in GitHub Desktop.
rails project setup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ARGV.empty? | |
puts 'usage: ruby setup_project.rb [project_name] [git_user]' | |
return | |
end | |
def cmd text | |
puts text | |
result = `#{text}` | |
puts result | |
result | |
end | |
def do_first_commit project, git_url | |
puts 'create project dir and do first commit' | |
Dir.mkdir project unless File.exists?(project) | |
Dir.chdir project | |
cmd 'git init' | |
cmd 'touch README' | |
cmd 'git add README' | |
cmd 'git commit -m "first commit"' | |
cmd "git remote add origin #{git_url}" | |
cmd 'git push origin master' | |
end | |
require 'fileutils' | |
project = ARGV[0] | |
git_user = ARGV.size > 1 ? ARGV[1] : 'robmckinnon' | |
git_url = "git@github.com:#{git_user}/#{project}.git" | |
result = cmd("git clone #{git_url}") | |
begin | |
if result[/Initialized empty Git repository/] | |
do_first_commit project, git_url | |
else | |
puts "entering #{project}" | |
Dir.chdir project | |
end | |
rescue Exception => e | |
if e.to_s[/No such file or directory/] | |
do_first_commit project, git_url | |
else | |
raise e | |
end | |
end | |
puts "make #{project}/vendor" | |
Dir.mkdir 'vendor' | |
cmd 'git submodule add git://github.com/rails/rails.git vendor/rails' | |
cmd "git commit -m 'imported edge rails as a submodule'" | |
cmd 'git push' | |
puts "make rails app" | |
Dir.chdir('..') | |
cmd "ruby #{project}/vendor/rails/railties/bin/rails #{project} -m http://gist.github.com/270394.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment