Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script to initialise skeleton Ruby (not Rails) project. Pass in the name of the project and it will create the file structure and some initial files, as per this tutorial: http://learnrubythehardway.org/book/ex46.html. Also initialises the folder as a git repository and does an initial commit. Finally, the script runs a smoke test to ensure…
#!/bin/bash
name=$1
if [[ -z $name ]]; then
echo "Please specify a name for the Ruby project"
exit
fi
# Setup directory structure
mkdir $name
cd $name
mkdir bin data doc ext tests lib lib/$name
# Create empty files
touch Rakefile
touch $name.gemspec
touch bin/$name # TODO: Check: Is this file supposed to be empty?
touch lib/$name.rb # TODO: Check: Is this file supposed to be empty?
touch tests/test_$name.rb
# Add content to files
# Rakefile
cat >Rakefile << EOL
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs << "tests"
t.test_files = FileList['tests/test*.rb']
t.verbose = true
end
EOL
# Gemspec
cat >$name.gemspec << EOL
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Gem::Specification.new do |spec|
spec.name = '$name'
spec.version = '0.0.1'
spec.authors = ["Your Name"]
spec.email = ["yourname@example.com"]
spec.summary = %q{Short summary of your project}
spec.description = %q{Longer description of your project.}
spec.homepage = "http://domainforproject.com/"
spec.license = "MIT"
spec.files = ['lib/$name.rb']
spec.executables = ['bin/$name']
spec.test_files = ['tests/test_$name.rb']
spec.require_paths = ["lib"]
end
EOL
# Tests
cat >tests/test_$name.rb << EOL
require "./lib/$name.rb"
require "test/unit"
class Test$name < Test::Unit::TestCase
def test_sample
assert_equal(4, 2+2)
end
end
EOL
# Setup as a git repository
git init
git add --all
git commit -m "Initial commit of Ruby project $name"
# Run smoke test
rake test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.