This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Rakefile
83 lines (74 loc) · 2.3 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require 'date'
task :default => :test
ROOTDIR = File.expand_path('..', __FILE__).sub(/#{Dir.pwd}(?=\/)/, '.')
LIBDIR = "#{ROOTDIR}/lib"
BINDIR = "#{ROOTDIR}/bin"
task :environment do
$:.unshift ROOTDIR if !$:.include?(ROOTDIR)
$:.unshift LIBDIR if !$:.include?(LIBDIR)
ENV['RUBYLIB'] = $LOAD_PATH.join(':')
ENV['PATH'] = "#{BINDIR}:#{ENV['PATH']}"
end
desc 'Run tests'
task :test => :environment do
$LOAD_PATH.unshift "#{ROOTDIR}/test"
Dir['test/test_*.rb'].each { |f| require(f) }
end
def source_version
@source_version ||= `ruby -Ilib -rbcat -e 'puts Bcat::VERSION'`.chomp
end
require 'rubygems'
$spec = eval(File.read('bcat.gemspec'))
desc "Build gem package"
task :package => 'bcat.gemspec' do
sh "gem build bcat.gemspec"
end
desc 'Build the manual'
task :man do
ENV['RONN_MANUAL'] = "Bcat #{source_version}"
ENV['RONN_ORGANIZATION'] = "Ryan Tomayko"
sh "ronn -stoc -w -r5 man/*.ronn"
end
desc 'Publish to github pages'
task :pages => :man do
puts '----------------------------------------------'
puts 'Rebuilding pages ...'
verbose(false) {
rm_rf 'pages'
push_url = `git remote show origin`.grep(/Push.*URL/).first[/git@.*/]
sh "
set -e
git fetch -q origin
rev=$(git rev-parse origin/gh-pages)
git clone -q -b gh-pages . pages
cd pages
git reset --hard $rev
rm -f *.html
cp -rp ../man/*.html ../man/index.* ./
git add -u *.html index.*
git commit -m 'rebuild manual'
git push #{push_url} gh-pages
", :verbose => false
}
end
file 'bcat.gemspec' => FileList['{lib,test,bin}/**','Rakefile'] do |f|
# read spec file and split out manifest section
spec = File.read(f.name)
head, manifest, tail = spec.split(" # = MANIFEST =\n")
# replace version and date
head.sub!(/\.version = '.*'/, ".version = '#{source_version}'")
head.sub!(/\.date = '.*'/, ".date = '#{Date.today.to_s}'")
# determine file list from git ls-files
files = `git ls-files`.
split("\n").
sort.
reject{ |file| file =~ /^\./ }.
reject { |file| file =~ /^doc/ }.
map{ |file| " #{file}" }.
join("\n")
# piece file back together and write...
manifest = " s.files = %w[\n#{files}\n ]\n"
spec = [head,manifest,tail].join(" # = MANIFEST =\n")
File.open(f.name, 'w') { |io| io.write(spec) }
puts "updated #{f.name}"
end