make converted gemfiles more useful out of the box

This commit is contained in:
John Bintz 2012-08-13 16:20:50 -04:00
parent df0154a225
commit 3ef5122246
6 changed files with 31 additions and 5 deletions

View File

@ -92,6 +92,12 @@ It then runs `bundle install`.
You can also run `penchant gemfile ENV`. Just straight `penchant gemfile` will rebuild the `Gemfile` from You can also run `penchant gemfile ENV`. Just straight `penchant gemfile` will rebuild the `Gemfile` from
`Gemfile.penchant` for whatever environment the `Gemfile` is currently using. `Gemfile.penchant` for whatever environment the `Gemfile` is currently using.
If you have an existing project, `penchant convert` will convert the `Gemfile` into a `Gemfile.penchant`
and add some bonuses, like defining that anything in `env :local` blocks automatically reference `..`,
ensuring that hooks are always installed when `penchant gemfile` is executed, and adding the `:github` gem property
that lets you pass in the username of the repo to reference that repo:
`gem 'penchant', :github => 'johnbintz'`.
### Deployment mode ### Deployment mode
Use `no_deployment` blocks to indicate gems that shouldn't even appear in `Gemfiles` destined for Use `no_deployment` blocks to indicate gems that shouldn't even appear in `Gemfiles` destined for

View File

@ -36,6 +36,17 @@ class PenchantCLI < Thor
def convert def convert
install install
FileUtils.mv 'Gemfile', 'Gemfile.penchant' FileUtils.mv 'Gemfile', 'Gemfile.penchant'
prepend_to_file 'Gemfile.penchant', <<-RB
# ensure git hooks are always installed
ensure_git_hooks!
# everything in the :local env is assumed to be a sibling directory of this one
defaults_for env(:local), :path => '../%s'
# reference a github repository with gem 'my-gem', :github => 'username'
property :github, :git => 'git://github.com/$1/%s.git'
RB
gemfile(:remote) gemfile(:remote)
end end

View File

@ -22,7 +22,7 @@ Feature: CLI
source :rubygems source :rubygems
""" """
When I run "bin/penchant convert" in the "tmp" directory When I run "bin/penchant convert" in the "tmp" directory
Then the file "tmp/Gemfile.penchant" should have the following content: Then the file "tmp/Gemfile.penchant" should include the following content:
""" """
source :rubygems source :rubygems
""" """

View File

@ -0,0 +1,3 @@
Then /^the file "(.*?)" should include the following content:$/ do |file, string|
File.read(file).should include(string)
end

View File

@ -21,11 +21,17 @@ module Penchant
end end
def self.install! def self.install!
if git?
puts "[penchant] installing git hooks" puts "[penchant] installing git hooks"
Dir['script/hooks/*'].each do |hook| Dir['script/hooks/*'].each do |hook|
FileUtils.ln_sf File.join(Dir.pwd, hook), ".git/hooks/#{File.split(hook).last}" FileUtils.ln_sf File.join(Dir.pwd, hook), "#{GIT_HOOKS_DIR}/#{File.split(hook).last}"
end end
end
end
def self.git?
File.directory?(GIT_HOOKS_DIR)
end end
end end
end end

View File

@ -1,3 +1,3 @@
module Penchant module Penchant
VERSION = "0.2.16" VERSION = "0.2.17"
end end