forked from rtomayko/tilt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
80 lines (65 loc) · 2.28 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
require 'rake/testtask'
task :default => :test
# SPECS =====================================================================
desc 'Generate test coverage report'
task :rcov do
sh "rcov -Ilib:test test/*_test.rb"
end
desc 'Run tests (default)'
Rake::TestTask.new(:test) do |t|
t.test_files = FileList['test/*_test.rb']
t.ruby_opts = ['-Itest']
t.ruby_opts << '-rubygems' if defined? Gem
end
# PACKAGING =================================================================
begin
require 'rubygems'
rescue LoadError
end
if defined?(Gem)
SPEC = eval(File.read('tilt.gemspec'))
def package(ext='')
"pkg/tilt-#{SPEC.version}" + ext
end
desc 'Build packages'
task :package => %w[.gem .tar.gz].map {|e| package(e)}
desc 'Build and install as local gem'
task :install => package('.gem') do
sh "gem install #{package('.gem')}"
end
directory 'pkg/'
file package('.gem') => %w[pkg/ tilt.gemspec] + SPEC.files do |f|
sh "gem build tilt.gemspec"
mv File.basename(f.name), f.name
end
file package('.tar.gz') => %w[pkg/] + SPEC.files do |f|
sh "git archive --format=tar HEAD | gzip > #{f.name}"
end
desc 'Upload gem and tar.gz distributables to rubyforge'
task :release => [package('.gem'), package('.tar.gz')] do |t|
sh <<-SH
rubyforge add_release sinatra tilt #{SPEC.version} #{package('.gem')} &&
rubyforge add_file sinatra tilt #{SPEC.version} #{package('.tar.gz')}
SH
end
end
# GEMSPEC ===================================================================
file 'tilt.gemspec' => FileList['{lib,test}/**','Rakefile'] do |f|
# read version from tilt.rb
version = File.read('lib/tilt.rb')[/VERSION = '(.*)'/] && $1
# read spec file and split out manifest section
spec = File.
read(f.name).
sub(/s\.version\s*=\s*'.*'/, "s.version = '#{version}'")
parts = spec.split(" # = MANIFEST =\n")
# determine file list from git ls-files
files = `git ls-files`.
split("\n").sort.reject{ |file| file =~ /^\./ }.
map{ |file| " #{file}" }.join("\n")
# piece file back together and write...
parts[1] = " s.files = %w[\n#{files}\n ]\n"
spec = parts.join(" # = MANIFEST =\n")
spec.sub!(/s.date = '.*'/, "s.date = '#{Time.now.strftime("%Y-%m-%d")}'")
File.open(f.name, 'w') { |io| io.write(spec) }
puts "updated #{f.name}"
end