squared 0.4.6 → 0.4.8
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 +77 -0
- data/README.ruby.md +52 -32
- data/lib/squared/common/base.rb +1 -0
- data/lib/squared/common/class.rb +20 -5
- data/lib/squared/common/format.rb +30 -22
- data/lib/squared/common/prompt.rb +39 -1
- data/lib/squared/common/shell.rb +14 -10
- data/lib/squared/common/system.rb +3 -3
- data/lib/squared/common/utils.rb +17 -10
- data/lib/squared/config.rb +1 -2
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +39 -23
- data/lib/squared/workspace/project/base.rb +242 -243
- data/lib/squared/workspace/project/docker.rb +119 -72
- data/lib/squared/workspace/project/git.rb +252 -214
- data/lib/squared/workspace/project/node.rb +65 -67
- data/lib/squared/workspace/project/python.rb +69 -57
- data/lib/squared/workspace/project/ruby.rb +297 -98
- data/lib/squared/workspace/project/support/class.rb +199 -0
- data/lib/squared/workspace/project/support.rb +3 -0
- data/lib/squared/workspace/project.rb +1 -0
- data/lib/squared/workspace/repo.rb +6 -8
- data/lib/squared/workspace/series.rb +7 -6
- data/lib/squared/workspace.rb +1 -8
- metadata +3 -1
data/lib/squared/common/utils.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'pathname'
|
4
4
|
require 'rake'
|
5
|
+
require 'time'
|
5
6
|
|
6
7
|
module Squared
|
7
8
|
module Common
|
@@ -101,6 +102,11 @@ module Squared
|
|
101
102
|
(cur.strftime('%Q').to_i + time_offset) - (val.strftime('%Q').to_i + ret)
|
102
103
|
end
|
103
104
|
|
105
|
+
def time_since(val, ms: true)
|
106
|
+
s = ms ? '%s%L' : '%s'
|
107
|
+
Time.now.utc.strftime(s).to_i - Time.parse(val).utc.strftime(s).to_i
|
108
|
+
end
|
109
|
+
|
104
110
|
def env(key, default = nil, suffix: nil, strict: false, equals: nil, ignore: nil)
|
105
111
|
ret = env_value(key, suffix: suffix, strict: strict)
|
106
112
|
return ret == equals.to_s unless equals.nil?
|
@@ -125,7 +131,7 @@ module Squared
|
|
125
131
|
|
126
132
|
def env_bool(key, default = false, suffix: nil, strict: false, index: false)
|
127
133
|
case key
|
128
|
-
when
|
134
|
+
when ::NilClass
|
129
135
|
default
|
130
136
|
when ::String
|
131
137
|
case (val = env_value(key, suffix: suffix, strict: strict))
|
@@ -142,14 +148,6 @@ module Squared
|
|
142
148
|
end
|
143
149
|
|
144
150
|
def env_pipe(key, default = 1, suffix: nil, strict: false, root: nil)
|
145
|
-
if default.is_a?(::String)
|
146
|
-
begin
|
147
|
-
default = (root ? root.join(default) : Pathname.new(default)).realdirpath
|
148
|
-
rescue StandardError => e
|
149
|
-
default = 1
|
150
|
-
warn e
|
151
|
-
end
|
152
|
-
end
|
153
151
|
case key
|
154
152
|
when ::String
|
155
153
|
case (ret = env_value(key, suffix: suffix, strict: strict))
|
@@ -159,7 +157,16 @@ module Squared
|
|
159
157
|
when ::Numeric
|
160
158
|
return key if key.between?(0, 2)
|
161
159
|
end
|
162
|
-
|
160
|
+
begin
|
161
|
+
if default.is_a?(::String)
|
162
|
+
default = (root ? Pathname.new(root).join(default) : Pathname.new(default)).realdirpath
|
163
|
+
end
|
164
|
+
rescue StandardError => e
|
165
|
+
warn e
|
166
|
+
1
|
167
|
+
else
|
168
|
+
default
|
169
|
+
end
|
163
170
|
end
|
164
171
|
|
165
172
|
def env_match(key, default = nil, suffix: nil, strict: false, options: 0, timeout: nil)
|
data/lib/squared/config.rb
CHANGED
@@ -38,7 +38,6 @@ module Squared
|
|
38
38
|
end
|
39
39
|
|
40
40
|
@@mime_obj = {}
|
41
|
-
@@task_desc = Rake::TaskManager.record_task_metadata
|
42
41
|
|
43
42
|
attr_reader :main, :name, :project, :theme
|
44
43
|
attr_accessor :pipe
|
@@ -306,7 +305,7 @@ module Squared
|
|
306
305
|
end
|
307
306
|
|
308
307
|
def task_desc(command, *ext, target: nil)
|
309
|
-
return unless
|
308
|
+
return unless Rake::TaskManager.record_task_metadata
|
310
309
|
|
311
310
|
val = "#{ext.first}[#{target ? '' : "file?=#{File.basename(main)}.#{ext.last},"}keys+]"
|
312
311
|
args = *name.split(':').push(command, val)
|
data/lib/squared/version.rb
CHANGED
@@ -15,7 +15,8 @@ module Squared
|
|
15
15
|
global: false,
|
16
16
|
env: false
|
17
17
|
}.freeze
|
18
|
-
|
18
|
+
TASK_METADATA = Rake::TaskManager.record_task_metadata
|
19
|
+
private_constant :SCRIPT_OBJ, :TASK_METADATA
|
19
20
|
|
20
21
|
class << self
|
21
22
|
def implement(*objs, base: false)
|
@@ -38,7 +39,7 @@ module Squared
|
|
38
39
|
impl_series.alias(*args)
|
39
40
|
end
|
40
41
|
if (args = obj.bannerargs)
|
41
|
-
@attr_banner
|
42
|
+
@attr_banner.merge(args)
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
@@ -51,6 +52,14 @@ module Squared
|
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
55
|
+
def exclude(*args)
|
56
|
+
@task_exclude.merge(args.map!(&:to_sym))
|
57
|
+
end
|
58
|
+
|
59
|
+
def series_wrap(app)
|
60
|
+
impl_series.new(app, exclude: @task_exclude.to_a)
|
61
|
+
end
|
62
|
+
|
54
63
|
def baseref
|
55
64
|
impl_project.ref
|
56
65
|
end
|
@@ -64,7 +73,7 @@ module Squared
|
|
64
73
|
end
|
65
74
|
|
66
75
|
@kind_project = []
|
67
|
-
|
76
|
+
@task_exclude = SymSet.new
|
68
77
|
|
69
78
|
attr_reader :root, :home, :main, :prefix, :exception, :warning, :pipe, :verbose, :theme, :series, :closed
|
70
79
|
|
@@ -81,7 +90,7 @@ module Squared
|
|
81
90
|
@home.mkpath rescue nil
|
82
91
|
@root = @home.parent
|
83
92
|
@prefix = prefix
|
84
|
-
@series = Application.
|
93
|
+
@series = Application.series_wrap(self)
|
85
94
|
@project = {}
|
86
95
|
@kind = {}
|
87
96
|
@extensions = []
|
@@ -184,36 +193,36 @@ module Squared
|
|
184
193
|
self
|
185
194
|
end
|
186
195
|
|
187
|
-
def run(script, group: @group, ref: @ref, on: nil)
|
188
|
-
script_command :run, script, group, ref, on
|
196
|
+
def run(script = nil, group: @group, ref: @ref, on: nil, &blk)
|
197
|
+
script_command :run, script, group, ref, on, &blk
|
189
198
|
end
|
190
199
|
|
191
200
|
def script(script, group: @group, ref: @ref, on: nil)
|
192
201
|
script_command :script, script, group, ref, on
|
193
202
|
end
|
194
203
|
|
195
|
-
def depend(script, group: @group, ref: @ref, on: nil)
|
196
|
-
script_command :depend, script, group, ref, on
|
204
|
+
def depend(script = nil, group: @group, ref: @ref, on: nil, &blk)
|
205
|
+
script_command :depend, script, group, ref, on, &blk
|
197
206
|
end
|
198
207
|
|
199
208
|
def graph(script, group: @group, ref: @ref, on: nil)
|
200
209
|
script_command :graph, as_a(script, :to_s).freeze, group, ref, on
|
201
210
|
end
|
202
211
|
|
203
|
-
def clean(script, group: @group, ref: @ref, on: nil)
|
204
|
-
script_command :clean, script, group, ref, on
|
212
|
+
def clean(script = nil, group: @group, ref: @ref, on: nil, &blk)
|
213
|
+
script_command :clean, script, group, ref, on, &blk
|
205
214
|
end
|
206
215
|
|
207
|
-
def doc(script, group: @group, ref: @ref, on: nil)
|
208
|
-
script_command :doc, script, group, ref, on
|
216
|
+
def doc(script = nil, group: @group, ref: @ref, on: nil, &blk)
|
217
|
+
script_command :doc, script, group, ref, on, &blk
|
209
218
|
end
|
210
219
|
|
211
|
-
def lint(script, group: @group, ref: @ref, on: nil)
|
212
|
-
script_command :lint, script, group, ref, on
|
220
|
+
def lint(script = nil, group: @group, ref: @ref, on: nil, &blk)
|
221
|
+
script_command :lint, script, group, ref, on, &blk
|
213
222
|
end
|
214
223
|
|
215
|
-
def test(script, group: @group, ref: @ref, on: nil)
|
216
|
-
script_command :test, script, group, ref, on
|
224
|
+
def test(script = nil, group: @group, ref: @ref, on: nil, &blk)
|
225
|
+
script_command :test, script, group, ref, on, &blk
|
217
226
|
end
|
218
227
|
|
219
228
|
def log(script, group: @group, ref: @ref)
|
@@ -350,7 +359,7 @@ module Squared
|
|
350
359
|
end
|
351
360
|
|
352
361
|
def describe(data)
|
353
|
-
@describe
|
362
|
+
@describe ||= {
|
354
363
|
alias: {},
|
355
364
|
replace: [],
|
356
365
|
pattern: {}
|
@@ -408,7 +417,7 @@ module Squared
|
|
408
417
|
end
|
409
418
|
|
410
419
|
def task_desc(*args, **kwargs)
|
411
|
-
return unless
|
420
|
+
return unless TASK_METADATA
|
412
421
|
|
413
422
|
name = kwargs.delete(:name)
|
414
423
|
if @describe
|
@@ -422,7 +431,7 @@ module Squared
|
|
422
431
|
@describe[:replace].each do |pat, tmpl|
|
423
432
|
next unless val =~ pat
|
424
433
|
|
425
|
-
val = replace.($~, tmpl.dup)
|
434
|
+
val = replace.call($~, tmpl.dup)
|
426
435
|
found = true
|
427
436
|
end
|
428
437
|
if (out = @describe[:alias][val])
|
@@ -432,7 +441,7 @@ module Squared
|
|
432
441
|
@describe[:pattern].each do |key, pat|
|
433
442
|
next unless val =~ pat
|
434
443
|
|
435
|
-
val = replace.($~, key.dup)
|
444
|
+
val = replace.call($~, key.dup)
|
436
445
|
found = true
|
437
446
|
break
|
438
447
|
end
|
@@ -461,7 +470,7 @@ module Squared
|
|
461
470
|
tasks.clear
|
462
471
|
break
|
463
472
|
end
|
464
|
-
tasks
|
473
|
+
tasks.concat(items)
|
465
474
|
end
|
466
475
|
return tasks unless tasks.empty?
|
467
476
|
end
|
@@ -495,7 +504,7 @@ module Squared
|
|
495
504
|
end
|
496
505
|
|
497
506
|
def format_desc(val, opts = nil, arg: 'opts*', before: nil, after: nil, out: false)
|
498
|
-
return unless
|
507
|
+
return unless TASK_METADATA || out
|
499
508
|
|
500
509
|
val = val.to_s.split(':') if val.is_a?(String)
|
501
510
|
if before || after || opts
|
@@ -552,6 +561,8 @@ module Squared
|
|
552
561
|
end
|
553
562
|
|
554
563
|
def task_include?(obj, key, ref = nil)
|
564
|
+
return false if @series.exclude.include?(key)
|
565
|
+
|
555
566
|
task_base?(key) ? obj.has?(key, ref || baseref) : task_extend?(obj, key)
|
556
567
|
end
|
557
568
|
|
@@ -643,7 +654,12 @@ module Squared
|
|
643
654
|
puts_oe(*args, pipe: pipe)
|
644
655
|
end
|
645
656
|
|
646
|
-
def script_command(task, val, group, ref, on)
|
657
|
+
def script_command(task, val, group, ref, on, &blk)
|
658
|
+
if block_given?
|
659
|
+
val = Struct.new(:run, :block).new(val, blk)
|
660
|
+
elsif !val
|
661
|
+
return self
|
662
|
+
end
|
647
663
|
if group
|
648
664
|
label = :group
|
649
665
|
items = as_a(group, :to_sym)
|