Skip to content

Instantly share code, notes, and snippets.

@jdickey
Last active December 14, 2015 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdickey/5079646 to your computer and use it in GitHub Desktop.
Save jdickey/5079646 to your computer and use it in GitHub Desktop.
My old-fashioned Ruby script for creating a new Rails project. Updated to 3.2.12. *NOTE* that the Gemfile references a couple of my forks of useful repos; I encourage others to maintain their own forks, just so you can know what changes when.
#!/usr/bin/env ruby
require 'git'
require 'logger'
BASE_SUBDIR = '/src/rails'
$logger = Logger.new STDOUT
$logger.level = Logger::INFO
if ARGV.empty? then
puts "Must specify project name!"
exit
else
PROJECT_NAME=ARGV[0]
end
$content = {}
$content[:cruise_rake] = %q(
task :cruise do
system 'rake db:reset db:test:clone teabag'
system 'rake spec coverage testoutdated'
end
)
$content[:dotrspec] = %q(
--colour
-f d
)
$content[:testoutdated_rake] = %q(
task :testoutdated do
run_check = defined?(RAILS_ENV) && RAILS_ENV != 'production'
RAILS_ENV = 'test'
GATE_FILE = '/tmp/run_test_outdated'
if run_check then
require 'FileUtils'
run_check = File.file? GATE_FILE
end
if run_check then
sh %{bundle-outdated}
else
puts "Skipping check for outdated Gems in bundle. To enable the check, touch #{GATE_FILE} or run 'bundle outdated' explicitly."
end
end
)
$content[:gemfile] = %q(
source 'https://rubygems.org'
gem 'rails', '3.2.12'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# gem 'haml'
gem 'bootstrap-sass'
gem 'haml-rails'
gem 'configurability'
gem 'loggability'
gem 'yajl-ruby'
gem 'validates_email_format_of'
gem 'thin'
group :production do
gem 'secret_token_replacer', :git => 'git://github.com/jdickey/secret_token_replacer.git'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'teabag'
gem 'twitter_bootstrap_form_for'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem 'execjs'
gem 'uglifier'
gem 'jquery-rails'
end
# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
end
#
group :development, :test do
gem 'awesome_print'
gem 'inherited_resources'
gem 'quiet_assets'
gem 'rspec'
gem 'rspec-rails'
gem 'rspec-html-matchers'
gem 'rspec-http'
gem 'capybara'
# gem 'fuubar'
gem 'pry'
gem 'pry-rails'
gem 'simplecov'
gem 'factory_girl_rails'
gem 'jasmine-fixtures'
# gem 'jasmine-fixtures', :git => 'git://github.com/jdickey/jasmine-fixtures.git'
# gem 'pry-doc'
# gem 'pry-nav'
# gem 'pry-remote'
# gem 'pry-stack_explorer'
# gem 'pry-exception_explorer'
end
)
$content[:gitignore] = %q(
*.js.js
*.sublime-project
*.sublime-workspace
*.tmproj
.bundle
.sass-cache/
coverage
db/*.sqlite3
doc/
docs
internal/
log/*.log
tmp/
vendor/cache/*
vendor/cache/**/
vendor/ruby
./config/initializers/secret_token.rb
)
$content[:dummy_spec] = %q(
require 'spec_helper'
describe "Dummy" do
pending "Get some specs written, and then delete spec/dummy_spec.rb"
end
)
def create_project(project_name)
Dir.chdir(Dir.home() + "/src/rails")
if Dir.exists? project_name then
puts "#{project_name} already exists!"
exit
end
system("rails new #{project_name} -T --skip-bundle")
$logger.info "Project #{project_name} created; skipped bundle."
Dir.chdir(project_name)
end
def output_to_file(key, mode, filename)
open(filename, mode) do |f|
f.puts $content[key]
end
end
def create_rake_task
output_to_file(:cruise_rake, 'w', 'lib/tasks/cruise.rake')
$logger.info "lib/tasks/cruise.rake created"
output_to_file(:testoutdated_rake, 'w', 'lib/tasks/testoutdated.rake')
$logger.info "lib/tasks/testoutdated.rake created"
end
def generate_spec_dir
system("rails generate rspec:install -q")
output_to_file(:dotrspec, 'w', '.rspec')
$logger.info "RSpec support initialised"
output_to_file(:dummy_spec, 'w', 'spec/dummy_spec.rb')
$logger.info "Dummy specfile created"
end
def setup_git
output_to_file(:gitignore, 'w', '.gitignore')
g = Git.init
g.add '.'
g.commit "Initial commit."
$logger.info "Git initalised and initial commit made."
end
def init_teabag
system "rails generate teabag:install"
end
def update_gemfile
output_to_file(:gemfile, 'w', 'Gemfile')
$logger.info "Gemfile updated"
system("sync;sync;sync;bundle install --path vendor && bundle package --all")
end
create_project PROJECT_NAME
update_gemfile
create_rake_task
generate_spec_dir
init_teabag
setup_git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment