Created
July 29, 2012 20:39
-
-
Save statonjr/3201726 to your computer and use it in GitHub Desktop.
Create a new Ruby project
This file contains hidden or 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 | |
| require 'fileutils' | |
| # Set the project name | |
| project_name = ARGV[0] | |
| # Make a directory named after the project | |
| puts "Creating directory #{project_name} as Git repository:" | |
| puts | |
| `git init #{project_name}` | |
| # Change into the project directory | |
| FileUtils.cd project_name do | |
| # Create .gitignore | |
| File.open(".gitignore", "w+") do |f| | |
| f.puts ".DS_Store" | |
| f.puts ".bundle/" | |
| f.puts "vendor/" | |
| f.puts "binstubs/" | |
| end | |
| # Create a Gemfile and Rakefile | |
| puts "\tCreating Gemfile" | |
| File.open("Gemfile", "w+") do |f| | |
| f.puts <<-EOS | |
| source :rubygems | |
| gem 'rake' | |
| group :development do | |
| gem 'yard' | |
| gem 'guard' | |
| gem 'yard-guard' | |
| end | |
| group :test do | |
| gem 'rspec' | |
| gem 'cucumber' | |
| end | |
| EOS | |
| end | |
| puts "\tCreating Rakefile" | |
| File.open("Rakefile", "w+") do |f| | |
| f.puts <<-EOS | |
| namespace :test do | |
| desc 'Run RSpec' | |
| task :spec do | |
| bundle exec rspec | |
| end | |
| desc 'Run Cucumber' | |
| task :cucumber do | |
| bundle exec cucumber | |
| end | |
| task :default => 'test:rspec' | |
| end | |
| EOS | |
| end | |
| # Create the lib and subsidiary directories | |
| puts "\tCreating lib directories" | |
| FileUtils.mkdir_p "lib/#{project_name}/ext" | |
| # Create the lib/project_name.rb file | |
| puts "\tCreating lib/#{project_name}.rb" | |
| `touch lib/#{project_name}.rb` | |
| # Create the examples directory | |
| puts "\tCreating examples directory" | |
| FileUtils.mkdir_p "examples" | |
| # Create the spec directory | |
| puts "\tCreating spec directory" | |
| FileUtils.mkdir_p "spec" | |
| File.open("spec/spec_helper.rb", "w+") do |f| | |
| f.puts "require 'lib/#{project_name}'" | |
| end | |
| # Create the features directory | |
| puts "\tCreating features directory" | |
| FileUtils.mkdir_p "features/step_definitions" | |
| FileUtils.mkdir_p "features/support" | |
| `touch features/support/env.rb` | |
| # Create the docs directory | |
| puts "\tCreating docs directory" | |
| FileUtils.mkdir_p "docs" | |
| # Create README | |
| puts "\tCreating README" | |
| File.open("README.md", "w+") do |f| | |
| f.puts <<-EOS | |
| # #{project_name.capitalize} | |
| Write your README first: | |
| http://tom.preston-werner.com/2010/08/23/readme-driven-development.html | |
| # TODO: | |
| - Set up remote Git repository | |
| - Set up continuous integration jobs | |
| EOS | |
| end | |
| end | |
| puts | |
| puts "Done." | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment