squared 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +68 -1
- data/README.md +3 -0
- data/README.ruby.md +120 -40
- data/lib/squared/app.rb +0 -2
- data/lib/squared/common/base.rb +20 -14
- data/lib/squared/common/class.rb +18 -1
- data/lib/squared/common/format.rb +9 -9
- data/lib/squared/common/shell.rb +17 -8
- data/lib/squared/common/system.rb +56 -20
- data/lib/squared/common/utils.rb +5 -5
- data/lib/squared/config.rb +130 -82
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +168 -51
- data/lib/squared/workspace/project/base.rb +341 -130
- data/lib/squared/workspace/project/git.rb +705 -270
- data/lib/squared/workspace/project/node.rb +174 -100
- data/lib/squared/workspace/project/python.rb +176 -61
- data/lib/squared/workspace/project/ruby.rb +337 -171
- data/lib/squared/workspace/repo.rb +35 -46
- data/lib/squared/workspace/series.rb +16 -14
- metadata +2 -2
@@ -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
|
|
@@ -265,7 +274,7 @@ module Squared
|
|
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)
|
@@ -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,21 +497,11 @@ module Squared
|
|
393
497
|
end
|
394
498
|
|
395
499
|
def script_get(*args, group: nil, ref: nil)
|
396
|
-
|
397
|
-
|
398
|
-
elsif ref.is_a?(Array)
|
399
|
-
ref = ref.each
|
400
|
-
end
|
401
|
-
if ref.instance_of?(Enumerator)
|
402
|
-
ref.each do |key|
|
403
|
-
next unless (ret = @script[:ref][key])
|
500
|
+
data_get(*args, group: group, ref: ref, target: @script)
|
501
|
+
end
|
404
502
|
|
405
|
-
|
406
|
-
|
407
|
-
nil
|
408
|
-
elsif ref
|
409
|
-
@script[:ref][ref]
|
410
|
-
end
|
503
|
+
def events_get(*args, group: nil, ref: nil)
|
504
|
+
data_get(*args, group: group, ref: ref, target: @events)
|
411
505
|
end
|
412
506
|
|
413
507
|
def banner_get(*ref, group: nil)
|
@@ -496,7 +590,7 @@ module Squared
|
|
496
590
|
puts_oe(*args, pipe: pipe)
|
497
591
|
end
|
498
592
|
|
499
|
-
def script_command(task, val, group, ref)
|
593
|
+
def script_command(task, val, group, ref, on)
|
500
594
|
if group
|
501
595
|
label = :group
|
502
596
|
items = as_a(group, :to_sym)
|
@@ -504,7 +598,12 @@ module Squared
|
|
504
598
|
label = :ref
|
505
599
|
items = as_a(ref, :to_sym)
|
506
600
|
end
|
507
|
-
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
|
508
607
|
self
|
509
608
|
end
|
510
609
|
|
@@ -519,6 +618,24 @@ module Squared
|
|
519
618
|
end
|
520
619
|
end
|
521
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
|
+
|
522
639
|
def root?(path, pass: [])
|
523
640
|
return false unless path.directory?
|
524
641
|
|
@@ -541,7 +658,7 @@ module Squared
|
|
541
658
|
end
|
542
659
|
return false if state == :prod && data[:dev] == true && data[:global]
|
543
660
|
|
544
|
-
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
|
545
662
|
end
|
546
663
|
|
547
664
|
def scriptobj
|