hub/Rakefile

132 строки
3.1 KiB
Ruby
Исходник Обычный вид История

2009-12-08 09:28:03 +03:00
require 'rake/testtask'
2010-04-12 02:19:49 +04:00
#
# Helpers
#
2009-12-08 13:12:29 +03:00
2011-10-27 16:20:07 +04:00
def command?(util)
Rake::Task[:load_path].invoke
context = Object.new
require 'hub/context'
context.extend Hub::Context
context.send(:command?, util)
2009-12-09 16:32:02 +03:00
end
2011-10-27 16:20:07 +04:00
task :load_path do
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2009-12-08 13:12:29 +03:00
end
2010-04-12 02:19:49 +04:00
task :check_dirty do
2011-10-27 16:20:07 +04:00
unless system 'git', 'diff', '--quiet', 'HEAD'
abort "Aborted: you have uncommitted changes"
2010-04-12 02:19:49 +04:00
end
end
2009-12-08 13:03:17 +03:00
2010-04-12 02:19:49 +04:00
#
# Tests
#
2009-12-08 13:03:17 +03:00
2010-04-12 02:19:49 +04:00
task :default => :test
2009-12-08 13:03:17 +03:00
Rake::TestTask.new do |t|
t.libs << 'test'
t.ruby_opts << '-rubygems'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
2010-04-12 02:19:49 +04:00
end
#
2011-10-27 16:20:07 +04:00
# Manual
2010-04-12 02:19:49 +04:00
#
2009-12-08 13:03:17 +03:00
2010-04-12 02:19:49 +04:00
if command? :ronn
2011-10-27 16:20:07 +04:00
desc "Show man page"
2010-04-12 02:19:49 +04:00
task :man => "man:build" do
exec "man man/hub.1"
end
2011-10-27 16:20:07 +04:00
desc "Build man pages"
task "man:build" => ["man/hub.1", "man/hub.1.html"]
extract_examples = lambda { |readme_file|
# split readme in sections
examples = File.read(readme_file).split(/^-{4,}$/)[3].strip
examples.sub!(/^.+?(###)/m, '\1') # strip intro paragraph
examples.sub!(/\n+.+\Z/, '') # remove last line
examples
}
# inject examples from README file to .ronn source
source_with_examples = lambda { |source, readme|
examples = extract_examples.call(readme)
compiled = File.read(source)
compiled.sub!('{{README}}', examples)
compiled
}
# generate man page with ronn
compile_ronn = lambda { |destination, type, contents|
File.popen("ronn --pipe --#{type} --organization=DEFUNKT --manual='Git Manual'", 'w+') { |io|
io.write contents
io.close_write
File.open(destination, 'w') { |f| f << io.read }
}
abort "ronn --#{type} conversion failed" unless $?.success?
}
file "man/hub.1" => ["man/hub.1.ronn", "README.md"] do |task|
contents = source_with_examples.call(*task.prerequisites)
compile_ronn.call(task.name, 'roff', contents)
compile_ronn.call("#{task.name}.html", 'html', contents)
end
file "man/hub.1.html" => ["man/hub.1.ronn", "README.md"] do |task|
Rake::Task["man/hub.1"].invoke
2009-12-08 11:26:59 +03:00
end
end
2010-04-12 02:19:49 +04:00
#
2011-10-27 16:20:07 +04:00
# Build
2010-04-12 02:19:49 +04:00
#
2011-10-27 16:20:07 +04:00
file "hub" => FileList.new("lib/hub/*.rb", "man/hub.1") do |task|
Rake::Task[:load_path].invoke
2010-04-12 02:19:49 +04:00
require 'hub/standalone'
2011-10-27 16:20:07 +04:00
Hub::Standalone.save(task.name)
end
2011-10-27 16:20:07 +04:00
desc "Build standalone script"
task :standalone => "hub"
desc "Install standalone script and man pages"
2011-10-27 16:20:07 +04:00
task :install => "hub" do
prefix = ENV['PREFIX'] || ENV['prefix'] || '/usr/local'
FileUtils.mkdir_p "#{prefix}/bin"
FileUtils.cp "hub", "#{prefix}/bin", :preserve => true
FileUtils.mkdir_p "#{prefix}/share/man/man1"
FileUtils.cp "man/hub.1", "#{prefix}/share/man/man1"
end
2011-10-27 16:20:07 +04:00
desc "Copy files to gh-pages branch, but don't publish"
task :gh_pages => [:check_dirty, "hub", "man/hub.1.html"] do
2009-12-11 19:44:49 +03:00
cp "man/hub.1.html", "html"
2010-03-09 12:10:33 +03:00
sh "git checkout gh-pages"
# replace the specific shebang with a generic ruby one
sh "echo '#!/usr/bin/env' ruby > standalone"
sh "sed 1d hub >> standalone"
mv "html", "hub.1.html"
2011-10-27 16:20:07 +04:00
sh "git add standalone hub.1.html"
2010-03-09 12:10:33 +03:00
sh "git commit -m 'update standalone'"
2011-10-27 16:20:07 +04:00
end
desc "Publish to GitHub Pages"
task :pages => :gh_pages do
2010-03-09 12:10:33 +03:00
sh "git push origin gh-pages"
sh "git checkout master"
2011-10-27 16:20:07 +04:00
puts "Done."
2009-12-08 12:14:16 +03:00
end