blob: 3ba910382b7b7f31ded7938b485aeb73eadd941e (
plain)
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
|
require "rubygems"
require "highline/import"
require "pty"
require "fileutils"
require 'rake/testtask'
##
## HELPER
##
def run(cmd)
PTY.spawn(cmd) do |output, input, pid|
begin
while line = output.gets do
puts line
end
rescue Errno::EIO
end
end
rescue PTY::ChildExited
end
##
## GEM BUILDING AND INSTALLING
##
$spec_path = 'leap_cli.gemspec'
$spec = eval(File.read($spec_path))
$base_dir = File.dirname(__FILE__)
$gem_path = File.join($base_dir, 'pkg', "#{$spec.name}-#{$spec.version}.gem")
def built_gem_path
Dir[File.join($base_dir, "#{$spec.name}-*.gem")].sort_by{|f| File.mtime(f)}.last
end
desc "Build #{$spec.name}-#{$spec.version}.gem into the pkg directory"
task 'build' do
FileUtils.mkdir_p(File.join($base_dir, 'pkg'))
FileUtils.rm($gem_path) if File.exists?($gem_path)
run "gem build -V '#{$spec_path}'"
file_name = File.basename(built_gem_path)
FileUtils.mv(built_gem_path, 'pkg')
say "#{$spec.name} #{$spec.version} built to pkg/#{file_name}"
end
desc "Build and install #{$spec.name}-#{$spec.version}.gem into either system-wide or user gems"
task 'install' do
if !File.exists?($gem_path)
say("Could not file #{$gem_path}. Try running 'rake build'")
else
if ENV["USER"] == "root"
run "gem install '#{$gem_path}'"
else
say("A system-wide install requires that you run 'rake install' as root, which you are not.")
if agree("Do you want to continue installing to #{Gem.path.grep /home/}? ")
run "gem install '#{$gem_path}' --user-install"
end
end
end
end
##
## TESTING
##
Rake::TestTask.new do |t|
t.pattern = "test/unit/*_test.rb"
end
task :default => :test
##
## DOCUMENTATION
##
# require 'rdoc/task'
# Rake::RDocTask.new do |rd|
# rd.main = "README.rdoc"
# rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
# rd.title = 'Your application title'
# end
|