add penchant for dev stuff

This commit is contained in:
John Bintz 2012-08-27 09:39:34 -04:00
parent f31dd0f3d4
commit aef76fac19
10 changed files with 150 additions and 3 deletions

10
Gemfile
View File

@ -1,4 +1,8 @@
source 'https://rubygems.org' # generated by penchant, environment: remote
source "https://rubygems.org"
# Specify your gem's dependencies in bullseye.gemspec
gemspec gemspec
gem "rake"
gem "capybara"
gem "cucumber"
gem "rspec"
gem "cuke-pack", {:git=>"git://github.com/johnbintz/cuke-pack.git"}

25
Gemfile.penchant Normal file
View File

@ -0,0 +1,25 @@
# 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'
source 'https://rubygems.org'
# Specify your gem's dependencies in bullseye.gemspec
gemspec
gem 'rake'
gems 'capybara', 'cucumber', 'rspec'
env :local do
gem 'cuke-pack'
end
env :remote do
gem 'cuke-pack', :github => 'johnbintz'
end

View File

@ -60,3 +60,9 @@ Want to target that page in your Sass? Use a little string interpolation and a f
``` ```
Piece of cake. Piece of cake.
## Hacking
_You'll need to install [Penchant](http://github.com/johnbintz/penchant) to mess with the Gemfile
during development._

View File

@ -1,2 +1,3 @@
#!/usr/bin/env rake #!/usr/bin/env rake
require "bundler/gem_tasks" require "bundler/gem_tasks"

11
script/gemfile Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'penchant'
if Penchant::Gemfile.do_full_env_switch!(ARGV[0])
puts "Gemfile switched to #{ARGV[0]}"
else
exit 0
end

40
script/hooks/commit-msg Executable file
View File

@ -0,0 +1,40 @@
#!/bin/bash
msg=$(cat $1)
OLD_GIT_DIR=$GIT_DIR
# lion appears to insert git paths before everything else. ensure rvm can
# bust through, at the very least.
if [ ! -z "$MY_RUBY_HOME" ]; then
PATH="$MY_RUBY_HOME/bin:$PATH"
fi
if [ ! -z "$GEM_PATH" ]; then
oifs="$IFS"
while IFS=":" read -ra GEM_PATHS; do
FIXED_GEM_PATH=""
for i in "${GEM_PATHS[@]}"; do
FIXED_GEM_PATH="$FIXED_GEM_PATH:${i}/bin"
done
done <<< "$GEM_PATH"
IFS="$oifs"
PATH="$FIXED_GEM_PATH:$PATH"
fi
if [[ "${msg}" != *"[ci skip]"* ]]; then
if [ "$(penchant gemfile-env)" != "remote" ]; then
unset GIT_DIR
penchant gemfile remote
GIT_DIR=$OLD_GIT_DIR
fi
if [ $(bundle exec rake -P | grep default | wc -l) -ne 0 ]; then
bundle exec rake
R=$?
if [ $R -ne 0 ]; then exit $R; fi
else
echo "[penchant] No default Rake task found! Add one if you want to run tests before committing."
fi
fi

5
script/hooks/post-commit Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
unset GIT_DIR
penchant gemfile remote --switch-back

14
script/hooks/pre-commit Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
if [ $(bundle exec rake -P | grep preflight_check | wc -l) -ne 0 ]; then
bundle exec rake preflight_check
R=$?
if [ $R -ne 0 ]; then exit $R; fi
fi
unset GIT_DIR
penchant gemfile remote --deployment
GIT_DIR=$OLD_GIT_DIR
git add Gemfile*
exit 0

35
script/initialize-environment Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env ruby
if File.file?('Gemfile.erb')
pwd = Dir.pwd
Dir.chdir '..' do
File.readlines(File.join(pwd, 'Gemfile.erb')).find_all { |line| line[':git'] }.each do |line|
repo = line[%r{:git => (['"])([^'"]+)\1}, 2]
puts "Installing #{repo}"
system %{git clone #{repo}}
end
end
puts "Bundling for local environment"
system %{script/gemfile local}
else
puts "Bundling..."
system %{bundle}
end
puts "Installing git hooks"
system %{script/install-git-hooks}
bundle = File.file?('Gemfile') ? 'bundle exec' : ''
command = [ bundle, 'rake', '-s', '-T', 'bootstrap' ]
if !(%x{#{command.join(' ')}}).empty?
puts "Trying to run rake bootstrap..."
system %{#{bundle} rake bootstrap}
end
puts "Done!"

6
script/install-git-hooks Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
for hook in script/hooks/* ; do
ln -sf $PWD/$hook .git/hooks/${hook##*/}
done