squared 0.0.6 → 0.0.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/README.ruby.md +48 -13
- data/lib/squared/common/base.rb +22 -16
- data/lib/squared/common/class.rb +5 -1
- data/lib/squared/common/format.rb +48 -45
- data/lib/squared/common/shell.rb +3 -3
- data/lib/squared/common/system.rb +35 -3
- data/lib/squared/common/task.rb +3 -11
- data/lib/squared/config.rb +21 -18
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +136 -128
- data/lib/squared/workspace/project/base.rb +131 -72
- data/lib/squared/workspace/project/git.rb +73 -73
- data/lib/squared/workspace/project/node.rb +88 -63
- data/lib/squared/workspace/project/python.rb +48 -33
- data/lib/squared/workspace/project/ruby.rb +196 -64
- data/lib/squared/workspace/project.rb +4 -0
- data/lib/squared/workspace/repo.rb +41 -28
- data/lib/squared/workspace/series.rb +54 -43
- data/lib/squared/workspace.rb +11 -3
- data/squared.gemspec +1 -0
- metadata +16 -2
@@ -8,17 +8,15 @@ module Squared
|
|
8
8
|
module Project
|
9
9
|
class Base
|
10
10
|
include Common
|
11
|
+
include Format
|
11
12
|
include System
|
12
13
|
include Shell
|
13
14
|
include Task
|
14
15
|
include ::Rake::DSL
|
15
16
|
|
16
|
-
SEM_VER =
|
17
|
+
SEM_VER = /(\d+)(?:(\.)(\d+))?(?:(\.)(\d+))?/.freeze
|
17
18
|
|
18
19
|
class << self
|
19
|
-
include Common::Task
|
20
|
-
include ::Rake::DSL
|
21
|
-
|
22
20
|
def populate(*); end
|
23
21
|
|
24
22
|
def tasks
|
@@ -34,24 +32,23 @@ module Squared
|
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
37
|
-
def
|
38
|
-
|
35
|
+
def ref
|
36
|
+
@ref ||= to_s.downcase.to_sym
|
39
37
|
end
|
40
38
|
|
41
|
-
def
|
42
|
-
to_s.
|
39
|
+
def to_s
|
40
|
+
super.to_s.match(/[^:]+$/)[0]
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
44
|
@@print_order = 0
|
47
45
|
@@tasks = {}
|
48
46
|
|
49
|
-
attr_reader :name, :project, :workspace, :group, :path, :
|
50
|
-
attr_accessor :warning
|
47
|
+
attr_reader :name, :project, :workspace, :group, :path, :theme
|
51
48
|
|
52
|
-
def initialize(name, path, workspace, *, group: nil,
|
49
|
+
def initialize(name, path, workspace, *, group: nil, **kwargs)
|
53
50
|
@name = name.to_s
|
54
|
-
@path =
|
51
|
+
@path = path
|
55
52
|
@project = @path.basename.to_s
|
56
53
|
@workspace = workspace
|
57
54
|
@group = group&.to_s
|
@@ -61,40 +58,51 @@ module Squared
|
|
61
58
|
@output = [kwargs[:run], nil]
|
62
59
|
@copy = kwargs[:copy]
|
63
60
|
@clean = kwargs[:clean]
|
64
|
-
@warning = workspace.warning
|
65
61
|
@theme = if !workspace.verbose
|
66
62
|
{}
|
67
|
-
elsif common
|
63
|
+
elsif kwargs.fetch(:common, true)
|
68
64
|
workspace.theme
|
69
65
|
else
|
70
66
|
__get__(:theme)[:project][to_sym] ||= {}
|
71
67
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
68
|
+
@ref = []
|
69
|
+
@exclude = as_a(kwargs[:exclude], :to_sym).freeze
|
70
|
+
initialize_ref(Base.ref)
|
71
|
+
initialize_logger(**kwargs)
|
72
|
+
end
|
73
|
+
|
74
|
+
def initialize_logger(log: nil, **)
|
75
|
+
log = log.is_a?(::Hash) ? log.dup : { file: log }
|
76
|
+
if (file = env('LOG_FILE')).nil? && (auto = env('LOG_AUTO'))
|
77
|
+
file = case auto
|
78
|
+
when 'y', 'year'
|
79
|
+
"#{@name}-#{Date.today.year}.log"
|
80
|
+
when 'm', 'month'
|
81
|
+
"#{@name}-#{Date.today.strftime('%Y-%m')}.log"
|
82
|
+
when 'd', 'day', '1'
|
83
|
+
"#{@name}-#{Date.today}.log"
|
84
|
+
end
|
82
85
|
end
|
83
|
-
if
|
84
|
-
|
85
|
-
|
86
|
+
if file ||= log[:file]
|
87
|
+
file = Date.today.strftime(file)
|
88
|
+
file = (dir = env('LOG_DIR')) ? Pathname.new(dir).join(file) : Pathname.new(file)
|
86
89
|
begin
|
87
|
-
|
90
|
+
file = file.realdirpath
|
88
91
|
rescue StandardError => e
|
89
|
-
|
90
|
-
|
92
|
+
raise if @workspace.exception
|
93
|
+
|
94
|
+
file = nil
|
95
|
+
warn e if @workspace.warning
|
91
96
|
end
|
92
97
|
end
|
93
|
-
|
98
|
+
log[:progname] = @name
|
99
|
+
log[:level] = env('LOG_LEVEL', log[:level] || Logger::INFO, ignore: nil)
|
100
|
+
log.delete(:file)
|
101
|
+
@log = [file, log]
|
94
102
|
end
|
95
103
|
|
96
104
|
def initialize_build(ref, **kwargs)
|
97
|
-
initialize_script(ref)
|
105
|
+
initialize_script(ref, **kwargs)
|
98
106
|
if (val = env('BUILD', strict: true))
|
99
107
|
@output[0] = val
|
100
108
|
elsif @script && @output[0] != false
|
@@ -106,26 +114,35 @@ module Squared
|
|
106
114
|
elsif env('BUILD', suffix: 'DEV')
|
107
115
|
@dev = true
|
108
116
|
elsif @dev.nil?
|
109
|
-
@dev = workspace.dev?
|
117
|
+
@dev = !group.nil? && workspace.dev?(group: group, global: true)
|
110
118
|
end
|
111
119
|
end
|
112
120
|
|
113
|
-
def initialize_script(ref)
|
121
|
+
def initialize_script(ref, **)
|
122
|
+
initialize_ref(ref)
|
114
123
|
return unless (script = workspace.script(group: group, ref: ref))
|
115
124
|
|
116
125
|
@depend = script[:depend] if @depend.nil?
|
117
126
|
@doc = script[:doc] if @doc.nil?
|
118
127
|
@test = script[:test] if @test.nil?
|
119
128
|
@clean = script[:clean] if @clean.nil?
|
129
|
+
@exclude = script[:exclude] if @exclude.empty? && script.key?(:exclude)
|
120
130
|
@script = script
|
121
131
|
end
|
122
132
|
|
133
|
+
def initialize_ref(ref)
|
134
|
+
@ref << ref unless @exclude.include?(ref)
|
135
|
+
end
|
136
|
+
|
123
137
|
def populate(*)
|
138
|
+
valid = ref?(Base.ref)
|
139
|
+
series = workspace.series
|
140
|
+
|
124
141
|
namespace name do
|
125
|
-
|
126
|
-
next unless
|
142
|
+
series.each_key do |key|
|
143
|
+
next unless series.include?(key) ? has?(key) && valid : workspace.task_extend?(self, key)
|
127
144
|
|
128
|
-
desc message(name, key)
|
145
|
+
desc message(*name.split(':'), key)
|
129
146
|
task key do
|
130
147
|
__send__(key)
|
131
148
|
end
|
@@ -154,25 +171,25 @@ module Squared
|
|
154
171
|
cmd = compose(opts)
|
155
172
|
banner = env('REPO_BUILD') == 'verbose'
|
156
173
|
end
|
157
|
-
run(cmd,
|
174
|
+
run(cmd, banner: banner, sync: sync)
|
158
175
|
end
|
159
176
|
|
160
177
|
def refresh(*)
|
161
178
|
build(sync: invoked_sync?('depend'))
|
162
179
|
key = "#{name}:copy"
|
163
180
|
if workspace.task_defined?(key)
|
164
|
-
invoke
|
181
|
+
invoke(key, exception: workspace.exception, warning: workspace.warning)
|
165
182
|
else
|
166
183
|
copy
|
167
184
|
end
|
168
185
|
end
|
169
186
|
|
170
187
|
def depend(*)
|
171
|
-
run(@depend,
|
188
|
+
run(@depend, sync: invoked_sync?('depend')) if @depend
|
172
189
|
end
|
173
190
|
|
174
191
|
def copy(*)
|
175
|
-
run_s(@copy, sync: invoked_sync?('copy'))
|
192
|
+
run_s(@copy, sync: invoked_sync?('copy')) if @copy
|
176
193
|
end
|
177
194
|
|
178
195
|
def doc
|
@@ -212,6 +229,12 @@ module Squared
|
|
212
229
|
end
|
213
230
|
end
|
214
231
|
|
232
|
+
def log
|
233
|
+
return @log unless @log.is_a?(::Array)
|
234
|
+
|
235
|
+
@log = Logger.new(enabled? ? @log[0] : nil, **@log[1])
|
236
|
+
end
|
237
|
+
|
215
238
|
def base_path(*args)
|
216
239
|
path.join(*args)
|
217
240
|
end
|
@@ -236,6 +259,10 @@ module Squared
|
|
236
259
|
respond_to?(m = :"#{method}?") && __send__(m)
|
237
260
|
end
|
238
261
|
|
262
|
+
def ref?(val)
|
263
|
+
@ref.include?(val)
|
264
|
+
end
|
265
|
+
|
239
266
|
def build?
|
240
267
|
!!@output[0]
|
241
268
|
end
|
@@ -245,7 +272,7 @@ module Squared
|
|
245
272
|
end
|
246
273
|
|
247
274
|
def depend?
|
248
|
-
|
275
|
+
@depend != false && (!@depend.nil? || has?('outdated'))
|
249
276
|
end
|
250
277
|
|
251
278
|
def doc?
|
@@ -264,16 +291,27 @@ module Squared
|
|
264
291
|
!!@clean
|
265
292
|
end
|
266
293
|
|
267
|
-
|
294
|
+
def dev?
|
295
|
+
!!@dev
|
296
|
+
end
|
268
297
|
|
269
|
-
|
270
|
-
return if req && !base_path(req).exist?
|
298
|
+
private
|
271
299
|
|
300
|
+
def run(cmd = @session, exception: workspace.exception, banner: true, sync: true, req: nil, **)
|
301
|
+
if req && !base_path(req).exist?
|
302
|
+
log.warn "#{req} (not found)"
|
303
|
+
return
|
304
|
+
end
|
272
305
|
cmd = close_session(cmd)
|
273
306
|
log.info cmd
|
274
|
-
print_item format_banner(cmd, banner: banner) if sync
|
275
307
|
begin
|
276
|
-
|
308
|
+
if cmd =~ /^\S+:(\S+:?)+$/ && workspace.task_defined?(cmd)
|
309
|
+
print_item if sync
|
310
|
+
invoke(cmd, exception: exception, warning: workspace.warning)
|
311
|
+
else
|
312
|
+
print_item format_banner(cmd, banner: banner) if sync
|
313
|
+
shell(cmd, chdir: path, exception: exception)
|
314
|
+
end
|
277
315
|
rescue StandardError => e
|
278
316
|
log.error e
|
279
317
|
raise
|
@@ -281,11 +319,12 @@ module Squared
|
|
281
319
|
end
|
282
320
|
|
283
321
|
def run_s(cmd, **kwargs)
|
284
|
-
run(cmd,
|
322
|
+
run(cmd, banner: verbose?, **kwargs) if cmd.is_a?(::String)
|
285
323
|
end
|
286
324
|
|
287
|
-
def env(key, equals: nil, ignore: ['0'].freeze,
|
288
|
-
|
325
|
+
def env(key, default = nil, equals: nil, ignore: ['0'].freeze, suffix: nil, strict: false)
|
326
|
+
@env ||= name.gsub(/[^\w]+/, '_').upcase
|
327
|
+
a = "#{key}_#{@env}"
|
289
328
|
b = ''
|
290
329
|
if suffix
|
291
330
|
a = [a, suffix].flatten.join('_')
|
@@ -328,7 +367,7 @@ module Squared
|
|
328
367
|
styles = [:bold] + styles
|
329
368
|
end
|
330
369
|
end
|
331
|
-
n = max_width(lines)
|
370
|
+
n = Project.max_width(lines)
|
332
371
|
ch = ' ' * pad
|
333
372
|
index = -1
|
334
373
|
out = lines.map do |val|
|
@@ -344,24 +383,27 @@ module Squared
|
|
344
383
|
out.join("\n")
|
345
384
|
end
|
346
385
|
|
347
|
-
def print_footer(*lines, sub: nil, border: theme[:border])
|
348
|
-
n = max_width(lines)
|
386
|
+
def print_footer(*lines, sub: nil, border: theme[:border], reverse: false)
|
387
|
+
n = Project.max_width(lines)
|
349
388
|
sub = as_a(sub)
|
350
389
|
lines.map! do |val|
|
351
390
|
s = val.ljust(n)
|
352
391
|
sub.each { |h| s = sub_style(s, **h) }
|
353
392
|
s
|
354
393
|
end
|
355
|
-
[sub_style('-' * n, styles: border), *lines]
|
394
|
+
ret = [sub_style('-' * n, styles: border), *lines]
|
395
|
+
ret.reverse! if reverse
|
396
|
+
ret.join("\n")
|
356
397
|
end
|
357
398
|
|
358
|
-
def format_desc(action, flag, opts = nil, req: 'opts*')
|
359
|
-
opts = "#{
|
360
|
-
|
399
|
+
def format_desc(action, flag, opts = nil, req: '', arg: 'opts*')
|
400
|
+
opts = "#{arg}=#{opts.join(',')}" if opts.is_a?(::Array)
|
401
|
+
unless flag
|
361
402
|
flag = action
|
362
403
|
action = ''
|
363
404
|
end
|
364
|
-
|
405
|
+
req = opts ? "#{req}," : "[#{req}]" unless req.to_s.empty?
|
406
|
+
message(*name.split(':'), action, opts ? "#{flag}[#{req}#{opts}]" : flag.to_s + req)
|
365
407
|
end
|
366
408
|
|
367
409
|
def format_banner(cmd, banner: true, multiple: false)
|
@@ -374,8 +416,8 @@ module Squared
|
|
374
416
|
end
|
375
417
|
end
|
376
418
|
|
377
|
-
def empty_status(msg, title, obj)
|
378
|
-
"#{msg}#{!obj || obj == 0 || obj.to_s.empty? ? '' : message(hint: message(title, obj.to_s))}"
|
419
|
+
def empty_status(msg, title, obj, always: false)
|
420
|
+
"#{msg}#{!always && (!obj || obj == 0 || obj.to_s.empty?) ? '' : message(hint: message(title, obj.to_s))}"
|
379
421
|
end
|
380
422
|
|
381
423
|
def append_nocolor
|
@@ -394,10 +436,33 @@ module Squared
|
|
394
436
|
@session = nil
|
395
437
|
raise_error(action, "#{flag}[]", hint: 'empty')
|
396
438
|
end
|
397
|
-
|
439
|
+
end
|
440
|
+
|
441
|
+
def store_pwd(done = nil)
|
442
|
+
if @pwd
|
443
|
+
Dir.chdir(@pwd)
|
444
|
+
@pwd = nil
|
445
|
+
elsif !done && Dir.pwd != path.to_s
|
446
|
+
@pwd = Dir.pwd
|
447
|
+
Dir.chdir(path)
|
448
|
+
@pwd
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
def semver(val)
|
453
|
+
unless val[3]
|
454
|
+
val[3] = '.'
|
455
|
+
val[4] = '0'
|
456
|
+
end
|
457
|
+
unless val[1]
|
458
|
+
val[1] = '.'
|
459
|
+
val[2] = '0'
|
460
|
+
end
|
461
|
+
val
|
462
|
+
end
|
398
463
|
|
399
|
-
|
400
|
-
|
464
|
+
def semmajor(cur, want)
|
465
|
+
cur[0] == '0' && want[0] == '0' ? cur[2] != want[2] : cur[0] != want[0]
|
401
466
|
end
|
402
467
|
|
403
468
|
def verbose?
|
@@ -408,8 +473,8 @@ module Squared
|
|
408
473
|
workspace.pipe
|
409
474
|
end
|
410
475
|
|
411
|
-
def invoked_sync?(action)
|
412
|
-
return true if workspace.series.sync?("#{action}:sync")
|
476
|
+
def invoked_sync?(action, flag = nil)
|
477
|
+
return true if !flag.nil? || workspace.series.sync?("#{action}:sync")
|
413
478
|
|
414
479
|
check = lambda do |val|
|
415
480
|
if invoked?(val)
|
@@ -423,17 +488,11 @@ module Squared
|
|
423
488
|
return ret unless ret.nil?
|
424
489
|
end
|
425
490
|
if (base = workspace.find_base(self))
|
426
|
-
ret = check.("#{action}:#{base.
|
491
|
+
ret = check.("#{action}:#{base.ref}")
|
427
492
|
return ret unless ret.nil?
|
428
493
|
end
|
429
494
|
invoked?("#{name}:#{action}") && (!invoked?(action) || !workspace.task_defined?("#{action}:sync"))
|
430
495
|
end
|
431
|
-
|
432
|
-
private
|
433
|
-
|
434
|
-
def max_width(lines)
|
435
|
-
[lines.max_by(&:size).size, Project.line_width].max
|
436
|
-
end
|
437
496
|
end
|
438
497
|
end
|
439
498
|
end
|