squared 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -4,9 +4,6 @@ module Squared
|
|
4
4
|
module Workspace
|
5
5
|
module Project
|
6
6
|
class Node < Git
|
7
|
-
REF = :node
|
8
|
-
private_constant :REF
|
9
|
-
|
10
7
|
class << self
|
11
8
|
def populate(*); end
|
12
9
|
|
@@ -27,7 +24,7 @@ module Squared
|
|
27
24
|
end
|
28
25
|
end
|
29
26
|
|
30
|
-
@@tasks[
|
27
|
+
@@tasks[ref] = {
|
31
28
|
install: %i[force dedupe frozen],
|
32
29
|
outdated: %i[major minor patch],
|
33
30
|
run: nil
|
@@ -35,35 +32,44 @@ module Squared
|
|
35
32
|
|
36
33
|
attr_reader :package
|
37
34
|
|
38
|
-
def initialize(
|
35
|
+
def initialize(*, script: nil, **kwargs)
|
39
36
|
super
|
40
|
-
initialize_script(
|
41
|
-
|
42
|
-
|
43
|
-
@output[1] = opts
|
44
|
-
else
|
45
|
-
@output[1] = (@script && @script[:run]) || workspace.script
|
46
|
-
end
|
47
|
-
@dev = dev
|
48
|
-
@prod = prod
|
37
|
+
initialize_script(Node.ref, **kwargs)
|
38
|
+
@dev = kwargs[:dev]
|
39
|
+
@prod = kwargs[:prod]
|
49
40
|
@pm = {}
|
50
41
|
@package = base_path('package.json')
|
42
|
+
return if @output[0] == false
|
43
|
+
|
44
|
+
if @output[0].nil?
|
45
|
+
val, ext = @workspace.script(Node.ref, @group)
|
46
|
+
apply_script val
|
47
|
+
unless ext
|
48
|
+
if script
|
49
|
+
apply_script script
|
50
|
+
elsif (val = @script && @script[:run])
|
51
|
+
@output[0] = val
|
52
|
+
@output[1] = nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@output[@output[0] || val.include?(' ') ? 0 : 1] = val if (val = env('BUILD', strict: true))
|
51
57
|
end
|
52
58
|
|
53
59
|
def populate(*)
|
54
60
|
super
|
55
|
-
return unless outdated?
|
61
|
+
return unless outdated? && ref?(Node.ref)
|
56
62
|
|
57
63
|
namespace name do
|
58
|
-
@@tasks[
|
64
|
+
@@tasks[Node.ref].each do |action, flags|
|
59
65
|
if flags.nil?
|
60
66
|
case action
|
61
67
|
when :run
|
62
68
|
desc format_desc(action, nil, 'command+')
|
63
69
|
task action, [:command] do |_, args|
|
64
|
-
|
65
|
-
guard_params(action, 'command', args:
|
66
|
-
run_script
|
70
|
+
cmd = args.to_a
|
71
|
+
guard_params(action, 'command', args: cmd)
|
72
|
+
run_script cmd
|
67
73
|
end
|
68
74
|
end
|
69
75
|
else
|
@@ -73,12 +79,12 @@ module Squared
|
|
73
79
|
when :install
|
74
80
|
desc format_desc(action, flag)
|
75
81
|
task flag do
|
76
|
-
depend(flag
|
82
|
+
depend(flag)
|
77
83
|
end
|
78
84
|
when :outdated
|
79
|
-
desc format_desc(action, flag, %w[prune dry-run],
|
85
|
+
desc format_desc(action, flag, %w[prune interactive dry-run], arg: 'opts?')
|
80
86
|
task flag, [:opts] do |_, args|
|
81
|
-
outdated(flag, opts:
|
87
|
+
outdated(flag, opts: args.to_a)
|
82
88
|
end
|
83
89
|
end
|
84
90
|
end
|
@@ -98,7 +104,7 @@ module Squared
|
|
98
104
|
into = @copy[:into] if @copy.key?(:into)
|
99
105
|
also = @copy[:also] if @copy.key?(:also)
|
100
106
|
end
|
101
|
-
items = [
|
107
|
+
items = [name == workspace.main ? nil : workspace.home].concat(as_a(also))
|
102
108
|
items.each_with_index do |dir, i|
|
103
109
|
if i == 0
|
104
110
|
next unless dev? & !doc?
|
@@ -136,8 +142,8 @@ module Squared
|
|
136
142
|
end
|
137
143
|
end
|
138
144
|
|
139
|
-
def depend(flag = nil
|
140
|
-
if @depend && !
|
145
|
+
def depend(flag = nil)
|
146
|
+
if @depend && !flag
|
141
147
|
super
|
142
148
|
elsif outdated?
|
143
149
|
frozen = flag == :frozen
|
@@ -194,22 +200,20 @@ module Squared
|
|
194
200
|
append_nocolor
|
195
201
|
end
|
196
202
|
append_loglevel
|
197
|
-
run(
|
203
|
+
run(sync: invoked_sync?('depend', flag))
|
198
204
|
end
|
199
205
|
end
|
200
206
|
|
201
207
|
def outdated(rev = nil, opts: [])
|
202
208
|
require 'json'
|
203
|
-
rev
|
209
|
+
equ = rev || (prod? ? :patch : :minor)
|
204
210
|
cmd = pnpm? ? 'pnpm outdated' : 'npm outdated'
|
205
|
-
if invoked_sync?('outdated')
|
206
|
-
print_item format_banner(message("#{cmd}#{opts.include?('dry-run') ? ' --dry-run' : ''}"), multiple: true)
|
207
|
-
end
|
208
|
-
pwd = Dir.pwd
|
209
|
-
Dir.chdir(path)
|
210
211
|
log.info cmd
|
212
|
+
if store_pwd || invoked_sync?("outdated#{rev && ":#{rev}"}")
|
213
|
+
print_item format_banner("#{cmd}#{opts.include?('dry-run') ? ' --dry-run' : ''}", multiple: true)
|
214
|
+
end
|
211
215
|
data = `#{cmd} --json --loglevel=error`
|
212
|
-
|
216
|
+
store_pwd true
|
213
217
|
json = JSON.parse(doc = package.read)
|
214
218
|
dep1 = json['dependencies'] || {}
|
215
219
|
dep2 = json['devDependencies'] || {}
|
@@ -227,7 +231,7 @@ module Squared
|
|
227
231
|
end
|
228
232
|
file = file[1..-1]
|
229
233
|
cur = val['current']
|
230
|
-
want = if
|
234
|
+
want = if equ == :major && val['latest'] =~ SEM_VER
|
231
235
|
[val['latest'], val['wanted']].max { |a, b| a <=> b }
|
232
236
|
else
|
233
237
|
val['wanted']
|
@@ -235,15 +239,14 @@ module Squared
|
|
235
239
|
next unless (cur != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
|
236
240
|
|
237
241
|
a, b = file.split('.')
|
238
|
-
c, d = want.split('.')
|
239
|
-
|
240
|
-
case rev
|
242
|
+
c, d, e = want.split('.')
|
243
|
+
case equ
|
241
244
|
when :major
|
242
245
|
upgrade = a == '0' ? c == '0' : true
|
243
246
|
when :minor
|
244
247
|
upgrade = ch == '^' && (a == '0' ? c == '0' && b == d : a == c)
|
245
248
|
when :patch
|
246
|
-
upgrade = a == c && b == d &&
|
249
|
+
upgrade = a == c && b == d && !e.nil?
|
247
250
|
end
|
248
251
|
if upgrade
|
249
252
|
next if file == want
|
@@ -281,17 +284,23 @@ module Squared
|
|
281
284
|
if !found.empty?
|
282
285
|
col1 = size_col.(found, 0) + 4
|
283
286
|
col2 = size_col.(found, 1) + 4
|
287
|
+
inter = opts.include?('interactive')
|
284
288
|
found.each_with_index do |item, i|
|
285
289
|
a, b, c, d = item
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
290
|
+
prompt = inter && (equ != :major || semmajor(semver(b.scan(SEM_VER)[0]), semver(c.scan(SEM_VER)[0])))
|
291
|
+
if prompt && !confirm_outdated(equ.upcase, a, c)
|
292
|
+
cur = -1
|
293
|
+
else
|
294
|
+
cur = modified
|
295
|
+
doc.sub!(/("#{Regexp.escape(a)}"\s*:\s*)"([~^])#{Regexp.escape(b)}"/) do |capture|
|
296
|
+
if $2 == '~' && equ != :patch
|
297
|
+
cur = -1
|
298
|
+
pending += 1
|
299
|
+
capture
|
300
|
+
else
|
301
|
+
modified += 1
|
302
|
+
"#{$1}\"#{$2 || ''}#{c}\""
|
303
|
+
end
|
295
304
|
end
|
296
305
|
end
|
297
306
|
a = a.ljust(col1)
|
@@ -300,10 +309,10 @@ module Squared
|
|
300
309
|
elsif modified == cur
|
301
310
|
'FAIL'
|
302
311
|
elsif d == 1
|
303
|
-
a = sub_style(a, :
|
312
|
+
a = sub_style(a, styles: theme[:major])
|
304
313
|
sub_style(c, :green, :bold)
|
305
314
|
else
|
306
|
-
sub_style(c, :green,
|
315
|
+
sub_style(c, :green, pat: SEM_VER, index: d)
|
307
316
|
end
|
308
317
|
puts "#{pad_ord.(i, found)}. #{a}#{b.ljust(col2)}#{c}"
|
309
318
|
end
|
@@ -323,9 +332,15 @@ module Squared
|
|
323
332
|
col3 = size_col.(avail, 2) + 4
|
324
333
|
avail.each_with_index do |item, i|
|
325
334
|
a, b, c, d = item
|
326
|
-
|
327
|
-
|
328
|
-
|
335
|
+
a = a.ljust(col1)
|
336
|
+
b = sub_style(b.ljust(col2), d ? :red : :yellow)
|
337
|
+
c = c.ljust(col3)
|
338
|
+
unless d
|
339
|
+
a = sub_style(a, styles: theme[:active])
|
340
|
+
c = sub_style(c, :green)
|
341
|
+
pending += 1
|
342
|
+
end
|
343
|
+
puts "#{pad_ord.(i, avail)}. #{a + c + b} (#{d ? 'locked' : 'latest'})"
|
329
344
|
end
|
330
345
|
footer.()
|
331
346
|
else
|
@@ -367,10 +382,6 @@ module Squared
|
|
367
382
|
@output[0] != false && (!@output[0].nil? || !@output[1].nil?)
|
368
383
|
end
|
369
384
|
|
370
|
-
def depend?
|
371
|
-
outdated? || !!@depend
|
372
|
-
end
|
373
|
-
|
374
385
|
def copy?
|
375
386
|
!!@copy
|
376
387
|
end
|
@@ -424,18 +435,14 @@ module Squared
|
|
424
435
|
end
|
425
436
|
|
426
437
|
def dev?
|
427
|
-
|
428
|
-
|
429
|
-
workspace.dev?(script: @output[1], pat: @dev, global: !@script || @script[:run].nil?)
|
438
|
+
!Node.prod? && workspace.dev?(script: @output[1], pat: @dev, **runargs)
|
430
439
|
end
|
431
440
|
|
432
441
|
def prod?
|
433
|
-
|
434
|
-
|
435
|
-
workspace.prod?(script: @output[1], pat: @prod, global: !@script || @script[:run].nil?)
|
442
|
+
Node.prod? || workspace.prod?(script: @output[1], pat: @prod, **runargs)
|
436
443
|
end
|
437
444
|
|
438
|
-
|
445
|
+
private
|
439
446
|
|
440
447
|
def append_loglevel(cmd = @session)
|
441
448
|
return unless (level = env('NODE_LOGLEVEL'))
|
@@ -467,6 +474,24 @@ module Squared
|
|
467
474
|
end
|
468
475
|
end
|
469
476
|
end
|
477
|
+
|
478
|
+
def confirm_outdated(rev, pkg, ver)
|
479
|
+
m = ver == :major
|
480
|
+
confirm("Upgrade to #{rev}? #{sub_style("#{pkg} #{ver}", styles: theme[:inline])} [#{m ? 'y/N' : 'Y/n'}] ",
|
481
|
+
default: m ? 'N' : 'Y', timeout: 60)
|
482
|
+
end
|
483
|
+
|
484
|
+
def apply_script(val)
|
485
|
+
@output[1] = if val.is_a?(::Array)
|
486
|
+
val[Node.prod? ? 1 : 0]
|
487
|
+
else
|
488
|
+
val
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
def runargs
|
493
|
+
{ ref: Node.ref, group: group, global: @output[0].nil? && !(@script && @script[:run]) }
|
494
|
+
end
|
470
495
|
end
|
471
496
|
end
|
472
497
|
end
|
@@ -4,13 +4,11 @@ module Squared
|
|
4
4
|
module Workspace
|
5
5
|
module Project
|
6
6
|
class Python < Git
|
7
|
-
REF = :python
|
8
7
|
REQUIREMENTS = %w[requirements.txt pyproject.toml setup.py].freeze
|
9
8
|
OPT_USER = %w[pre dry-run].freeze
|
10
9
|
OPT_FORCE = [*OPT_USER, 'user'].freeze
|
11
|
-
|
12
|
-
|
13
|
-
private_constant :REF, :REQUIREMENTS, :OPT_USER, :OPT_FORCE, :OPT_UPGRADE, :OPT_GENERAL
|
10
|
+
OPT_GENERAL = %w{venv isolated no-cache-dir [v]erbose}.freeze
|
11
|
+
private_constant :REQUIREMENTS, :OPT_USER, :OPT_FORCE, :OPT_GENERAL
|
14
12
|
|
15
13
|
class << self
|
16
14
|
def populate(*); end
|
@@ -35,38 +33,48 @@ module Squared
|
|
35
33
|
|
36
34
|
attr_reader :requirements
|
37
35
|
|
38
|
-
def initialize(
|
36
|
+
def initialize(*, **kwargs)
|
39
37
|
super
|
40
38
|
@reqindex = REQUIREMENTS.index { |file| base_path(file).exist? } || 0
|
41
39
|
@requirements = base_path(REQUIREMENTS[@reqindex])
|
42
|
-
initialize_build(
|
40
|
+
initialize_build(Python.ref, **kwargs)
|
43
41
|
end
|
44
42
|
|
45
|
-
@@tasks[
|
46
|
-
install: %i[user upgrade force]
|
43
|
+
@@tasks[ref] = {
|
44
|
+
install: %i[user target upgrade force]
|
47
45
|
}.freeze
|
48
46
|
|
49
47
|
def populate(*)
|
50
48
|
super
|
51
|
-
return unless outdated?
|
49
|
+
return unless outdated? && ref?(Python.ref)
|
52
50
|
|
53
51
|
namespace name do
|
54
|
-
@@tasks[
|
52
|
+
@@tasks[Python.ref].each do |action, flags|
|
55
53
|
namespace action do
|
56
54
|
flags.each do |flag|
|
57
55
|
case action
|
58
56
|
when :install
|
59
57
|
list = case flag
|
58
|
+
when :target
|
59
|
+
req = 'dir'
|
60
|
+
OPT_USER + %w[upgrade eager]
|
60
61
|
when :upgrade
|
61
|
-
|
62
|
+
OPT_FORCE + ['eager']
|
62
63
|
when :force
|
63
64
|
OPT_FORCE
|
64
65
|
else
|
65
66
|
OPT_USER
|
66
67
|
end
|
67
|
-
desc format_desc(action, flag, list + OPT_GENERAL)
|
68
|
-
|
69
|
-
|
68
|
+
desc format_desc(action, flag, list + OPT_GENERAL, req: req)
|
69
|
+
if flag == :target
|
70
|
+
task flag, [:dir, :opts] do |_, args|
|
71
|
+
guard_params(action, flag, args: args, key: :dir)
|
72
|
+
depend(flag, dir: args.dir, opts: args.to_a)
|
73
|
+
end
|
74
|
+
else
|
75
|
+
task flag do |_, args|
|
76
|
+
depend(flag, opts: args.to_a)
|
77
|
+
end
|
70
78
|
end
|
71
79
|
end
|
72
80
|
end
|
@@ -75,42 +83,47 @@ module Squared
|
|
75
83
|
end
|
76
84
|
end
|
77
85
|
|
78
|
-
def depend(flag = nil,
|
79
|
-
if @depend && !
|
86
|
+
def depend(flag = nil, dir: nil, opts: [])
|
87
|
+
if @depend && !flag
|
80
88
|
super
|
81
89
|
elsif outdated?
|
90
|
+
sync = invoked_sync?('depend', flag)
|
82
91
|
case (type = install_type)
|
83
92
|
when 1, 2
|
84
93
|
cmd = pip_session 'install'
|
85
94
|
case flag
|
86
95
|
when :user
|
87
96
|
cmd << '--user'
|
88
|
-
|
97
|
+
append_pip opts, OPT_USER
|
98
|
+
when :target
|
99
|
+
cmd << "--target=#{shell_escape(base_path(dir).to_s, quote: true)}"
|
100
|
+
append_pip opts, OPT_USER + ['upgrade']
|
101
|
+
append_eager opts
|
89
102
|
when :upgrade
|
90
103
|
cmd << '--upgrade'
|
91
|
-
|
104
|
+
append_pip opts, OPT_FORCE
|
105
|
+
append_eager opts
|
92
106
|
when :force
|
93
107
|
cmd << '--force-reinstall'
|
94
|
-
|
108
|
+
append_pip opts, OPT_FORCE
|
95
109
|
end
|
96
110
|
cmd << (type == 1 ? '-r requirements.txt' : '.')
|
97
|
-
run(
|
111
|
+
run(sync: sync)
|
98
112
|
when 3
|
99
|
-
run_s("#{@bin} setup.py install", sync:
|
113
|
+
run_s("#{@bin} setup.py install", sync: sync)
|
100
114
|
end
|
101
115
|
end
|
102
116
|
end
|
103
117
|
|
104
|
-
def outdated(*)
|
118
|
+
def outdated(*)
|
119
|
+
pip_session 'list', '--outdated'
|
120
|
+
run
|
121
|
+
end
|
105
122
|
|
106
123
|
def install_type(*)
|
107
124
|
requirements.exist? ? @reqindex + 1 : 0
|
108
125
|
end
|
109
126
|
|
110
|
-
def depend?
|
111
|
-
outdated? || !!@depend
|
112
|
-
end
|
113
|
-
|
114
127
|
def outdated?
|
115
128
|
install_type > 0
|
116
129
|
end
|
@@ -121,18 +134,13 @@ module Squared
|
|
121
134
|
session('pip', *cmd)
|
122
135
|
end
|
123
136
|
|
124
|
-
def
|
125
|
-
list += OPT_GENERAL
|
137
|
+
def append_pip(opts, list = [])
|
126
138
|
opts.each do |opt|
|
127
|
-
next unless (v = opt.match(/^v+$/))
|
139
|
+
next unless list.include?(opt) || OPT_GENERAL.include?(opt) || (v = opt.match(/^v+$/))
|
128
140
|
|
129
141
|
@session << case opt
|
130
|
-
when 'eager'
|
131
|
-
'--upgrade-strategy=eager'
|
132
142
|
when 'venv'
|
133
143
|
'--require-virtualenv'
|
134
|
-
when 'no-cache'
|
135
|
-
'--no-cache-dir'
|
136
144
|
else
|
137
145
|
(v ? "-#{v[0]}" : "--#{opt}")
|
138
146
|
end
|
@@ -142,8 +150,15 @@ module Squared
|
|
142
150
|
if (val = env('PIP_PROXY'))
|
143
151
|
@session << "--proxy=#{shell_escape(val, quote: true)}"
|
144
152
|
end
|
153
|
+
if (val = env('PIP_LOG'))
|
154
|
+
@session << "--log=#{shell_escape(base_path(val).to_s, quote: true)}"
|
155
|
+
end
|
145
156
|
append_nocolor
|
146
157
|
end
|
158
|
+
|
159
|
+
def append_eager(opts)
|
160
|
+
@session << '--upgrade-strategy=eager' if opts.include?('eager')
|
161
|
+
end
|
147
162
|
end
|
148
163
|
end
|
149
164
|
end
|