squared 0.1.11 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +65 -86
- data/README.md +1289 -240
- data/README.ruby.md +384 -0
- data/lib/squared/app.rb +0 -2
- data/lib/squared/common/base.rb +23 -20
- data/lib/squared/common/class.rb +18 -1
- data/lib/squared/common/format.rb +20 -22
- data/lib/squared/common/prompt.rb +1 -1
- data/lib/squared/common/shell.rb +22 -14
- data/lib/squared/common/system.rb +66 -39
- data/lib/squared/common/utils.rb +6 -6
- data/lib/squared/config.rb +130 -84
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +174 -69
- data/lib/squared/workspace/project/base.rb +368 -185
- data/lib/squared/workspace/project/git.rb +728 -278
- data/lib/squared/workspace/project/node.rb +179 -119
- data/lib/squared/workspace/project/python.rb +190 -75
- data/lib/squared/workspace/project/ruby.rb +342 -178
- data/lib/squared/workspace/repo.rb +38 -47
- data/lib/squared/workspace/series.rb +16 -14
- data/squared.gemspec +3 -4
- metadata +4 -17
@@ -64,6 +64,7 @@ module Squared
|
|
64
64
|
end
|
65
65
|
|
66
66
|
@kind_project = []
|
67
|
+
@@task_desc = Rake::TaskManager.record_task_metadata
|
67
68
|
|
68
69
|
attr_reader :root, :home, :main, :prefix, :exception, :warning, :pipe, :verbose, :theme, :series, :closed
|
69
70
|
|
@@ -81,6 +82,7 @@ module Squared
|
|
81
82
|
@prefix = prefix
|
82
83
|
@series = Application.impl_series.new(self)
|
83
84
|
@project = {}
|
85
|
+
@kind = {}
|
84
86
|
@extensions = []
|
85
87
|
@pipe = env_pipe(pipe, (ARG[:OUT] && env(ARG[:OUT])) || 1, root: @home)
|
86
88
|
@exception = env_bool(exception)
|
@@ -99,6 +101,10 @@ module Squared
|
|
99
101
|
group!: {},
|
100
102
|
ref!: {}
|
101
103
|
}.freeze
|
104
|
+
@events = {
|
105
|
+
group: {},
|
106
|
+
ref: {}
|
107
|
+
}.freeze
|
102
108
|
@banner = {
|
103
109
|
group: {},
|
104
110
|
ref: {}
|
@@ -125,14 +131,18 @@ module Squared
|
|
125
131
|
.map(&:to_s)
|
126
132
|
end
|
127
133
|
@project.each_value do |proj|
|
128
|
-
|
129
|
-
|
130
|
-
proj.
|
134
|
+
if proj.enabled?
|
135
|
+
proj.populate(series.keys.dup, **kwargs)
|
136
|
+
elsif proj.enabled?(base: false)
|
137
|
+
proj.generate([], **kwargs)
|
138
|
+
else
|
139
|
+
next
|
140
|
+
end
|
131
141
|
series.populate(proj)
|
132
142
|
end
|
133
143
|
|
134
144
|
Application.kind_project.each { |obj| obj.populate(self, **kwargs) }
|
135
|
-
@extensions.each { |ext| __send__(ext, **kwargs) }
|
145
|
+
@extensions.uniq.each { |ext| __send__(ext, **kwargs) }
|
136
146
|
|
137
147
|
series.build(**kwargs)
|
138
148
|
__build__(**kwargs)
|
@@ -166,28 +176,28 @@ module Squared
|
|
166
176
|
self
|
167
177
|
end
|
168
178
|
|
169
|
-
def run(script, group: @group, ref: @ref)
|
170
|
-
script_command :run, script, group, ref
|
179
|
+
def run(script, group: @group, ref: @ref, on: nil)
|
180
|
+
script_command :run, script, group, ref, on
|
171
181
|
end
|
172
182
|
|
173
|
-
def depend(script, group: @group, ref: @ref)
|
174
|
-
script_command :depend, script, group, ref
|
183
|
+
def depend(script, group: @group, ref: @ref, on: nil)
|
184
|
+
script_command :depend, script, group, ref, on
|
175
185
|
end
|
176
186
|
|
177
|
-
def graph(script, group: @group, ref: @ref)
|
178
|
-
script_command :graph, as_a(script, :to_s).freeze, group, ref
|
187
|
+
def graph(script, group: @group, ref: @ref, on: nil)
|
188
|
+
script_command :graph, as_a(script, :to_s).freeze, group, ref, on
|
179
189
|
end
|
180
190
|
|
181
|
-
def clean(script, group: @group, ref: @ref)
|
182
|
-
script_command :clean, script, group, ref
|
191
|
+
def clean(script, group: @group, ref: @ref, on: nil)
|
192
|
+
script_command :clean, script, group, ref, on
|
183
193
|
end
|
184
194
|
|
185
|
-
def doc(script, group: @group, ref: @ref)
|
186
|
-
script_command :doc, script, group, ref
|
195
|
+
def doc(script, group: @group, ref: @ref, on: nil)
|
196
|
+
script_command :doc, script, group, ref, on
|
187
197
|
end
|
188
198
|
|
189
|
-
def test(script, group: @group, ref: @ref)
|
190
|
-
script_command :test, script, group, ref
|
199
|
+
def test(script, group: @group, ref: @ref, on: nil)
|
200
|
+
script_command :test, script, group, ref, on
|
191
201
|
end
|
192
202
|
|
193
203
|
def log(script, group: @group, ref: @ref)
|
@@ -224,16 +234,15 @@ module Squared
|
|
224
234
|
end
|
225
235
|
data[:order] << meth
|
226
236
|
end
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
end
|
235
|
-
items.each { |val| @banner[label][val.to_sym] = data }
|
237
|
+
data = {} if !command && data[:order].empty?
|
238
|
+
if group
|
239
|
+
label = :group
|
240
|
+
items = as_a(group)
|
241
|
+
else
|
242
|
+
label = :ref
|
243
|
+
items = ref ? as_a(ref) : [:_]
|
236
244
|
end
|
245
|
+
items.each { |val| @banner[label][val.to_sym] = data }
|
237
246
|
self
|
238
247
|
end
|
239
248
|
|
@@ -259,13 +268,13 @@ module Squared
|
|
259
268
|
index = 0
|
260
269
|
while @project[name]
|
261
270
|
index += 1
|
262
|
-
name =
|
271
|
+
name = "#{project}-#{index}"
|
263
272
|
end
|
264
273
|
proj = ((if !ref.is_a?(Class)
|
265
274
|
Application.find(ref, path: path)
|
266
275
|
elsif ref < Project::Base
|
267
276
|
ref
|
268
|
-
end) || Project::Base).new(self, path, name, **kwargs)
|
277
|
+
end) || @kind[name]&.last || Project::Base).new(self, path, name, **kwargs)
|
269
278
|
@project[name] = proj
|
270
279
|
__get__(:project)[name] = proj unless kwargs[:private]
|
271
280
|
proj.instance_eval(&blk) if block_given?
|
@@ -312,13 +321,49 @@ module Squared
|
|
312
321
|
self
|
313
322
|
end
|
314
323
|
|
315
|
-
def
|
316
|
-
|
317
|
-
|
318
|
-
|
324
|
+
def describe(data)
|
325
|
+
@describe = {
|
326
|
+
alias: {},
|
327
|
+
replace: [],
|
328
|
+
pattern: {}
|
329
|
+
}
|
330
|
+
data.each do |key, val|
|
331
|
+
key = key.to_s
|
332
|
+
if /\A(\\A|\^)/ =~ key || /(\\z|\$)\z/ =~ key
|
333
|
+
@describe[:replace] << [Regexp.new(key), val]
|
334
|
+
else
|
335
|
+
@describe[val.is_a?(Regexp) ? :pattern : :alias][key.to_s] = val
|
336
|
+
end
|
337
|
+
end
|
338
|
+
self
|
339
|
+
end
|
340
|
+
|
341
|
+
def find(path = nil, name: nil, group: nil, ref: nil, &blk)
|
342
|
+
ret = group ? @project.select { |_, item| item.group == group }.map(&:last) : []
|
343
|
+
if path.is_a?(Symbol)
|
344
|
+
ref ||= path
|
345
|
+
path = nil
|
346
|
+
end
|
347
|
+
if ret.empty?
|
348
|
+
ret = @project.select { |_, item| item.ref?(ref) }.map(&:last) if ref
|
349
|
+
if ret.empty? && (path || name)
|
350
|
+
path &&= rootpath(path)
|
351
|
+
name &&= name.to_s
|
352
|
+
proj = @project.find { |_, item| (path && item.path == path) || (name && item.name == name) }&.last
|
353
|
+
ret << proj if proj
|
354
|
+
end
|
355
|
+
end
|
356
|
+
return (group || ref ? ret : ret[0]) unless block_given?
|
357
|
+
|
358
|
+
ret.each(&blk)
|
359
|
+
self
|
360
|
+
end
|
361
|
+
|
362
|
+
def get(name, &blk)
|
363
|
+
ret = @project[name.to_s]
|
319
364
|
return ret unless block_given?
|
320
365
|
|
321
|
-
|
366
|
+
ret&.instance_eval(&blk)
|
322
367
|
self
|
323
368
|
end
|
324
369
|
|
@@ -326,9 +371,48 @@ module Squared
|
|
326
371
|
Application.kind_project.find { |proj| obj.instance_of?(proj) }
|
327
372
|
end
|
328
373
|
|
329
|
-
def task_name(val
|
330
|
-
|
331
|
-
|
374
|
+
def task_name(val)
|
375
|
+
prefix ? task_join(prefix, val) : val.to_s
|
376
|
+
end
|
377
|
+
|
378
|
+
def task_localname(val)
|
379
|
+
prefix && val.is_a?(String) ? val.sub(/\A#{Regexp.escape(prefix)}:/o, '') : val.to_s
|
380
|
+
end
|
381
|
+
|
382
|
+
def task_desc(*args, **kwargs)
|
383
|
+
return unless @@task_desc
|
384
|
+
|
385
|
+
name = kwargs.delete(:name)
|
386
|
+
if @describe
|
387
|
+
val = name || task_join(*args)
|
388
|
+
found = false
|
389
|
+
replace = lambda do |data, out|
|
390
|
+
if (index = data.size) > 0
|
391
|
+
data.to_a.reverse_each { |group| out.sub!("%#{index -= 1}", group) }
|
392
|
+
end
|
393
|
+
out
|
394
|
+
end
|
395
|
+
@describe[:replace].each do |pat, key|
|
396
|
+
next unless (data = pat.match(val))
|
397
|
+
|
398
|
+
val = replace.(data, key.dup)
|
399
|
+
found = true
|
400
|
+
end
|
401
|
+
if (out = @describe[:alias][val])
|
402
|
+
val = out
|
403
|
+
found = true
|
404
|
+
else
|
405
|
+
@describe[:pattern].each do |key, pat|
|
406
|
+
next unless (data = pat.match(val))
|
407
|
+
|
408
|
+
val = replace.(data, key.dup)
|
409
|
+
found = true
|
410
|
+
break
|
411
|
+
end
|
412
|
+
end
|
413
|
+
args = Shell.split_escape(val, char: ':').map! { |s| s.gsub('\\:', ':') } if found
|
414
|
+
end
|
415
|
+
desc message(*args, **kwargs)
|
332
416
|
end
|
333
417
|
|
334
418
|
def task_namespace(val, first: false)
|
@@ -343,7 +427,7 @@ module Squared
|
|
343
427
|
tasks << key if obj.has?(key, baseref)
|
344
428
|
elsif (batch = series.batch_get(key))
|
345
429
|
obj.allref.each do |ref|
|
346
|
-
next unless
|
430
|
+
next unless (data = batch[ref])
|
347
431
|
|
348
432
|
data.each do |val|
|
349
433
|
if (items = task_resolve(obj, val)).empty?
|
@@ -362,7 +446,7 @@ module Squared
|
|
362
446
|
return [] if (base && !obj.ref?(baseref)) || !(data = series.alias_get(key))
|
363
447
|
|
364
448
|
obj.allref.each do |ref|
|
365
|
-
next unless
|
449
|
+
next unless (alt = data[ref])
|
366
450
|
|
367
451
|
ret = task_resolve(obj, alt)
|
368
452
|
break unless ret.empty?
|
@@ -383,6 +467,26 @@ module Squared
|
|
383
467
|
task_defined?(ret = task_join(key, 'sync')) ? ret : key
|
384
468
|
end
|
385
469
|
|
470
|
+
def format_desc(val, opts = nil, arg: 'opts*', before: nil, after: nil, out: false)
|
471
|
+
return unless @@task_desc || out
|
472
|
+
|
473
|
+
val = val.to_s.split(':') if val.is_a?(String)
|
474
|
+
if before || after || opts
|
475
|
+
pos = []
|
476
|
+
pos << (before.is_a?(Array) ? before.join(',') : before) if before
|
477
|
+
if opts
|
478
|
+
pos << if opts.is_a?(Array)
|
479
|
+
arg ? "#{arg}=#{opts.join(',')}" : opts.join('|')
|
480
|
+
else
|
481
|
+
opts
|
482
|
+
end
|
483
|
+
end
|
484
|
+
pos << (after.is_a?(Array) ? after.join(',') : after) if after
|
485
|
+
val << "#{val.pop}[#{pos.join(',')}]"
|
486
|
+
end
|
487
|
+
out ? message(*val) : task_desc(*val)
|
488
|
+
end
|
489
|
+
|
386
490
|
def script_find(*args)
|
387
491
|
args.reverse_each do |val|
|
388
492
|
next unless val && (ret = val.is_a?(Symbol) ? @script[:ref!][val] : @script[:group!][val.to_sym])
|
@@ -393,20 +497,11 @@ module Squared
|
|
393
497
|
end
|
394
498
|
|
395
499
|
def script_get(*args, group: nil, ref: nil)
|
396
|
-
|
397
|
-
|
398
|
-
elsif ref
|
399
|
-
if ref.is_a?(Enumerable)
|
400
|
-
ref.each do |key|
|
401
|
-
next unless (ret = @script[:ref][key])
|
500
|
+
data_get(*args, group: group, ref: ref, target: @script)
|
501
|
+
end
|
402
502
|
|
403
|
-
|
404
|
-
|
405
|
-
nil
|
406
|
-
else
|
407
|
-
@script[:ref][ref]
|
408
|
-
end
|
409
|
-
end
|
503
|
+
def events_get(*args, group: nil, ref: nil)
|
504
|
+
data_get(*args, group: group, ref: ref, target: @events)
|
410
505
|
end
|
411
506
|
|
412
507
|
def banner_get(*ref, group: nil)
|
@@ -453,14 +548,6 @@ module Squared
|
|
453
548
|
Rake::Win32.windows?
|
454
549
|
end
|
455
550
|
|
456
|
-
def jruby?
|
457
|
-
RUBY_ENGINE == 'jruby'
|
458
|
-
end
|
459
|
-
|
460
|
-
def jruby_win?
|
461
|
-
jruby? && windows?
|
462
|
-
end
|
463
|
-
|
464
551
|
def rootpath(*args)
|
465
552
|
root.join(*args)
|
466
553
|
end
|
@@ -494,21 +581,16 @@ module Squared
|
|
494
581
|
private
|
495
582
|
|
496
583
|
def __build__(default: nil, **)
|
497
|
-
unless task_defined?(
|
498
|
-
|
499
|
-
|
500
|
-
end
|
501
|
-
end
|
502
|
-
if default && task_defined?(out = task_name(default))
|
503
|
-
task Rake.application.default_task_name => out
|
504
|
-
end
|
584
|
+
return unless default && task_defined?(out = task_name(default))
|
585
|
+
|
586
|
+
task Rake.application.default_task_name => out
|
505
587
|
end
|
506
588
|
|
507
589
|
def puts(*args)
|
508
590
|
puts_oe(*args, pipe: pipe)
|
509
591
|
end
|
510
592
|
|
511
|
-
def script_command(task, val, group, ref)
|
593
|
+
def script_command(task, val, group, ref, on)
|
512
594
|
if group
|
513
595
|
label = :group
|
514
596
|
items = as_a(group, :to_sym)
|
@@ -516,7 +598,12 @@ module Squared
|
|
516
598
|
label = :ref
|
517
599
|
items = as_a(ref, :to_sym)
|
518
600
|
end
|
519
|
-
items.each
|
601
|
+
items.each do |name|
|
602
|
+
(@script[label][name] ||= {})[task] = val
|
603
|
+
next unless on.is_a?(Hash)
|
604
|
+
|
605
|
+
(@events[label][name] ||= {})[task] = on
|
606
|
+
end
|
520
607
|
self
|
521
608
|
end
|
522
609
|
|
@@ -531,6 +618,24 @@ module Squared
|
|
531
618
|
end
|
532
619
|
end
|
533
620
|
|
621
|
+
def data_get(*args, group: nil, ref: nil, target: nil)
|
622
|
+
if group
|
623
|
+
target[:group][group.to_sym]
|
624
|
+
elsif ref.is_a?(Array)
|
625
|
+
ref = ref.each
|
626
|
+
end
|
627
|
+
if ref.instance_of?(Enumerator)
|
628
|
+
ref.each do |key|
|
629
|
+
next unless (ret = target[:ref][key])
|
630
|
+
|
631
|
+
return ret if args.empty? || args.any? { |val| ret.key?(val) }
|
632
|
+
end
|
633
|
+
nil
|
634
|
+
elsif ref
|
635
|
+
target[:ref][ref]
|
636
|
+
end
|
637
|
+
end
|
638
|
+
|
534
639
|
def root?(path, pass: [])
|
535
640
|
return false unless path.directory?
|
536
641
|
|
@@ -553,7 +658,7 @@ module Squared
|
|
553
658
|
end
|
554
659
|
return false if state == :prod && data[:dev] == true && data[:global]
|
555
660
|
|
556
|
-
target && pat.is_a?(Regexp) ? as_a(target).any? { |val|
|
661
|
+
target && pat.is_a?(Regexp) ? as_a(target).any? { |val| val =~ pat } : pat == true
|
557
662
|
end
|
558
663
|
|
559
664
|
def scriptobj
|