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
|
|
|
|
2011-10-27 16:19:35 +04: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"
|
2011-10-19 19:41:10 +04:00
|
|
|
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
|
|
|
|
|
2009-12-11 19:44:42 +03:00
|
|
|
|
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)
|
2009-12-11 19:44:42 +03:00
|
|
|
end
|
|
|
|
|
2011-10-27 16:20:07 +04:00
|
|
|
desc "Build standalone script"
|
|
|
|
task :standalone => "hub"
|
|
|
|
|
2009-12-11 19:44:42 +03:00
|
|
|
desc "Install standalone script and man pages"
|
2011-10-27 16:20:07 +04:00
|
|
|
task :install => "hub" do
|
2009-12-11 19:44:42 +03:00
|
|
|
prefix = ENV['PREFIX'] || ENV['prefix'] || '/usr/local'
|
|
|
|
|
|
|
|
FileUtils.mkdir_p "#{prefix}/bin"
|
2011-03-19 22:49:43 +03:00
|
|
|
FileUtils.cp "hub", "#{prefix}/bin", :preserve => true
|
2009-12-11 19:44:42 +03:00
|
|
|
|
|
|
|
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"
|
2011-11-23 20:06:24 +04:00
|
|
|
# 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
|