Datos personales

miércoles, 22 de enero de 2014

Ruby on Rails automation script for new project

When i started to develop rails applications(short time ago) setup the project was the first: name, database, rvmrc, ruby version, gems and maybe some third-party angular, bootstrap, etc. I get bored quickly, because i had to do it each time for a project in order to practice rails, so i wrote a simple script to do it fast and start to code happy.


To do:

#Install ruby version
$rvm install 2.0.0

Work directory sample bootstrap - postgreSQL
- railsprojects
|- railsnew.sh
|- Gemfile
|- dist/
Setup Gemfile pg & haml

source 'https://rubygems.org'

gem 'rails', '4.0.0'
gem 'pg'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
gem 'haml'

group :test,:development do
  gem 'rspec-rails'
  gem 'pry'
end

group :test do
  gem 'capybara', "2.0.2"
  gem 'fabrication'
  gem "shoulda-matchers"
end

Download bootstrap
$wget https://github.com/twbs/bootstrap/releases/download/v3.0.3/bootstrap-3.0.3-dist.zip
$unzip bootstrap-3.0.3-dist.zip 
Script railsnew.sh
echo "Running"
rails new "$1" --database=postgresql

cp Gemfile $PWD"/$1"
cd $1
echo "$1" > .ruby-gemset
cat .ruby-gemset
echo "$2" > .ruby-version
cat .ruby-version

cp ../dist/js/bootstrap.js  $PWD/app/assets/javascripts/
cp ../dist/css/bootstrap.css  $PWD/app/assets/stylesheets/
Permissions
sudo chmod +x railsnew.sh
To run the script we need to pass 2 parameters "appname" "ruby-version"
#Our ruby list
$rvm list

rvm rubies

=* ruby-1.9.3-p429 [ i686 ]
   ruby-2.0.0-p195-perf [ i686 ]

# => - current
# =* - current && default
#  * - default

Execution & verification
$./railsnew.sh testapp ruby-1.9.3-p429
$cd testapp
$rvm current
$bundle
That's it, you can add/edit what you need for your projects

No hay comentarios:

Publicar un comentario