senv 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README +14 -0
- data/Rakefile +576 -0
- data/a.rb +92 -0
- data/bin/senv +259 -0
- data/dist/senv-0.4.2-linux-x86.tgz +0 -0
- data/dist/senv-0.4.2-linux-x86_64.tgz +0 -0
- data/dist/senv-0.4.2-osx.tgz +0 -0
- data/dist/senv.rb +1468 -0
- data/dist/senv.sh +11 -0
- data/lib/senv.rb +663 -0
- data/lib/senv/script.rb +527 -0
- data/senv.gemspec +44 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8e98f626b16a25e287d0bacc26b74693c7e73afdbcf5355fa6bdacc838a4ddc9
|
4
|
+
data.tar.gz: 4532ab5366769d32db307fe122a814e75a6d145754ca04982c099d0a1267485b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 87be7f0e30838c16754ede578042014dc806ac6daaee1bdaba767cc3823cbbb61486c6c14e522191aba0844ff01c8c6db2c0294fdb7617d4b918d3308316e603
|
7
|
+
data.tar.gz: 73de806290b942a1c721f1be37f5b837b3062f38ccb2762cb3e827fc404164d07a473fdf08b1243560e5ebaa121b2099565de8e272f3f82835693fcf0c0f7d63
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 ara.t.howard
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,576 @@
|
|
1
|
+
This.author = "Ara T. Howard"
|
2
|
+
This.email = "ara.t.howard@gmail.com"
|
3
|
+
This.homepage = "https://github.com/ahoward/#{ This.lib }"
|
4
|
+
|
5
|
+
task :license do
|
6
|
+
open('LICENSE', 'w'){|fd| fd.puts "Ruby"}
|
7
|
+
end
|
8
|
+
|
9
|
+
task :default do
|
10
|
+
puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
|
11
|
+
end
|
12
|
+
|
13
|
+
task :test do
|
14
|
+
run_tests!
|
15
|
+
end
|
16
|
+
|
17
|
+
namespace :test do
|
18
|
+
task(:unit){ run_tests!(:unit) }
|
19
|
+
task(:functional){ run_tests!(:functional) }
|
20
|
+
task(:integration){ run_tests!(:integration) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_tests!(which = nil)
|
24
|
+
which ||= '**'
|
25
|
+
test_dir = File.join(This.dir, "test")
|
26
|
+
test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
|
27
|
+
test_rbs = Dir.glob(test_glob).sort
|
28
|
+
|
29
|
+
div = ('=' * 119)
|
30
|
+
line = ('-' * 119)
|
31
|
+
|
32
|
+
test_rbs.each_with_index do |test_rb, index|
|
33
|
+
testno = index + 1
|
34
|
+
command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
|
35
|
+
|
36
|
+
puts
|
37
|
+
say(div, :color => :cyan, :bold => true)
|
38
|
+
say("@#{ testno } => ", :bold => true, :method => :print)
|
39
|
+
say(command, :color => :cyan, :bold => true)
|
40
|
+
say(line, :color => :cyan, :bold => true)
|
41
|
+
|
42
|
+
system(command)
|
43
|
+
|
44
|
+
say(line, :color => :cyan, :bold => true)
|
45
|
+
|
46
|
+
status = $?.exitstatus
|
47
|
+
|
48
|
+
if status.zero?
|
49
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
50
|
+
say("SUCCESS", :color => :green, :bold => true)
|
51
|
+
else
|
52
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
53
|
+
say("FAILURE", :color => :red, :bold => true)
|
54
|
+
end
|
55
|
+
say(line, :color => :cyan, :bold => true)
|
56
|
+
|
57
|
+
exit(status) unless status.zero?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
task :gemspec do
|
63
|
+
ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
|
64
|
+
ignore_directories = ['pkg']
|
65
|
+
ignore_files = ['test/log']
|
66
|
+
|
67
|
+
shiteless =
|
68
|
+
lambda do |list|
|
69
|
+
list.delete_if do |entry|
|
70
|
+
next unless test(?e, entry)
|
71
|
+
extension = File.basename(entry).split(%r/[.]/).last
|
72
|
+
ignore_extensions.any?{|ext| ext === extension}
|
73
|
+
end
|
74
|
+
list.delete_if do |entry|
|
75
|
+
next unless test(?d, entry)
|
76
|
+
dirname = File.expand_path(entry)
|
77
|
+
ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
|
78
|
+
end
|
79
|
+
list.delete_if do |entry|
|
80
|
+
next unless test(?f, entry)
|
81
|
+
filename = File.expand_path(entry)
|
82
|
+
ignore_files.any?{|file| File.expand_path(file) == filename}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
lib = This.lib
|
87
|
+
object = This.object
|
88
|
+
version = This.version
|
89
|
+
files = shiteless[Dir::glob("**/**")]
|
90
|
+
executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
|
91
|
+
#has_rdoc = true #File.exist?('doc')
|
92
|
+
test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
|
93
|
+
summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
|
94
|
+
description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
|
95
|
+
license = object.respond_to?(:license) ? object.license : "Ruby"
|
96
|
+
|
97
|
+
if This.extensions.nil?
|
98
|
+
This.extensions = []
|
99
|
+
extensions = This.extensions
|
100
|
+
%w( Makefile configure extconf.rb ).each do |ext|
|
101
|
+
extensions << ext if File.exists?(ext)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
extensions = [extensions].flatten.compact
|
105
|
+
|
106
|
+
if This.dependencies.nil?
|
107
|
+
dependencies = []
|
108
|
+
else
|
109
|
+
case This.dependencies
|
110
|
+
when Hash
|
111
|
+
dependencies = This.dependencies.values
|
112
|
+
when Array
|
113
|
+
dependencies = This.dependencies
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
template =
|
118
|
+
if test(?e, 'gemspec.erb')
|
119
|
+
Template{ IO.read('gemspec.erb') }
|
120
|
+
else
|
121
|
+
Template {
|
122
|
+
<<-__
|
123
|
+
## <%= lib %>.gemspec
|
124
|
+
#
|
125
|
+
|
126
|
+
Gem::Specification::new do |spec|
|
127
|
+
spec.name = <%= lib.inspect %>
|
128
|
+
spec.version = <%= version.inspect %>
|
129
|
+
spec.platform = Gem::Platform::RUBY
|
130
|
+
spec.summary = <%= lib.inspect %>
|
131
|
+
spec.description = <%= description.inspect %>
|
132
|
+
spec.license = <%= license.inspect %>
|
133
|
+
|
134
|
+
spec.files =\n<%= files.sort.pretty_inspect %>
|
135
|
+
spec.executables = <%= executables.inspect %>
|
136
|
+
|
137
|
+
spec.require_path = "lib"
|
138
|
+
|
139
|
+
spec.test_files = <%= test_files.inspect %>
|
140
|
+
|
141
|
+
<% dependencies.each do |lib_version| %>
|
142
|
+
spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>)
|
143
|
+
<% end %>
|
144
|
+
|
145
|
+
spec.extensions.push(*<%= extensions.inspect %>)
|
146
|
+
|
147
|
+
spec.author = <%= This.author.inspect %>
|
148
|
+
spec.email = <%= This.email.inspect %>
|
149
|
+
spec.homepage = <%= This.homepage.inspect %>
|
150
|
+
end
|
151
|
+
__
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
Fu.mkdir_p(This.pkgdir)
|
156
|
+
gemspec = "#{ lib }.gemspec"
|
157
|
+
open(gemspec, "w"){|fd| fd.puts(template)}
|
158
|
+
This.gemspec = gemspec
|
159
|
+
end
|
160
|
+
|
161
|
+
task :dist_rb do
|
162
|
+
Dir.chdir(This.dir)
|
163
|
+
|
164
|
+
distdir = File.join(This.dir, 'dist')
|
165
|
+
Fu.mkdir_p(distdir)
|
166
|
+
|
167
|
+
bin = IO.binread('./bin/senv')
|
168
|
+
|
169
|
+
libs = ''
|
170
|
+
Dir.glob('lib/**/**.rb').each do |lib|
|
171
|
+
libs << "### <lib src='#{ lib }'>\n\n"
|
172
|
+
libs << IO.binread(lib)
|
173
|
+
libs << "\n\n### </lib src='#{ lib }'>\n\n"
|
174
|
+
end
|
175
|
+
|
176
|
+
dist_rb = <<~____
|
177
|
+
#{ bin }
|
178
|
+
|
179
|
+
BEGIN {
|
180
|
+
|
181
|
+
#{ libs }
|
182
|
+
|
183
|
+
}
|
184
|
+
____
|
185
|
+
|
186
|
+
dist = "./dist/senv.rb"
|
187
|
+
|
188
|
+
Fu.mkdir_p(File.dirname(dist))
|
189
|
+
IO.binwrite(dist, dist_rb)
|
190
|
+
Fu.chmod(0755, dist)
|
191
|
+
|
192
|
+
system("#{ dist } help > /dev/null 2>&1")
|
193
|
+
abort("#{ dist } is borked") unless $?.exitstatus.zero?
|
194
|
+
STDOUT.puts(dist)
|
195
|
+
end
|
196
|
+
|
197
|
+
task :dist => [:dist_rb] do
|
198
|
+
Dir.chdir(This.dir)
|
199
|
+
|
200
|
+
version = This.version
|
201
|
+
name = This.name.downcase
|
202
|
+
|
203
|
+
platforms = %w[
|
204
|
+
linux-x86
|
205
|
+
linux-x86_64
|
206
|
+
osx
|
207
|
+
]
|
208
|
+
|
209
|
+
Dir.glob("./dist/#{ name }-*").each do |entry|
|
210
|
+
Fu.rm_rf(entry)
|
211
|
+
end
|
212
|
+
|
213
|
+
spawn = proc do |cmd|
|
214
|
+
system(cmd) or abort("#{ cmd } #=> #{ $? }")
|
215
|
+
end
|
216
|
+
|
217
|
+
name = This.name.downcase
|
218
|
+
entrypoint = File.expand_path("./dist/#{ name }.sh")
|
219
|
+
|
220
|
+
platforms.each do |platform|
|
221
|
+
distdir = "./dist/#{ name }-#{ version }-#{ platform }"
|
222
|
+
Fu.mkdir_p(distdir)
|
223
|
+
|
224
|
+
libdir = File.join(distdir, 'lib')
|
225
|
+
Fu.mkdir_p(libdir)
|
226
|
+
|
227
|
+
appdir = File.join(libdir, 'app')
|
228
|
+
Fu.mkdir_p(appdir)
|
229
|
+
|
230
|
+
rubydir = File.join(libdir, 'ruby')
|
231
|
+
Fu.mkdir_p(rubydir)
|
232
|
+
|
233
|
+
Fu.cp('./dist/senv.rb', appdir)
|
234
|
+
|
235
|
+
Dir.chdir(rubydir) do
|
236
|
+
basename = "traveling-ruby-20141215-2.1.5-#{ platform }.tar.gz"
|
237
|
+
cmd = "curl -s -L -O --fail https://d6r77u77i8pq3.cloudfront.net/releases/#{ basename }"
|
238
|
+
spawn[cmd]
|
239
|
+
spawn["tar -xzf #{ basename }"]
|
240
|
+
Fu.rm(basename)
|
241
|
+
|
242
|
+
if test(?d, 'lib/vendor')
|
243
|
+
%`
|
244
|
+
# Remove tests
|
245
|
+
rm -rf lib/vendor/ruby/*/gems/*/test
|
246
|
+
rm -rf lib/vendor/ruby/*/gems/*/tests
|
247
|
+
rm -rf lib/vendor/ruby/*/gems/*/spec
|
248
|
+
rm -rf lib/vendor/ruby/*/gems/*/features
|
249
|
+
rm -rf lib/vendor/ruby/*/gems/*/benchmark
|
250
|
+
|
251
|
+
# Remove documentation
|
252
|
+
rm -f lib/vendor/ruby/*/gems/*/README*
|
253
|
+
rm -f lib/vendor/ruby/*/gems/*/CHANGE*
|
254
|
+
rm -f lib/vendor/ruby/*/gems/*/Change*
|
255
|
+
rm -f lib/vendor/ruby/*/gems/*/COPYING*
|
256
|
+
rm -f lib/vendor/ruby/*/gems/*/LICENSE*
|
257
|
+
rm -f lib/vendor/ruby/*/gems/*/MIT-LICENSE*
|
258
|
+
rm -f lib/vendor/ruby/*/gems/*/TODO
|
259
|
+
rm -f lib/vendor/ruby/*/gems/*/*.txt
|
260
|
+
rm -f lib/vendor/ruby/*/gems/*/*.md
|
261
|
+
rm -f lib/vendor/ruby/*/gems/*/*.rdoc
|
262
|
+
rm -rf lib/vendor/ruby/*/gems/*/doc
|
263
|
+
rm -rf lib/vendor/ruby/*/gems/*/docs
|
264
|
+
rm -rf lib/vendor/ruby/*/gems/*/example
|
265
|
+
rm -rf lib/vendor/ruby/*/gems/*/examples
|
266
|
+
rm -rf lib/vendor/ruby/*/gems/*/sample
|
267
|
+
rm -rf lib/vendor/ruby/*/gems/*/doc-api
|
268
|
+
find lib/vendor/ruby -name '*.md' | xargs rm -f
|
269
|
+
|
270
|
+
# Remove misc unnecessary files
|
271
|
+
rm -rf lib/vendor/ruby/*/gems/*/.gitignore
|
272
|
+
rm -rf lib/vendor/ruby/*/gems/*/.travis.yml
|
273
|
+
|
274
|
+
# Remove leftover native extension sources and compilation objects
|
275
|
+
rm -f lib/vendor/ruby/*/gems/*/ext/Makefile
|
276
|
+
rm -f lib/vendor/ruby/*/gems/*/ext/*/Makefile
|
277
|
+
rm -f lib/vendor/ruby/*/gems/*/ext/*/tmp
|
278
|
+
find lib/vendor/ruby -name '*.c' | xargs rm -f
|
279
|
+
find lib/vendor/ruby -name '*.cpp' | xargs rm -f
|
280
|
+
find lib/vendor/ruby -name '*.h' | xargs rm -f
|
281
|
+
find lib/vendor/ruby -name '*.rl' | xargs rm -f
|
282
|
+
find lib/vendor/ruby -name 'extconf.rb' | xargs rm -f
|
283
|
+
find lib/vendor/ruby/*/gems -name '*.o' | xargs rm -f
|
284
|
+
find lib/vendor/ruby/*/gems -name '*.so' | xargs rm -f
|
285
|
+
find lib/vendor/ruby/*/gems -name '*.bundle' | xargs rm -f
|
286
|
+
|
287
|
+
# Remove Java files. They're only used for JRuby support
|
288
|
+
find lib/vendor/ruby -name '*.java' | xargs rm -f
|
289
|
+
find lib/vendor/ruby -name '*.class' | xargs rm -f
|
290
|
+
`.split("\n") do |line|
|
291
|
+
next if line =~ /^\s*#/
|
292
|
+
next if line =~ /^\s*$/
|
293
|
+
cmd = line.strip
|
294
|
+
spawn[cmd]
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
Dir.chdir(distdir) do
|
300
|
+
Fu.cp(entrypoint, name)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
if STDOUT.tty?
|
305
|
+
system('tree -L 4 dist 2>/dev/null')
|
306
|
+
end
|
307
|
+
|
308
|
+
Dir.chdir './dist' do
|
309
|
+
platforms.each do |platform|
|
310
|
+
dist = "#{ name }-#{ version }-#{ platform }"
|
311
|
+
spawn["tar cvfz #{ dist }.tgz ./#{ dist } >/dev/null 2>&1"]
|
312
|
+
Fu.rm_rf(dist)
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
task :gem => [:clean, :gemspec] do
|
318
|
+
Fu.mkdir_p(This.pkgdir)
|
319
|
+
before = Dir['*.gem']
|
320
|
+
cmd = "gem build #{ This.gemspec }"
|
321
|
+
`#{ cmd }`
|
322
|
+
after = Dir['*.gem']
|
323
|
+
gem = ((after - before).first || after.first) or abort('no gem!')
|
324
|
+
Fu.mv(gem, This.pkgdir)
|
325
|
+
This.gem = File.join(This.pkgdir, File.basename(gem))
|
326
|
+
end
|
327
|
+
|
328
|
+
task :readme do
|
329
|
+
samples = ''
|
330
|
+
prompt = '~ > '
|
331
|
+
lib = This.lib
|
332
|
+
version = This.version
|
333
|
+
|
334
|
+
Dir['sample*/*'].sort.each do |sample|
|
335
|
+
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
|
336
|
+
|
337
|
+
cmd = "cat #{ sample }"
|
338
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
339
|
+
samples << Util.indent(`#{ cmd }`, 4) << "\n"
|
340
|
+
|
341
|
+
cmd = "ruby #{ sample }"
|
342
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
343
|
+
|
344
|
+
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
|
345
|
+
samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
|
346
|
+
end
|
347
|
+
|
348
|
+
template =
|
349
|
+
if test(?e, 'README.erb')
|
350
|
+
Template{ IO.read('README.erb') }
|
351
|
+
else
|
352
|
+
Template {
|
353
|
+
<<-__
|
354
|
+
NAME
|
355
|
+
#{ lib }
|
356
|
+
|
357
|
+
DESCRIPTION
|
358
|
+
|
359
|
+
INSTALL
|
360
|
+
gem install #{ lib }
|
361
|
+
|
362
|
+
SAMPLES
|
363
|
+
#{ samples }
|
364
|
+
__
|
365
|
+
}
|
366
|
+
end
|
367
|
+
|
368
|
+
open("README", "w"){|fd| fd.puts template}
|
369
|
+
end
|
370
|
+
|
371
|
+
task :clean do
|
372
|
+
Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
|
373
|
+
end
|
374
|
+
|
375
|
+
task :release => [:dist, :gem] do
|
376
|
+
gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
|
377
|
+
raise "which one? : #{ gems.inspect }" if gems.size > 1
|
378
|
+
raise "no gems?" if gems.size < 1
|
379
|
+
|
380
|
+
cmd = "gem push #{ This.gem }"
|
381
|
+
puts cmd
|
382
|
+
puts
|
383
|
+
system(cmd)
|
384
|
+
abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
|
385
|
+
end
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
BEGIN {
|
392
|
+
# support for this rakefile
|
393
|
+
#
|
394
|
+
$VERBOSE = nil
|
395
|
+
|
396
|
+
require 'ostruct'
|
397
|
+
require 'erb'
|
398
|
+
require 'fileutils'
|
399
|
+
require 'rbconfig'
|
400
|
+
require 'pp'
|
401
|
+
|
402
|
+
# fu shortcut
|
403
|
+
#
|
404
|
+
Fu = FileUtils
|
405
|
+
|
406
|
+
# cache a bunch of stuff about this rakefile/environment
|
407
|
+
#
|
408
|
+
This = OpenStruct.new
|
409
|
+
|
410
|
+
This.file = File.expand_path(__FILE__)
|
411
|
+
This.dir = File.dirname(This.file)
|
412
|
+
This.pkgdir = File.join(This.dir, 'pkg')
|
413
|
+
This.lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
|
414
|
+
|
415
|
+
# load _lib
|
416
|
+
#
|
417
|
+
_lib = ["./lib/#{ This.lib }/_lib.rb", "./lib/#{ This.lib }.rb"].detect{|l| test(?s, l)}
|
418
|
+
unless _lib
|
419
|
+
abort "could not find a _lib in ./lib!?"
|
420
|
+
end
|
421
|
+
This._lib = _lib
|
422
|
+
require This._lib
|
423
|
+
|
424
|
+
# extract name from _lib
|
425
|
+
#
|
426
|
+
lines = IO.binread(This._lib).split("\n")
|
427
|
+
re = %r`\A \s* (module|class) \s+ ([^\s]+) \s* \z`iomx
|
428
|
+
name = nil
|
429
|
+
lines.each do |line|
|
430
|
+
match = line.match(re)
|
431
|
+
if match
|
432
|
+
name = match.to_a.last
|
433
|
+
break
|
434
|
+
end
|
435
|
+
end
|
436
|
+
unless name
|
437
|
+
abort "could not extract `name` from #{ This._lib }"
|
438
|
+
end
|
439
|
+
This.name = name
|
440
|
+
|
441
|
+
# now, fully grok This
|
442
|
+
#
|
443
|
+
This.object = eval(This.name)
|
444
|
+
|
445
|
+
version = This.object.send(:version)
|
446
|
+
This.version = version
|
447
|
+
|
448
|
+
if This.object.respond_to?(:dependencies)
|
449
|
+
This.dependencies = This.object.dependencies
|
450
|
+
end
|
451
|
+
|
452
|
+
# discover full path to this ruby executable
|
453
|
+
#
|
454
|
+
c = RbConfig::CONFIG
|
455
|
+
bindir = c["bindir"] || c['BINDIR']
|
456
|
+
ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
|
457
|
+
ruby_ext = c['EXEEXT'] || ''
|
458
|
+
ruby = File.join(bindir, (ruby_install_name + ruby_ext))
|
459
|
+
This.ruby = ruby
|
460
|
+
|
461
|
+
# some utils
|
462
|
+
#
|
463
|
+
module Util
|
464
|
+
def indent(s, n = 2)
|
465
|
+
s = unindent(s)
|
466
|
+
ws = ' ' * n
|
467
|
+
s.gsub(%r/^/, ws)
|
468
|
+
end
|
469
|
+
|
470
|
+
def unindent(s)
|
471
|
+
indent = nil
|
472
|
+
s.each_line do |line|
|
473
|
+
next if line =~ %r/^\s*$/
|
474
|
+
indent = line[%r/^\s*/] and break
|
475
|
+
end
|
476
|
+
indent ? s.gsub(%r/^#{ indent }/, "") : s
|
477
|
+
end
|
478
|
+
extend self
|
479
|
+
end
|
480
|
+
|
481
|
+
# template support
|
482
|
+
#
|
483
|
+
class Template
|
484
|
+
def initialize(&block)
|
485
|
+
@block = block
|
486
|
+
@template = block.call.to_s
|
487
|
+
end
|
488
|
+
def expand(b=nil)
|
489
|
+
ERB.new(Util.unindent(@template)).result((b||@block).binding)
|
490
|
+
end
|
491
|
+
alias_method 'to_s', 'expand'
|
492
|
+
end
|
493
|
+
def Template(*args, &block) Template.new(*args, &block) end
|
494
|
+
|
495
|
+
# os / platform support
|
496
|
+
#
|
497
|
+
module Platform
|
498
|
+
def Platform.windows?
|
499
|
+
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
500
|
+
end
|
501
|
+
|
502
|
+
def Platform.darwin?
|
503
|
+
(/darwin/ =~ RUBY_PLATFORM) != nil
|
504
|
+
end
|
505
|
+
|
506
|
+
def Platform.mac?
|
507
|
+
Platform.darwin?
|
508
|
+
end
|
509
|
+
|
510
|
+
def Platform.unix?
|
511
|
+
!Platform.windows?
|
512
|
+
end
|
513
|
+
|
514
|
+
def Platform.linux?
|
515
|
+
Platform.unix? and not Platform.darwin?
|
516
|
+
end
|
517
|
+
|
518
|
+
def Platform.jruby?
|
519
|
+
RUBY_ENGINE == 'jruby'
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
# colored console output support
|
524
|
+
#
|
525
|
+
This.ansi = {
|
526
|
+
:clear => "\e[0m",
|
527
|
+
:reset => "\e[0m",
|
528
|
+
:erase_line => "\e[K",
|
529
|
+
:erase_char => "\e[P",
|
530
|
+
:bold => "\e[1m",
|
531
|
+
:dark => "\e[2m",
|
532
|
+
:underline => "\e[4m",
|
533
|
+
:underscore => "\e[4m",
|
534
|
+
:blink => "\e[5m",
|
535
|
+
:reverse => "\e[7m",
|
536
|
+
:concealed => "\e[8m",
|
537
|
+
:black => "\e[30m",
|
538
|
+
:red => "\e[31m",
|
539
|
+
:green => "\e[32m",
|
540
|
+
:yellow => "\e[33m",
|
541
|
+
:blue => "\e[34m",
|
542
|
+
:magenta => "\e[35m",
|
543
|
+
:cyan => "\e[36m",
|
544
|
+
:white => "\e[37m",
|
545
|
+
:on_black => "\e[40m",
|
546
|
+
:on_red => "\e[41m",
|
547
|
+
:on_green => "\e[42m",
|
548
|
+
:on_yellow => "\e[43m",
|
549
|
+
:on_blue => "\e[44m",
|
550
|
+
:on_magenta => "\e[45m",
|
551
|
+
:on_cyan => "\e[46m",
|
552
|
+
:on_white => "\e[47m"
|
553
|
+
}
|
554
|
+
def say(phrase, *args)
|
555
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
556
|
+
options[:color] = args.shift.to_s.to_sym unless args.empty?
|
557
|
+
keys = options.keys
|
558
|
+
keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
|
559
|
+
|
560
|
+
color = options[:color]
|
561
|
+
bold = options.has_key?(:bold)
|
562
|
+
|
563
|
+
parts = [phrase]
|
564
|
+
parts.unshift(This.ansi[color]) if color
|
565
|
+
parts.unshift(This.ansi[:bold]) if bold
|
566
|
+
parts.push(This.ansi[:clear]) if parts.size > 1
|
567
|
+
|
568
|
+
method = options[:method] || :puts
|
569
|
+
|
570
|
+
Kernel.send(method, parts.join)
|
571
|
+
end
|
572
|
+
|
573
|
+
# always run out of the project dir
|
574
|
+
#
|
575
|
+
Dir.chdir(This.dir)
|
576
|
+
}
|