-
Notifications
You must be signed in to change notification settings - Fork 71
/
Rakefile
104 lines (77 loc) · 2.15 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
$: << File.expand_path("../lib", __FILE__)
require "rake/testtask"
require "fileutils"
require "airplay/version"
require "airplay/cli/version"
class RuleBuilder
attr_reader :task, :info
TASKS = [:lib, :cli]
def initialize(options = {})
@task = options[:task]
@info = {
lib: { name: "airplay", version: Airplay::VERSION },
cli: { name: "airplay-cli", version: Airplay::CLI::VERSION }
}
end
def construct(action)
-> n {
task.call(:all) do
TASKS.each { |task| Rake::Task["#{action}:#{task}"].invoke }
end
TASKS.each do |task_name|
task.call(task_name) { action_method(action, task_name) }
end
}
end
private
def action_method(action, task_name)
method("#{action}_gem".to_sym).call(task_name)
end
def build_gem(type)
name = info[type][:name]
version = info[type][:version]
gem_name = "#{name}-#{version}.gem"
FileUtils.mkdir_p("pkg")
`gem build #{name}.gemspec`
FileUtils.mv(gem_name, "pkg")
puts "#{name} (v#{version}) builded!"
"./pkg/#{gem_name}"
end
def install_gem(type)
name = info[type][:name]
gem_path = build_gem(type)
`gem install --local #{gem_path}`
puts "#{gem_path} installed!"
end
def release_gem(type)
name = info[type][:name]
gem_path = build_gem(type)
`gem push #{gem_path}`
puts "#{gem_path} released!"
end
end
builder = RuleBuilder.new(task: method(:task))
namespace :build, &builder.construct(:build)
namespace :install, &builder.construct(:install)
namespace :release, &builder.construct(:release)
Rake::TestTask.new("test:all") do |t|
t.libs << "test"
t.pattern = "test/**/*_test.rb"
end
Rake::TestTask.new("test:unit") do |t|
t.libs << "test"
t.pattern = "test/unit/**/*_test.rb"
end
Rake::TestTask.new("test:integration") do |t|
t.libs << "test"
t.pattern = "test/integration**/*_test.rb"
end
task :default => "test:all"
namespace :doc do
task :generate do
structure = %w(header toc installation usage testing documentation contributors)
File.open("README.md", "w+") do |f|
structure.each { |part| f << File.read("doc/#{part}.md") + "\n" }
end
end
end