make things betterer

This commit is contained in:
John Bintz 2011-08-18 17:37:54 -04:00
parent 7c0f49e931
commit 892ad17e4e
3 changed files with 29 additions and 7 deletions

View File

@ -22,16 +22,18 @@ Installs a bunch of scripts into the `scripts` directory of your project:
## initialize-environment ## initialize-environment
It will also try to run `rake bootstrap`, so add a `:bootstrap` task for things that should happen when you start going It will also try to run `rake bootstrap`, so add a `:bootstrap` task for things that should happen when you start going
(make databases, other stuff, etc, whatever). (make databases, other stuff, etc, whatever). This won't run if the `:bootstrap` task is not there.
## Gemfile.erb?! ## Gemfile.erb?!
Yeah, it's a `Gemfile` with ERB in it: Yeah, it's a `Gemfile` with ERB in it:
``` erb ``` erb
<% if env == "local" %> <% env :local do %>
gem 'guard', :path => '../guard' gem 'guard', :path => '../guard'
<% else %> <% end %>
<% env :remote do %>
gem 'guard', :git => 'git://github.com/johnbintz/guard.git' gem 'guard', :git => 'git://github.com/johnbintz/guard.git'
<% end %> <% end %>
``` ```
@ -39,14 +41,25 @@ Yeah, it's a `Gemfile` with ERB in it:
Use `script/gemfile local` to get at the local ones, and `script/gemfile remote` (or anything, really) to get at the remote ones. Use `script/gemfile local` to get at the local ones, and `script/gemfile remote` (or anything, really) to get at the remote ones.
It then runs `bundle install`. It then runs `bundle install`.
You can also run `penchant gemfile ENV`.
### What environment are you currently using in that Gemfile?
`head -n 1` that puppy, or `penchant gemfile-env`.
## git hook?! ## git hook?!
It runs `script/gemfile remote` then runs `bundle exec rake`. Make sure your default Rake task for the project runs your It runs `penchant gemfile remote` then runs `bundle exec rake`. Make sure your default Rake task for the project runs your
tests and performs any other magic necessary before each commit. tests and performs any other magic necessary before each commit. Your re-environmented Gemfile and Gemfile.lock will be added
to your commit if they've changed.
## How?! ## How?!
* `gem install penchant` * `gem install penchant`
* `cd` to your project directory * `cd` to your project directory
* `penchant install` (can do `--dir=WHEREVER`, too)
And then one of the following:
* `penchant install` for a new project (`--dir=WHEREVER` will install the scripts to a directory other than `$PWD/scripts`)
* `penchant convert` for an existing project (`--dir=WHEVEVER` works here, too)

View File

@ -15,6 +15,15 @@ class PenchantCLI < Thor
Dir[File.join(options[:dir], '**/*')].each { |file| File.chmod(0755, file) } Dir[File.join(options[:dir], '**/*')].each { |file| File.chmod(0755, file) }
end end
desc "convert", "Make an existing project Penchant-isized"
method_options :dir => 'script'
def convert
install
copy_file 'Gemfile', 'Gemfile.erb'
remove_file 'Gemfile'
gemfile(:remote)
end
desc "gemfile ENV", "Switch the gemfile environment" desc "gemfile ENV", "Switch the gemfile environment"
def gemfile(env) def gemfile(env)
Penchant::Gemfile.do_full_env_switch!(env) Penchant::Gemfile.do_full_env_switch!(env)

View File

@ -6,7 +6,7 @@ if [ $(penchant gemfile-env) != "remote" ]; then
unset GIT_DIR unset GIT_DIR
penchant gemfile remote penchant gemfile remote
GIT_DIR=$OLD_GIT_DIR GIT_DIR=$OLD_GIT_DIR
git add Gemfile git add Gemfile*
fi fi
bundle exec rake bundle exec rake