forked from heroku/legacy-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
116 lines (92 loc) · 2.92 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
$:.unshift File.expand_path("../lib", __FILE__)
require "heroku/version"
require 'rake'
require 'spec/rake/spectask'
desc "Run all specs"
Spec::Rake::SpecTask.new('spec') do |t|
t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
t.spec_files = FileList['spec/**/*_spec.rb']
end
desc "Print specdocs"
Spec::Rake::SpecTask.new(:doc) do |t|
t.spec_opts = ["--format", "specdoc", "--dry-run"]
t.spec_files = FileList['spec/*_spec.rb']
end
desc "Generate RCov code coverage report"
Spec::Rake::SpecTask.new('rcov') do |t|
t.spec_files = FileList['spec/*_spec.rb']
t.rcov = true
t.rcov_opts = ['--exclude', 'examples']
end
def gem_paths
%x{ bundle show }.split("\n").map do |line|
if line =~ /^ \* (.*?) \((.*?)\)/
%x{ bundle show #{$1} }.strip
end
end.compact
end
GEM_BLACKLIST = %w( bundler heroku )
def copy_gems(package_gem_dir)
lines = %x{ bundle show }.strip.split("\n")
raise "error running bundler" unless $?.success?
%x{ env BUNDLE_WITHOUT="development:test" bundle show }.split("\n").each do |line|
if line =~ /^ \* (.*?) \((.*?)\)/
next if GEM_BLACKLIST.include?($1)
puts "vendoring: #{$1}-#{$2}"
gem_dir = %x{ bundle show #{$1} }.strip
%x{ cp -R #{gem_dir} #{package_gem_dir}/ }
end
end.compact
end
def package_path(path, stream)
puts "#{path}/**/*.rb"
Dir["#{path}/**/*"].each do |file|
next unless File.file?(file)
puts "finding file: #{file}"
relative = file.gsub(/^#{path}/, '')
relative.gsub!(/^\//, '')
stream.puts("__FILE__ #{relative}")
stream.puts(File.read(file))
stream.puts("__ENDFILE__")
end
end
desc "Package as a single file"
task :package do
base_dir = File.dirname(__FILE__)
require "tmpdir"
package_dir = "#{Dir.mktmpdir}/heroku-#{Heroku::VERSION}"
package_gem_dir = "#{package_dir}/vendor/gems"
puts "building in: #{package_dir}"
%x{ mkdir -p #{package_gem_dir} }
copy_gems package_gem_dir
%x{ cp -R #{base_dir}/lib #{package_dir} }
File.open("#{package_dir}/heroku", "w") do |file|
file.puts <<-PREAMBLE
#!/usr/bin/env ruby
gem_dir = File.expand_path("../vendor/gems", __FILE__)
Dir["\#{gem_dir}/**/lib"].each do |libdir|
$:.unshift libdir
end
$:.unshift File.expand_path("../lib", __FILE__)
require 'heroku'
require 'heroku/command'
args = ARGV.dup
ARGV.clear
command = args.shift.strip rescue 'help'
Heroku::Command.run(command, args)
PREAMBLE
end
%x{ chmod +x #{package_dir}/heroku }
if plugins = (ENV["PLUGINS"] || "").split(" ")
plugins.each do |plugin|
puts "plugin: #{plugin}"
%x{ mkdir -p #{package_dir}/plugins }
%x{ cd #{package_dir}/plugins && git clone #{plugin} 2>&1 }
%x{ rm -rf $(find #{package_dir}/plugins -name .git) }
end
end
%x{ mkdir -p #{base_dir}/pkg }
%x{ cd #{package_dir}/.. && tar czvpf #{base_dir}/pkg/heroku-#{Heroku::VERSION}.tgz * 2>&1 }
puts "package: pkg/heroku-#{Heroku::VERSION}.tgz"
end
task :default => :spec