rails_build 1.2.0 → 2.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,37 +1,452 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
1
+ This.author = "Ara T. Howard"
2
+ This.email = "ara.t.howard@gmail.com"
3
+ This.github = "ahoward"
4
+ This.homepage = "https://github.com/#{ This.github }/#{ This.basename }"
5
+ This.repo = "https://github.com/#{ This.github }/#{ This.basename }"
6
+
7
+ task :license do
8
+ open('LICENSE', 'w'){|fd| fd.puts "Ruby"}
9
+ end
10
+
11
+ task :default do
12
+ puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
13
+ end
14
+
15
+ task :test do
16
+ run_tests!
5
17
  end
6
18
 
7
- require 'rdoc/task'
19
+ namespace :test do
20
+ task(:unit){ run_tests!(:unit) }
21
+ task(:functional){ run_tests!(:functional) }
22
+ task(:integration){ run_tests!(:integration) }
23
+ end
24
+
25
+ def run_tests!(which = nil)
26
+ which ||= '**'
27
+ test_dir = File.join(This.dir, "test")
28
+ test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
29
+ test_rbs = Dir.glob(test_glob).sort
30
+
31
+ div = ('=' * 119)
32
+ line = ('-' * 119)
33
+
34
+ test_rbs.each_with_index do |test_rb, index|
35
+ testno = index + 1
36
+ command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
8
37
 
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'RailsBuild'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.md')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
38
+ puts
39
+ say(div, :color => :cyan, :bold => true)
40
+ say("@#{ testno } => ", :bold => true, :method => :print)
41
+ say(command, :color => :cyan, :bold => true)
42
+ say(line, :color => :cyan, :bold => true)
43
+
44
+ system(command)
45
+
46
+ say(line, :color => :cyan, :bold => true)
47
+
48
+ status = $?.exitstatus
49
+
50
+ if status.zero?
51
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
52
+ say("SUCCESS", :color => :green, :bold => true)
53
+ else
54
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
55
+ say("FAILURE", :color => :red, :bold => true)
56
+ end
57
+ say(line, :color => :cyan, :bold => true)
58
+
59
+ exit(status) unless status.zero?
60
+ end
15
61
  end
16
62
 
17
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
- load 'rails/tasks/engine.rake'
19
63
 
64
+ task :gemspec do
65
+ ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
66
+ ignore_directories = ['pkg']
67
+ ignore_files = ['test/log']
68
+
69
+ shiteless =
70
+ lambda do |list|
71
+ list.delete_if do |entry|
72
+ next unless test(?e, entry)
73
+ extension = File.basename(entry).split(%r/[.]/).last
74
+ ignore_extensions.any?{|ext| ext === extension}
75
+ end
76
+
77
+ list.delete_if do |entry|
78
+ next unless test(?d, entry)
79
+ dirname = File.expand_path(entry)
80
+ ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
81
+ end
82
+
83
+ list.delete_if do |entry|
84
+ next unless test(?f, entry)
85
+ filename = File.expand_path(entry)
86
+ ignore_files.any?{|file| File.expand_path(file) == filename}
87
+ end
88
+ end
89
+
90
+ name = This.basename
91
+ object = This.object
92
+ version = This.version
93
+ files = shiteless[Dir::glob("**/**")]
94
+ executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
95
+ summary = Util.unindent(This.summary).strip
96
+ description = Util.unindent(This.description).strip
97
+ license = This.license.strip
20
98
 
21
- load 'rails/tasks/statistics.rake'
99
+ if This.extensions.nil?
100
+ This.extensions = []
101
+ extensions = This.extensions
102
+ %w( Makefile configure extconf.rb ).each do |ext|
103
+ extensions << ext if File.exist?(ext)
104
+ end
105
+ end
106
+ extensions = [extensions].flatten.compact
22
107
 
108
+ if This.dependencies.nil?
109
+ dependencies = []
110
+ else
111
+ case This.dependencies
112
+ when Hash
113
+ dependencies = This.dependencies.values
114
+ when Array
115
+ dependencies = This.dependencies
116
+ end
117
+ end
23
118
 
119
+ template =
120
+ if test(?e, 'gemspec.erb')
121
+ Template{ IO.read('gemspec.erb') }
122
+ else
123
+ Template {
124
+ <<-__
125
+ ## <%= name %>.gemspec
126
+ #
24
127
 
25
- require 'bundler/gem_tasks'
128
+ Gem::Specification::new do |spec|
129
+ spec.name = <%= name.inspect %>
130
+ spec.version = <%= version.inspect %>
131
+ spec.required_ruby_version = '>= 3.0'
132
+ spec.platform = Gem::Platform::RUBY
133
+ spec.summary = <%= summary.inspect %>
134
+ spec.description = <%= description.inspect %>
135
+ spec.license = <%= license.inspect %>
26
136
 
27
- require 'rake/testtask'
137
+ spec.files =\n<%= files.sort.pretty_inspect %>
138
+ spec.executables = <%= executables.inspect %>
139
+
140
+ spec.require_path = "lib"
28
141
 
29
- Rake::TestTask.new(:test) do |t|
30
- t.libs << 'lib'
31
- t.libs << 'test'
32
- t.pattern = 'test/**/*_test.rb'
33
- t.verbose = false
142
+ <% dependencies.each do |lib_version| %>
143
+ spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>)
144
+ <% end %>
145
+
146
+ spec.extensions.push(*<%= extensions.inspect %>)
147
+
148
+ spec.author = <%= This.author.inspect %>
149
+ spec.email = <%= This.email.inspect %>
150
+ spec.homepage = <%= This.homepage.inspect %>
151
+ end
152
+ __
153
+ }
154
+ end
155
+
156
+ Fu.mkdir_p(This.pkgdir)
157
+ gemspec = "#{ name }.gemspec"
158
+ open(gemspec, "w"){|fd| fd.puts(template)}
159
+ This.gemspec = gemspec
160
+ end
161
+
162
+ task :gem => [:clean, :gemspec] do
163
+ Fu.mkdir_p(This.pkgdir)
164
+ before = Dir['*.gem']
165
+ cmd = "gem build #{ This.gemspec }"
166
+ `#{ cmd }`
167
+ after = Dir['*.gem']
168
+ gem = ((after - before).first || after.first) or abort('no gem!')
169
+ Fu.mv(gem, This.pkgdir)
170
+ This.gem = File.join(This.pkgdir, File.basename(gem))
34
171
  end
35
172
 
173
+ task :README => [:readme]
174
+
175
+ task :readme do
176
+ samples = ''
177
+ prompt = '~ > '
178
+ lib = This.lib
179
+ version = This.version
180
+
181
+ Dir['sample*/**/**.rb'].sort.each do |sample|
182
+ link = "[#{ sample }](#{ This.repo }/blob/main/#{ sample })"
183
+ samples << " #### <========< #{ link } >========>\n"
184
+
185
+ cmd = "cat #{ sample }"
186
+ samples << "```sh\n"
187
+ samples << Util.indent(prompt + cmd, 2) << "\n"
188
+ samples << "```\n"
189
+ samples << "```ruby\n"
190
+ samples << Util.indent(IO.binread(sample), 4) << "\n"
191
+ samples << "```\n"
192
+
193
+ samples << "\n"
194
+
195
+ cmd = "ruby #{ sample }"
196
+ samples << "```sh\n"
197
+ samples << Util.indent(prompt + cmd, 2) << "\n"
198
+ samples << "```\n"
199
+
200
+ cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
201
+ oe = `#{ cmd } 2>&1`
202
+ samples << "```txt\n"
203
+ samples << Util.indent(oe, 4) << "\n"
204
+ samples << "```\n"
205
+
206
+ samples << "\n"
207
+ end
208
+
209
+ This.samples = samples
210
+
211
+ template =
212
+ case
213
+ when test(?e, 'README.md.erb')
214
+ Template{ IO.read('README.md.erb') }
215
+ when test(?e, 'README.erb')
216
+ Template{ IO.read('README.erb') }
217
+ else
218
+ Template {
219
+ <<-__
220
+ NAME
221
+ #{ lib }
222
+
223
+ DESCRIPTION
224
+
225
+ INSTALL
226
+ gem install #{ lib }
227
+
228
+ SAMPLES
229
+ #{ samples }
230
+ __
231
+ }
232
+ end
233
+
234
+ IO.binwrite('README.md', template)
235
+ end
236
+
237
+ task :clean do
238
+ Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
239
+ end
240
+
241
+ task :release => [:dist, :gem] do
242
+ gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
243
+ abort "which one? : #{ gems.inspect }" if gems.size > 1
244
+ abort "no gems?" if gems.size < 1
245
+
246
+ cmd = "gem push #{ This.gem }"
247
+ puts cmd
248
+ puts
249
+ system(cmd)
250
+ abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
251
+ end
252
+
253
+
254
+
255
+
256
+
257
+ BEGIN {
258
+ # support for this rakefile
259
+ #
260
+ $VERBOSE = nil
261
+
262
+ require 'ostruct'
263
+ require 'erb'
264
+ require 'fileutils'
265
+ require 'rbconfig'
266
+ require 'pp'
267
+
268
+ # fu shortcut!
269
+ #
270
+ Fu = FileUtils
271
+
272
+ # guess a bunch of stuff about this rakefile/environment based on the
273
+ #
274
+ This = OpenStruct.new
275
+
276
+ This.file = File.expand_path(__FILE__)
277
+ This.dir = File.dirname(This.file)
278
+ This.pkgdir = File.join(This.dir, 'pkg')
279
+ This.basename = File.basename(This.dir)
280
+
281
+ # load actual shit _lib
282
+ #
283
+ _libpath = ["./lib/#{ This.basename }/_lib.rb", "./lib/#{ This.basename }.rb"]
284
+ _lib = _libpath.detect{|l| test(?s, l)}
285
+
286
+ abort "could not find a _lib in ./lib/ via #{ _libpath.join(':') }" unless _lib
287
+
288
+ This._lib = _lib
289
+ require This._lib
290
+
291
+ # extract the name from the _lib
292
+ #
293
+ lines = IO.binread(This._lib).split("\n")
294
+ re = %r`\A \s* (module|class) \s+ ([^\s]+) \s* \z`iomx
295
+ name = nil
296
+ lines.each do |line|
297
+ match = line.match(re)
298
+ if match
299
+ name = match.to_a.last
300
+ break
301
+ end
302
+ end
303
+ unless name
304
+ abort "could not extract `name` from #{ This._lib }"
305
+ end
306
+ This.name = name
307
+ This.basename = This.name.gsub(/([A-Z][a-z])/){|ab| "_#{ ab }"}.gsub(/^_/, '').downcase
308
+
309
+ # now, fully grok This
310
+ #
311
+ This.object = eval(This.name)
312
+ This.version = This.object.version
313
+ This.dependencies = This.object.dependencies
314
+ This.summary = This.object.summary
315
+ This.description = This.object.respond_to?(:description) ? This.object.description : This.summary
316
+ This.license = This.object.respond_to?(:license) ? This.object.license : IO.binread('LICENSE').strip
317
+
318
+ # discover full path to this ruby executable
319
+ #
320
+ c = RbConfig::CONFIG
321
+ bindir = c["bindir"] || c['BINDIR']
322
+ ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
323
+ ruby_ext = c['EXEEXT'] || ''
324
+ ruby = File.join(bindir, (ruby_install_name + ruby_ext))
325
+ This.ruby = ruby
326
+
327
+ # some utils, alwayze teh utils...
328
+ #
329
+ module Util
330
+ def indent(s, n = 2)
331
+ s = unindent(s)
332
+ ws = ' ' * n
333
+ s.gsub(%r/^/, ws)
334
+ end
335
+
336
+ def unindent(s)
337
+ indent = nil
338
+ s.each_line do |line|
339
+ next if line =~ %r/^\s*$/
340
+ indent = line[%r/^\s*/] and break
341
+ end
342
+ unindented = indent ? s.gsub(%r/^#{ indent }/, "") : s
343
+ unindented.strip
344
+ end
345
+ extend self
346
+ end
347
+
348
+ # template support
349
+ #
350
+ class Template
351
+ def Template.indent(string, n = 2)
352
+ string = string.to_s
353
+ n = n.to_i
354
+ padding = (42 - 10).chr * n
355
+ initial = %r/^#{ Regexp.escape(padding) }/
356
+ #require 'debug'
357
+ #binding.break
358
+ Util.indent(string, n).sub(initial, '')
359
+ end
360
+ def initialize(&block)
361
+ @block = block
362
+ @template = block.call.to_s
363
+ end
364
+ def expand(b=nil)
365
+ ERB.new(Util.unindent(@template), trim_mode: '%<>-').result((b||@block).binding)
366
+ end
367
+ alias_method 'to_s', 'expand'
368
+ end
369
+ def Template(*args, &block) Template.new(*args, &block) end
370
+
371
+ # os / platform support
372
+ #
373
+ module Platform
374
+ def Platform.windows?
375
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
376
+ end
377
+
378
+ def Platform.darwin?
379
+ (/darwin/ =~ RUBY_PLATFORM) != nil
380
+ end
381
+
382
+ def Platform.mac?
383
+ Platform.darwin?
384
+ end
385
+
386
+ def Platform.unix?
387
+ !Platform.windows?
388
+ end
389
+
390
+ def Platform.linux?
391
+ Platform.unix? and not Platform.darwin?
392
+ end
393
+
394
+ def Platform.jruby?
395
+ RUBY_ENGINE == 'jruby'
396
+ end
397
+ end
398
+
399
+ # colored console output support
400
+ #
401
+ This.ansi = {
402
+ :clear => "\e[0m",
403
+ :reset => "\e[0m",
404
+ :erase_line => "\e[K",
405
+ :erase_char => "\e[P",
406
+ :bold => "\e[1m",
407
+ :dark => "\e[2m",
408
+ :underline => "\e[4m",
409
+ :underscore => "\e[4m",
410
+ :blink => "\e[5m",
411
+ :reverse => "\e[7m",
412
+ :concealed => "\e[8m",
413
+ :black => "\e[30m",
414
+ :red => "\e[31m",
415
+ :green => "\e[32m",
416
+ :yellow => "\e[33m",
417
+ :blue => "\e[34m",
418
+ :magenta => "\e[35m",
419
+ :cyan => "\e[36m",
420
+ :white => "\e[37m",
421
+ :on_black => "\e[40m",
422
+ :on_red => "\e[41m",
423
+ :on_green => "\e[42m",
424
+ :on_yellow => "\e[43m",
425
+ :on_blue => "\e[44m",
426
+ :on_magenta => "\e[45m",
427
+ :on_cyan => "\e[46m",
428
+ :on_white => "\e[47m"
429
+ }
430
+ def say(phrase, *args)
431
+ options = args.last.is_a?(Hash) ? args.pop : {}
432
+ options[:color] = args.shift.to_s.to_sym unless args.empty?
433
+ keys = options.keys
434
+ keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
435
+
436
+ color = options[:color]
437
+ bold = options.has_key?(:bold)
438
+
439
+ parts = [phrase]
440
+ parts.unshift(This.ansi[color]) if color
441
+ parts.unshift(This.ansi[:bold]) if bold
442
+ parts.push(This.ansi[:clear]) if parts.size > 1
443
+
444
+ method = options[:method] || :puts
445
+
446
+ Kernel.send(method, parts.join)
447
+ end
36
448
 
37
- task default: :test
449
+ # always run out of the project dir
450
+ #
451
+ Dir.chdir(This.dir)
452
+ }