squared 0.4.7 → 0.4.9
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 +106 -1
- data/README.ruby.md +57 -28
- data/lib/squared/common/base.rb +1 -0
- data/lib/squared/common/class.rb +19 -1
- data/lib/squared/common/format.rb +35 -38
- data/lib/squared/common/prompt.rb +66 -3
- data/lib/squared/common/shell.rb +30 -19
- data/lib/squared/common/system.rb +3 -3
- data/lib/squared/common/utils.rb +11 -10
- data/lib/squared/config.rb +4 -5
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +46 -34
- data/lib/squared/workspace/project/base.rb +191 -70
- data/lib/squared/workspace/project/docker.rb +79 -40
- data/lib/squared/workspace/project/git.rb +742 -392
- data/lib/squared/workspace/project/node.rb +35 -51
- data/lib/squared/workspace/project/python.rb +42 -48
- data/lib/squared/workspace/project/ruby.rb +316 -100
- data/lib/squared/workspace/project/support/class.rb +37 -19
- data/lib/squared/workspace/repo.rb +10 -12
- data/lib/squared/workspace/series.rb +11 -7
- data/lib/squared/workspace.rb +2 -9
- metadata +3 -3
data/lib/squared/common/shell.rb
CHANGED
@@ -8,12 +8,12 @@ module Squared
|
|
8
8
|
module Shell
|
9
9
|
module_function
|
10
10
|
|
11
|
-
def shell_escape(val, quote: false, force: false, double: false, override: false)
|
11
|
+
def shell_escape(val, quote: false, force: false, double: false, option: false, override: false)
|
12
12
|
if (r = /\A(--?)([^= ]+)((=|\s+)(["'])?(.+?)(["'])?)?\z/m.match(val = val.to_s))
|
13
|
-
return val if !r[3] || (!r[5] && r[6].match?(/\s/))
|
13
|
+
return val if !r[3] || (!r[5] && !r[6].match?(/\s/))
|
14
14
|
|
15
15
|
combine = lambda do |opt|
|
16
|
-
if r[2] =~ /\A(["'])(.+)\1\z/
|
16
|
+
if r[2] =~ /\A(["'])(.+)\1\z/m
|
17
17
|
double = $1 == '"'
|
18
18
|
r[2] = $2
|
19
19
|
override = true
|
@@ -21,22 +21,33 @@ module Squared
|
|
21
21
|
r[1] + r[2] + r[4] + shell_quote(opt, double: double, force: force, override: override)
|
22
22
|
end
|
23
23
|
if r[5] == r[7]
|
24
|
-
r[5] ? val : combine.(r[6])
|
24
|
+
r[5] ? val : combine.call(r[6])
|
25
25
|
else
|
26
26
|
force = true
|
27
|
-
combine.(r[5] + r[6] + r[7])
|
27
|
+
combine.call(r[5] + r[6] + r[7])
|
28
28
|
end
|
29
|
+
elsif option && val =~ /\A([^=]+)=(.+)\z/m
|
30
|
+
return val if $2.match?(/\A(["']).+\1\z/m)
|
31
|
+
|
32
|
+
"#{$1}=%s" % if $2.include?(' ')
|
33
|
+
shell_quote($2, option: false)
|
34
|
+
else
|
35
|
+
Rake::Win32.windows? ? $2 : Shellwords.escape($2)
|
36
|
+
end
|
29
37
|
elsif Rake::Win32.windows?
|
30
38
|
quote ? shell_quote(val, double: double, force: force) : val
|
31
39
|
else
|
32
|
-
Shellwords.escape(val)
|
40
|
+
val.empty? ? '' : Shellwords.escape(val)
|
33
41
|
end
|
34
42
|
end
|
35
43
|
|
36
44
|
def shell_quote(val, option: true, force: true, double: false, override: false)
|
37
45
|
val = val.to_s
|
38
|
-
return val if !force && !val.include?(' ')
|
39
|
-
|
46
|
+
return val if (!force && !val.include?(' ')) || val.empty?
|
47
|
+
|
48
|
+
if option && val.match?(/(?:\A|\A[^=\s]+(?:=|\s+)|#{Rake::Win32.windows? ? '[\\\/]' : '\/'})(["']).+\1\z/m)
|
49
|
+
return val
|
50
|
+
end
|
40
51
|
|
41
52
|
if double || Rake::Win32.windows? || (ARG[:QUOTE] == '"' && !override)
|
42
53
|
"\"#{val.gsub(/(?<!\\)"/, '\\"')}\""
|
@@ -45,8 +56,8 @@ module Squared
|
|
45
56
|
end
|
46
57
|
end
|
47
58
|
|
48
|
-
def shell_option(flag, val = nil, escape: true, quote: true,
|
49
|
-
merge: false)
|
59
|
+
def shell_option(flag, val = nil, escape: true, quote: true, option: true, force: true, double: false,
|
60
|
+
merge: false, override: false)
|
50
61
|
flag = flag.to_s
|
51
62
|
if flag =~ /\A(["'])(.+)\1\z/
|
52
63
|
double = $1 == '"'
|
@@ -66,30 +77,30 @@ module Squared
|
|
66
77
|
"#{a}#{flag}#{if val
|
67
78
|
"#{b}#{if escape
|
68
79
|
shell_escape(val, quote: quote, double: double, override: override)
|
80
|
+
elsif quote
|
81
|
+
shell_quote(val, option: option, force: force, double: double, override: override)
|
69
82
|
else
|
70
|
-
|
83
|
+
val
|
71
84
|
end}"
|
72
85
|
end}"
|
73
86
|
end
|
74
87
|
|
75
|
-
def shell_split(val,
|
76
|
-
ret =
|
77
|
-
|
78
|
-
|
79
|
-
ret.map! { |opt| shell_escape(opt, quote: quote) } if escape
|
88
|
+
def shell_split(val, quote: false, force: false, join: nil)
|
89
|
+
ret = val.shellsplit
|
90
|
+
ret.map! { |opt| shell_escape(opt, quote: quote, force: force, double: true, option: true) }
|
80
91
|
return ret unless join
|
81
92
|
|
82
93
|
ret.join(join.is_a?(::String) ? join : ' ')
|
83
94
|
end
|
84
95
|
|
85
96
|
def fill_option(val, double: false)
|
86
|
-
return "-#{val}" if val.match?(
|
97
|
+
return "-#{val}" if val.match?(/\A(?:[a-z]\d*|\d)\z/i)
|
87
98
|
|
88
99
|
shell_escape(val.start_with?('-') ? val : "--#{val}", double: double)
|
89
100
|
end
|
90
101
|
|
91
|
-
def quote_option(flag, val, double: false)
|
92
|
-
shell_option(flag, val, escape: false, double: double)
|
102
|
+
def quote_option(flag, val, option: true, double: false, merge: false)
|
103
|
+
shell_option(flag, val, escape: false, option: option, double: double, merge: merge)
|
93
104
|
end
|
94
105
|
|
95
106
|
def basic_option(flag, val, merge: false)
|
@@ -30,10 +30,10 @@ module Squared
|
|
30
30
|
if pass
|
31
31
|
exclude = []
|
32
32
|
pass = [pass] unless pass.is_a?(::Array)
|
33
|
-
pass.each { |val| exclude.concat(Dir.glob(src
|
33
|
+
pass.each { |val| exclude.concat(Dir.glob(src + val)) }
|
34
34
|
end
|
35
35
|
(glob.is_a?(::Array) ? glob : [glob]).each do |val|
|
36
|
-
Dir.glob(src
|
36
|
+
Dir.glob(src + val) do |path|
|
37
37
|
next if exclude&.include?(path) || (path = Pathname.new(path)).directory?
|
38
38
|
|
39
39
|
dir = dest.join(path.relative_path_from(src)).dirname
|
@@ -89,7 +89,7 @@ module Squared
|
|
89
89
|
case link
|
90
90
|
when 'hard', 1
|
91
91
|
FileUtils.ln(src, dest, force: force, verbose: verbose)
|
92
|
-
when
|
92
|
+
when TrueClass, 'soft', 0
|
93
93
|
FileUtils.ln_s(src, dest, force: force, verbose: verbose)
|
94
94
|
else
|
95
95
|
FileUtils.cp(src, dest, verbose: verbose)
|
data/lib/squared/common/utils.rb
CHANGED
@@ -131,7 +131,7 @@ module Squared
|
|
131
131
|
|
132
132
|
def env_bool(key, default = false, suffix: nil, strict: false, index: false)
|
133
133
|
case key
|
134
|
-
when
|
134
|
+
when ::NilClass
|
135
135
|
default
|
136
136
|
when ::String
|
137
137
|
case (val = env_value(key, suffix: suffix, strict: strict))
|
@@ -148,14 +148,6 @@ module Squared
|
|
148
148
|
end
|
149
149
|
|
150
150
|
def env_pipe(key, default = 1, suffix: nil, strict: false, root: nil)
|
151
|
-
if default.is_a?(::String)
|
152
|
-
begin
|
153
|
-
default = (root ? Pathname.new(root).join(default) : Pathname.new(default)).realdirpath
|
154
|
-
rescue StandardError => e
|
155
|
-
default = 1
|
156
|
-
warn e
|
157
|
-
end
|
158
|
-
end
|
159
151
|
case key
|
160
152
|
when ::String
|
161
153
|
case (ret = env_value(key, suffix: suffix, strict: strict))
|
@@ -165,7 +157,16 @@ module Squared
|
|
165
157
|
when ::Numeric
|
166
158
|
return key if key.between?(0, 2)
|
167
159
|
end
|
168
|
-
|
160
|
+
begin
|
161
|
+
if default.is_a?(::String)
|
162
|
+
default = (root ? Pathname.new(root) + default : Pathname.new(default)).realdirpath
|
163
|
+
end
|
164
|
+
rescue StandardError => e
|
165
|
+
warn e
|
166
|
+
1
|
167
|
+
else
|
168
|
+
default
|
169
|
+
end
|
169
170
|
end
|
170
171
|
|
171
172
|
def env_match(key, default = nil, suffix: nil, strict: false, options: 0, timeout: nil)
|
data/lib/squared/config.rb
CHANGED
@@ -14,7 +14,7 @@ module Squared
|
|
14
14
|
class << self
|
15
15
|
def parse(gem, namespace, ext = [pkg])
|
16
16
|
require gem
|
17
|
-
obj = eval
|
17
|
+
obj = eval namespace
|
18
18
|
ext = [ext] unless ext.is_a?(Array)
|
19
19
|
ext.each { |val| @@mime_obj[val] = [obj, ext] }
|
20
20
|
rescue LoadError, NameError => e
|
@@ -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
|
@@ -128,7 +127,7 @@ module Squared
|
|
128
127
|
if enabled?
|
129
128
|
if namespace
|
130
129
|
require(gem || type)
|
131
|
-
obj = eval
|
130
|
+
obj = eval namespace
|
132
131
|
else
|
133
132
|
as_a(ext).each do |val|
|
134
133
|
next unless (data = @@mime_obj[val])
|
@@ -164,7 +163,7 @@ module Squared
|
|
164
163
|
def also(path, type = nil, name: nil, **kwargs)
|
165
164
|
return self if @mime.frozen? || !(file = basepath(path)).exist?
|
166
165
|
|
167
|
-
ext = mimetype
|
166
|
+
ext = mimetype file
|
168
167
|
type ||= ext
|
169
168
|
name ||= file.basename.to_s.chomp(File.extname(file))
|
170
169
|
add(type, ext: ext, command: name, file: file, **kwargs)
|
@@ -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)
|
@@ -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
|
|
@@ -74,20 +83,20 @@ module Squared
|
|
74
83
|
basename = @home.basename.to_s
|
75
84
|
if main
|
76
85
|
@main = main.to_s.freeze
|
77
|
-
@home
|
86
|
+
@home += @main unless @main == basename || (windows? && @main.downcase == basename.downcase)
|
78
87
|
else
|
79
88
|
@main = basename.freeze
|
80
89
|
end
|
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 = []
|
88
97
|
@envname = @main.gsub(/[^\w]+/, '_').upcase.freeze
|
89
98
|
@pipe = env_pipe(pipe, (ARG[:OUT] && env(ARG[:OUT])) || 1, root: @home)
|
90
|
-
@exception = env_bool
|
99
|
+
@exception = env_bool exception
|
91
100
|
@verbose = env_bool(verbose, verbose.nil? || verbose.is_a?(String) ? @pipe != 0 : verbose, index: true)
|
92
101
|
@warning = @verbose != false
|
93
102
|
@closed = false
|
@@ -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)
|
@@ -265,7 +274,7 @@ module Squared
|
|
265
274
|
data = {} if !command && data[:order].empty?
|
266
275
|
if group
|
267
276
|
label = :group
|
268
|
-
items = as_a
|
277
|
+
items = as_a group
|
269
278
|
else
|
270
279
|
label = :ref
|
271
280
|
items = ref ? as_a(ref) : [:_]
|
@@ -290,9 +299,9 @@ module Squared
|
|
290
299
|
kwargs = kwargs.dup unless @withargs
|
291
300
|
kwargs[:group] = @group
|
292
301
|
end
|
293
|
-
path =
|
302
|
+
path = root + path
|
294
303
|
project = (project || path.basename).to_s
|
295
|
-
name = task_name
|
304
|
+
name = task_name project
|
296
305
|
index = 0
|
297
306
|
while @project[name]
|
298
307
|
index += 1
|
@@ -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
|
@@ -490,12 +499,12 @@ module Squared
|
|
490
499
|
end
|
491
500
|
|
492
501
|
def task_sync(key)
|
493
|
-
key = task_name
|
502
|
+
key = task_name key
|
494
503
|
task_defined?(ret = task_join(key, 'sync')) ? ret : key
|
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?(key)
|
565
|
+
|
555
566
|
task_base?(key) ? obj.has?(key, ref || baseref) : task_extend?(obj, key)
|
556
567
|
end
|
557
568
|
|
@@ -587,7 +598,7 @@ module Squared
|
|
587
598
|
end
|
588
599
|
|
589
600
|
def docker?
|
590
|
-
|
601
|
+
!Dir['/.dockerenv', '/docker-*.{sh,d}'].empty?
|
591
602
|
end
|
592
603
|
|
593
604
|
def powershell?
|
@@ -597,7 +608,7 @@ module Squared
|
|
597
608
|
when 'powershell.exe', 'vscode'
|
598
609
|
true
|
599
610
|
else
|
600
|
-
ENV.fetch('PSModulePath', '').split(';').size > 1
|
611
|
+
ENV.fetch('PSModulePath', '').split(';', 2).size > 1
|
601
612
|
end
|
602
613
|
end
|
603
614
|
|
@@ -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)
|
@@ -670,12 +686,8 @@ module Squared
|
|
670
686
|
end
|
671
687
|
|
672
688
|
def data_get(*args, group: nil, ref: nil, target: nil)
|
673
|
-
if group
|
674
|
-
|
675
|
-
elsif ref.is_a?(Array)
|
676
|
-
ref = ref.each
|
677
|
-
end
|
678
|
-
if ref.instance_of?(Enumerator)
|
689
|
+
target[:group][group.to_sym] if group
|
690
|
+
if ref.is_a?(Enumerable)
|
679
691
|
ref.each do |key|
|
680
692
|
next unless (ret = target[:ref][key])
|
681
693
|
|