提交 75404cb2 编写于 作者: M Mislav Marohnić

improve a bunch of existing rake tasks

上级 452ea80a
...@@ -4,19 +4,21 @@ require 'rake/testtask' ...@@ -4,19 +4,21 @@ require 'rake/testtask'
# Helpers # Helpers
# #
def command?(command) def command?(util)
`which #{command} 2>/dev/null` Rake::Task[:load_path].invoke
$?.success? context = Object.new
require 'hub/context'
context.extend Hub::Context
context.send(:command?, util)
end end
task :load_hub do task :load_path do
$LOAD_PATH.unshift 'lib' $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
require 'hub'
end end
task :check_dirty do task :check_dirty do
if !`git status`.include?('nothing to commit') unless system 'git', 'diff', '--quiet', 'HEAD'
abort "dirty index - not publishing!" abort "Aborted: you have uncommitted changes"
end end
end end
...@@ -44,16 +46,16 @@ end ...@@ -44,16 +46,16 @@ end
# #
# Ron # Manual
# #
if command? :ronn if command? :ronn
desc "Show the manual" desc "Show man page"
task :man => "man:build" do task :man => "man:build" do
exec "man man/hub.1" exec "man man/hub.1"
end end
desc "Build the manual" desc "Build man pages"
task "man:build" => ["man/hub.1", "man/hub.1.html"] task "man:build" => ["man/hub.1", "man/hub.1.html"]
extract_examples = lambda { |readme_file| extract_examples = lambda { |readme_file|
...@@ -95,17 +97,20 @@ end ...@@ -95,17 +97,20 @@ end
# #
# Gems # Build
# #
desc "Build standalone script" file "hub" => FileList.new("lib/hub/*.rb", "man/hub.1") do |task|
task :standalone => :load_hub do Rake::Task[:load_path].invoke
require 'hub/standalone' require 'hub/standalone'
Hub::Standalone.save('hub') Hub::Standalone.save(task.name)
end end
desc "Build standalone script"
task :standalone => "hub"
desc "Install standalone script and man pages" desc "Install standalone script and man pages"
task :install => :standalone do task :install => "hub" do
prefix = ENV['PREFIX'] || ENV['prefix'] || '/usr/local' prefix = ENV['PREFIX'] || ENV['prefix'] || '/usr/local'
FileUtils.mkdir_p "#{prefix}/bin" FileUtils.mkdir_p "#{prefix}/bin"
...@@ -115,16 +120,19 @@ task :install => :standalone do ...@@ -115,16 +120,19 @@ task :install => :standalone do
FileUtils.cp "man/hub.1", "#{prefix}/share/man/man1" FileUtils.cp "man/hub.1", "#{prefix}/share/man/man1"
end end
desc "Publish to GitHub Pages" desc "Copy files to gh-pages branch, but don't publish"
task :pages => [ "man:build", :check_dirty, :standalone ] do task :gh_pages => [:check_dirty, "hub", "man/hub.1.html"] do
cp "man/hub.1.html", "html" cp "man/hub.1.html", "html"
sh "git checkout gh-pages" sh "git checkout gh-pages"
sh "mv hub standalone" sh "mv hub standalone"
sh "git add standalone*"
sh "mv html hub.1.html" sh "mv html hub.1.html"
sh "git add hub.1.html" sh "git add standalone hub.1.html"
sh "git commit -m 'update standalone'" sh "git commit -m 'update standalone'"
end
desc "Publish to GitHub Pages"
task :pages => :gh_pages do
sh "git push origin gh-pages" sh "git push origin gh-pages"
sh "git checkout master" sh "git checkout master"
puts :done puts "Done."
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册