Created
October 3, 2008 18:28
-
-
Save bkeepers/14606 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# Generate a rails app (using EDGE rails), set up a git repo for it, and install common plugins | |
# | |
# USAGE: $0 some_app_name | |
# | |
# Adapted from http://github.com/foca/utility_scripts/ | |
# Released under a WTFP license (http://sam.zoy.org/wtfpl/) | |
RAILS_DIR = File.expand_path('~/.rails') | |
SUBMODULES = { | |
'vendor/rails' => 'git://github.com/rails/rails.git', | |
'vendor/plugins/rspec' => 'git://github.com/dchelimsky/rspec.git', | |
'vendor/plugins/rspec_on_rails' => 'git://github.com/dchelimsky/rspec-rails.git', | |
'vendor/plugins/rspec_on_rails_matchers' => 'git://github.com/brandon/rspec-on-rails-matchers.git', | |
'vendor/plugins/awesomeness' => 'git://github.com/collectiveidea/awesomeness.git', | |
'vendor/plugins/exception_notification' => 'git://github.com/pager/exception_notification.git', | |
'vendor/plugins/action_mailer_optional_tls' => 'git://github.com/collectiveidea/action_mailer_optional_tls.git' | |
} | |
GITIGNORE = %w[config/database.yml tmp/* log/*.log db/*.sqlite3 .DS_Store .rake_tasks backups coverage] * "\n" | |
ACTION_MAILER = <<-EOF | |
ActionMailer::Base.smtp_settings = { | |
:address => 'smtp.example.com', | |
:domain => 'foobar.com', | |
:port => 587, | |
:authentication => :plain, | |
:user_name => 'user@example.com', | |
:password => 'foobar', | |
:tls => true | |
} | |
ExceptionNotifier.exception_recipients = %w(developers@example.com) | |
ExceptionNotifier.email_prefix = "[:PROJECT:] " | |
ExceptionNotifier.sender_address = %("Application Error" <developers@example.com>) | |
EOF | |
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 git(message) | |
silent "git add ." | |
silent "git commit -m '#{message}'" | |
end | |
def rake(task, args={}) | |
args = args.map {|name,value| "#{name.to_s.upcase}=#{value}"}.join(" ") | |
silent "rake #{task} #{args}" | |
end | |
end | |
if __FILE__ == $0 | |
include Helpers | |
app_name = ARGV.first | |
announcing "Fetching Edge Rails" do | |
if File.exists?(RAILS_DIR) | |
Dir.chdir(RAILS_DIR) { `git pull` } | |
else | |
`git clone git://github.com/rails/rails.git #{RAILS_DIR}` | |
end | |
end | |
announcing "Creating application layout" do | |
silent "ruby #{RAILS_DIR}/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" | |
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 << GITIGNORE } | |
silent "touch {tmp,log}/.gitignore" | |
git "Initial Rails app" | |
end | |
announcing "Installing submodules" do | |
SUBMODULES.each do |path,repo| | |
`git submodule add #{repo} #{path}` | |
end | |
git "Adding submodules" | |
end | |
announcing "Generating RSpec base files" do | |
silent "script/generate rspec" | |
git "Generating RSpec" | |
end | |
announcing "Configuring email" do | |
File.open('config/initializers/email.rb', 'w+') {|f| f << ACTION_MAILER.gsub(':PROJECT:', app_name.upcase)} | |
git "Configuring email" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment