-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
208 lines (162 loc) · 4.84 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
This.author = "Ara T. Howard"
This.email = "[email protected]"
This.rubyforge_project = 'gnip'
This.homepage = 'http://github.com/gnip/gnip-ruby/tree/master'
task :default do
puts(Rake::Task.tasks.map{|task| task.name} - ['default'])
end
task :gemspec do
ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
ignore_directories = 'pkg'
shiteless =
lambda do |list|
list.delete_if do |entry|
next unless test(?e, entry)
extension = File.basename(entry).split(%r/[.]/).last
ignore_extensions.any?{|ext| ext === extension}
end
list.delete_if do |entry|
next unless test(?d, entry)
dirname = File.expand_path(entry)
ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
end
end
lib = This.lib
version = This.version
files = shiteless[Dir::glob("**/**")]
executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
has_rdoc = true #File.exist?('doc')
test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
template =
if test(?e, 'gemspec.erb')
Template{ IO.read('gemspec.erb') }
else
Template {
<<-__
## #{ This.gemspec }
#
Gem::Specification::new do |spec|
spec.name = #{ lib.inspect }
spec.version = #{ version.inspect }
spec.platform = Gem::Platform::RUBY
spec.summary = #{ lib.inspect }
spec.files = #{ files.inspect }
spec.executables = #{ executables.inspect }
spec.require_path = "lib"
spec.has_rdoc = #{ has_rdoc.inspect }
spec.test_files = #{ test_files.inspect }
spec.rubyforge_project = #{ This.rubyforge_project.inspect }
spec.author = #{ This.author.inspect }
spec.email = #{ This.email.inspect }
spec.homepage = #{ This.homepage.inspect }
end
__
}
end
open(This.gemspec, "w"){|fd| fd.puts template}
end
task :gem => [:clean, :gemspec] do
Fu.mkdir_p This.pkgdir
before = Dir['*.gem']
cmd = "gem build #{ This.gemspec }"
`#{ cmd }`
after = Dir['*.gem']
gem = ((after - before).first || after.first) or abort('no gem!')
Fu.mv gem, This.pkgdir
This.gem = File.basename(gem)
end
task :readme do
samples = ''
prompt = '~ > '
lib = This.lib
version = This.version
Dir['sample*/*'].sort.each do |sample|
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
cmd = "cat #{ sample }"
samples << Util.indent(prompt + cmd, 2) << "\n\n"
samples << Util.indent(`#{ cmd }`, 4) << "\n"
cmd = "ruby #{ sample }"
samples << Util.indent(prompt + cmd, 2) << "\n\n"
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -Ilib #{ sample })'"
samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
end
template =
if test(?e, 'readme.erb')
Template{ IO.read('readme.erb') }
else
Template {
<<-__
NAME
#{ lib }
DESCRIPTION
INSTALL
gem install #{ lib }
SAMPLES
#{ samples }
__
}
end
open("README", "w"){|fd| fd.puts template}
end
task :clean do
Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
end
task :release => [:clean, :gemspec, :gem] do
gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
raise "which one? : #{ gems.inspect }" if gems.size > 1
raise "no gems?" if gems.size < 1
cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.pkgdir }/#{ This.gem }"
puts cmd
system cmd
end
BEGIN {
$VERBOSE = nil
require 'ostruct'
require 'erb'
require 'fileutils'
Fu = FileUtils
This = OpenStruct.new
This.file = File.expand_path(__FILE__)
This.dir = File.dirname(This.file)
This.pkgdir = File.join(This.dir, 'pkg')
This.lib = ENV['LIB']
This.lib ||= 'gnip'
version = ENV['VERSION']
unless version
name = This.lib.capitalize
require "./lib/#{ This.lib }"
version = eval(name).send(:version)
end
This.version = version
abort('no lib') unless This.lib
abort('no version') unless This.version
This.gemspec = "gnip-ruby.gemspec"
module Util
def indent(s, n = 2)
s = unindent(s)
ws = ' ' * n
s.gsub(%r/^/, ws)
end
def unindent(s)
indent = nil
s.each do |line|
next if line =~ %r/^\s*$/
indent = line[%r/^\s*/] and break
end
indent ? s.gsub(%r/^#{ indent }/, "") : s
end
extend self
end
class Template
def initialize(&block)
@block = block
@template = block.call.to_s
end
def expand(b=nil)
ERB.new(Util.unindent(@template)).result(b||@block)
end
alias_method 'to_s', 'expand'
end
def Template(*args, &block) Template.new(*args, &block) end
Dir.chdir(This.dir)
}