squared 0.0.6 → 0.0.7
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 +30 -8
- data/lib/squared/common/base.rb +14 -8
- 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 +1 -9
- data/lib/squared/config.rb +3 -4
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +79 -83
- data/lib/squared/workspace/project/base.rb +100 -57
- data/lib/squared/workspace/project/git.rb +21 -21
- data/lib/squared/workspace/project/node.rb +62 -52
- data/lib/squared/workspace/project/python.rb +9 -16
- data/lib/squared/workspace/project/ruby.rb +211 -63
- data/lib/squared/workspace/project.rb +4 -0
- data/lib/squared/workspace/repo.rb +20 -16
- data/lib/squared/workspace/series.rb +14 -12
- data/lib/squared/workspace.rb +3 -1
- metadata +2 -2
@@ -6,12 +6,13 @@ module Squared
|
|
6
6
|
class Git < Base
|
7
7
|
include Format
|
8
8
|
|
9
|
-
REF = :git
|
10
9
|
OPT_PULL = %w[all tags prune ff-only autostash dry-run].freeze
|
11
10
|
OPT_FETCH = %w[tags prune prune-tags depth=n dry-run].freeze
|
12
|
-
private_constant :
|
11
|
+
private_constant :OPT_PULL, :OPT_FETCH
|
13
12
|
|
14
13
|
class << self
|
14
|
+
include ::Rake::DSL
|
15
|
+
|
15
16
|
def populate(workspace, parallel: [], **)
|
16
17
|
return if workspace.series.pull.empty?
|
17
18
|
|
@@ -27,8 +28,8 @@ module Squared
|
|
27
28
|
else
|
28
29
|
sync.(:pull)
|
29
30
|
end
|
30
|
-
invoke(pull, exception: workspace.exception)
|
31
|
-
invoke(workspace.dev? ? :refresh : :build, exception: workspace.exception)
|
31
|
+
Common::Task.invoke(pull, exception: workspace.exception)
|
32
|
+
Common::Task.invoke(workspace.dev? ? :refresh : :build, exception: workspace.exception)
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
@@ -45,7 +46,7 @@ module Squared
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
@@tasks[
|
49
|
+
@@tasks[ref] = {
|
49
50
|
checkout: %i[branch detach force merge],
|
50
51
|
commit: %i[add amend amend-orig all no-all],
|
51
52
|
diff: %i[head cached branch files],
|
@@ -61,24 +62,22 @@ module Squared
|
|
61
62
|
|
62
63
|
def populate(*)
|
63
64
|
super
|
64
|
-
return unless gitdir.exist?
|
65
|
+
return unless gitdir.exist? && !@exclude.include?(Git.ref)
|
65
66
|
|
66
67
|
namespace name do
|
67
|
-
@@tasks[
|
68
|
+
@@tasks[Git.ref].each do |action, flags|
|
68
69
|
namespace action do
|
69
70
|
flags.each do |flag|
|
70
71
|
case action
|
71
72
|
when :pull
|
72
73
|
desc format_desc(action, flag, OPT_PULL)
|
73
74
|
task flag, [:opts] do |_, args|
|
74
|
-
|
75
|
-
pull(flag, opts: opts)
|
75
|
+
pull(flag, opts: args.to_a)
|
76
76
|
end
|
77
77
|
when :fetch
|
78
78
|
desc format_desc(action, flag, OPT_FETCH)
|
79
79
|
task flag, [:opts] do |_, args|
|
80
|
-
|
81
|
-
fetch(flag, opts: opts)
|
80
|
+
fetch(flag, opts: args.to_a)
|
82
81
|
end
|
83
82
|
when :commit, :restore
|
84
83
|
if flag == :all
|
@@ -89,15 +88,16 @@ module Squared
|
|
89
88
|
else
|
90
89
|
desc format_desc(action, flag, 'pathspec+')
|
91
90
|
task flag, [:pathspec] do |_, args|
|
92
|
-
|
93
|
-
|
91
|
+
files = args.to_a
|
92
|
+
guard_params(action, flag, args: files)
|
93
|
+
__send__(action, flag, files)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
when :stash
|
97
97
|
if flag == :push
|
98
98
|
desc format_desc(action, flag, 'pathspec*')
|
99
99
|
task flag, [:pathspec] do |_, args|
|
100
|
-
stash(flag,
|
100
|
+
stash(flag, args.to_a)
|
101
101
|
end
|
102
102
|
else
|
103
103
|
desc format_desc(action, flag, 'commit?')
|
@@ -120,20 +120,20 @@ module Squared
|
|
120
120
|
when :head
|
121
121
|
desc format_desc(action, flag, 'index?=0,pathspec*')
|
122
122
|
task flag, [:pathspec] do |_, args|
|
123
|
-
files =
|
123
|
+
files = args.to_a
|
124
124
|
index = /^\d+$/.match?(files.first) && !option('index') ? files.shift.to_i : 0
|
125
125
|
diff(flag, files, index: index)
|
126
126
|
end
|
127
127
|
when :cached
|
128
128
|
desc format_desc(action, flag, 'pathspec*')
|
129
129
|
task flag, [:pathspec] do |_, args|
|
130
|
-
diff(flag,
|
130
|
+
diff(flag, args.to_a)
|
131
131
|
end
|
132
132
|
when :branch
|
133
133
|
desc format_desc(action, flag, 'name,pathspec*')
|
134
134
|
task flag, [:name, :pathspec] do |_, args|
|
135
135
|
guard_params(action, flag, args: args, key: :name)
|
136
|
-
diff(flag,
|
136
|
+
diff(flag, args.to_a[1..-1], branch: args.name)
|
137
137
|
end
|
138
138
|
when :files
|
139
139
|
desc format_desc(action, flag, 'path1,path2')
|
@@ -165,7 +165,7 @@ module Squared
|
|
165
165
|
detach = args.detach
|
166
166
|
commit = args.commit
|
167
167
|
end
|
168
|
-
guard_params(
|
168
|
+
guard_params(action, flag, args: { create: create }, key: :create, pat: /^b$/i) if create
|
169
169
|
checkout(flag, branch: args.name, create: create, commit: commit, detach: detach)
|
170
170
|
end
|
171
171
|
when :detach
|
@@ -176,15 +176,14 @@ module Squared
|
|
176
176
|
else
|
177
177
|
desc format_desc(action, flag, 'pathspec*')
|
178
178
|
task flag, [:pathspec] do |_, args|
|
179
|
-
checkout(flag,
|
179
|
+
checkout(flag, args.to_a)
|
180
180
|
end
|
181
181
|
end
|
182
182
|
when :reset
|
183
183
|
if flag == :head
|
184
184
|
desc format_desc(action, flag, 'ref?=HEAD,pathspec+')
|
185
185
|
task flag, [:ref, :pathspec] do |_, args|
|
186
|
-
|
187
|
-
reset(flag, collect_args(args, :pathspec), ref: args.ref)
|
186
|
+
reset(flag, args.to_a[1..-1], ref: args.ref)
|
188
187
|
end
|
189
188
|
else
|
190
189
|
desc format_desc(action, flag, 'ref?=HEAD')
|
@@ -272,6 +271,7 @@ module Squared
|
|
272
271
|
def reset(flag, files = [], ref: nil)
|
273
272
|
cmd = git_session 'reset'
|
274
273
|
if flag == :head
|
274
|
+
guard_params('reset', flag, args: files)
|
275
275
|
append_commit ref
|
276
276
|
append_pathspec files
|
277
277
|
else
|
@@ -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,35 @@ module Squared
|
|
35
32
|
|
36
33
|
attr_reader :package
|
37
34
|
|
38
|
-
def initialize(
|
35
|
+
def initialize(*, **kwargs)
|
39
36
|
super
|
40
|
-
initialize_script(
|
37
|
+
initialize_script(Node.ref, **kwargs)
|
41
38
|
if (opts = env('BUILD', strict: true))
|
42
39
|
raise_error("BUILD_#{@name.upcase}", opts) if @output[0].is_a?(::Array)
|
43
40
|
@output[1] = opts
|
44
41
|
else
|
45
|
-
@output[1] = (@script && @script[:run]) || workspace.script
|
42
|
+
@output[1] = (@script && @script[:run]) || @workspace.script
|
46
43
|
end
|
47
|
-
@dev = dev
|
48
|
-
@prod = prod
|
44
|
+
@dev = kwargs[:dev]
|
45
|
+
@prod = kwargs[:prod]
|
49
46
|
@pm = {}
|
50
47
|
@package = base_path('package.json')
|
51
48
|
end
|
52
49
|
|
53
50
|
def populate(*)
|
54
51
|
super
|
55
|
-
return unless outdated?
|
52
|
+
return unless outdated? && !@exclude.include?(Node.ref)
|
56
53
|
|
57
54
|
namespace name do
|
58
|
-
@@tasks[
|
55
|
+
@@tasks[Node.ref].each do |action, flags|
|
59
56
|
if flags.nil?
|
60
57
|
case action
|
61
58
|
when :run
|
62
59
|
desc format_desc(action, nil, 'command+')
|
63
60
|
task action, [:command] do |_, args|
|
64
|
-
|
65
|
-
guard_params(action, 'command', args:
|
66
|
-
run_script
|
61
|
+
cmd = args.to_a
|
62
|
+
guard_params(action, 'command', args: cmd)
|
63
|
+
run_script cmd
|
67
64
|
end
|
68
65
|
end
|
69
66
|
else
|
@@ -76,9 +73,9 @@ module Squared
|
|
76
73
|
depend(flag, override: true)
|
77
74
|
end
|
78
75
|
when :outdated
|
79
|
-
desc format_desc(action, flag, %w[prune dry-run], req: 'opts?')
|
76
|
+
desc format_desc(action, flag, %w[prune interactive dry-run], req: 'opts?')
|
80
77
|
task flag, [:opts] do |_, args|
|
81
|
-
outdated(flag, opts:
|
78
|
+
outdated(flag, opts: args.to_a)
|
82
79
|
end
|
83
80
|
end
|
84
81
|
end
|
@@ -194,22 +191,20 @@ module Squared
|
|
194
191
|
append_nocolor
|
195
192
|
end
|
196
193
|
append_loglevel
|
197
|
-
run(
|
194
|
+
run(sync: invoked_sync?('depend'))
|
198
195
|
end
|
199
196
|
end
|
200
197
|
|
201
198
|
def outdated(rev = nil, opts: [])
|
202
199
|
require 'json'
|
203
|
-
rev
|
200
|
+
equ = rev || (prod? ? :patch : :minor)
|
204
201
|
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
202
|
log.info cmd
|
203
|
+
if store_pwd || invoked_sync?("outdated#{rev ? ":#{rev}" : ''}")
|
204
|
+
print_item format_banner("#{cmd}#{opts.include?('dry-run') ? ' --dry-run' : ''}", multiple: true)
|
205
|
+
end
|
211
206
|
data = `#{cmd} --json --loglevel=error`
|
212
|
-
|
207
|
+
store_pwd true
|
213
208
|
json = JSON.parse(doc = package.read)
|
214
209
|
dep1 = json['dependencies'] || {}
|
215
210
|
dep2 = json['devDependencies'] || {}
|
@@ -227,7 +222,7 @@ module Squared
|
|
227
222
|
end
|
228
223
|
file = file[1..-1]
|
229
224
|
cur = val['current']
|
230
|
-
want = if
|
225
|
+
want = if equ == :major && val['latest'] =~ SEM_VER
|
231
226
|
[val['latest'], val['wanted']].max { |a, b| a <=> b }
|
232
227
|
else
|
233
228
|
val['wanted']
|
@@ -235,15 +230,14 @@ module Squared
|
|
235
230
|
next unless (cur != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
|
236
231
|
|
237
232
|
a, b = file.split('.')
|
238
|
-
c, d = want.split('.')
|
239
|
-
|
240
|
-
case rev
|
233
|
+
c, d, e = want.split('.')
|
234
|
+
case equ
|
241
235
|
when :major
|
242
236
|
upgrade = a == '0' ? c == '0' : true
|
243
237
|
when :minor
|
244
238
|
upgrade = ch == '^' && (a == '0' ? c == '0' && b == d : a == c)
|
245
239
|
when :patch
|
246
|
-
upgrade = a == c && b == d &&
|
240
|
+
upgrade = a == c && b == d && !e.nil?
|
247
241
|
end
|
248
242
|
if upgrade
|
249
243
|
next if file == want
|
@@ -281,17 +275,23 @@ module Squared
|
|
281
275
|
if !found.empty?
|
282
276
|
col1 = size_col.(found, 0) + 4
|
283
277
|
col2 = size_col.(found, 1) + 4
|
278
|
+
inter = opts.include?('interactive')
|
284
279
|
found.each_with_index do |item, i|
|
285
280
|
a, b, c, d = item
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
281
|
+
prompt = inter && (equ != :major || semmajor(semver(b.scan(SEM_VER)[0]), semver(c.scan(SEM_VER)[0])))
|
282
|
+
if prompt && !confirm_outdated(equ.upcase, a, c)
|
283
|
+
cur = -1
|
284
|
+
else
|
285
|
+
cur = modified
|
286
|
+
doc.sub!(/("#{Regexp.escape(a)}"\s*:\s*)"([~^])#{Regexp.escape(b)}"/) do |capture|
|
287
|
+
if $2 == '~' && equ != :patch
|
288
|
+
cur = -1
|
289
|
+
pending += 1
|
290
|
+
capture
|
291
|
+
else
|
292
|
+
modified += 1
|
293
|
+
"#{$1}\"#{$2 || ''}#{c}\""
|
294
|
+
end
|
295
295
|
end
|
296
296
|
end
|
297
297
|
a = a.ljust(col1)
|
@@ -300,7 +300,7 @@ module Squared
|
|
300
300
|
elsif modified == cur
|
301
301
|
'FAIL'
|
302
302
|
elsif d == 1
|
303
|
-
a = sub_style(a, :
|
303
|
+
a = sub_style(a, styles: theme[:active])
|
304
304
|
sub_style(c, :green, :bold)
|
305
305
|
else
|
306
306
|
sub_style(c, :green, :bold, pat: SEM_VER, index: d)
|
@@ -323,9 +323,15 @@ module Squared
|
|
323
323
|
col3 = size_col.(avail, 2) + 4
|
324
324
|
avail.each_with_index do |item, i|
|
325
325
|
a, b, c, d = item
|
326
|
-
|
327
|
-
|
328
|
-
|
326
|
+
a = a.ljust(col1)
|
327
|
+
b = sub_style(b.ljust(col2), d ? :red : :yellow)
|
328
|
+
c = c.ljust(col3)
|
329
|
+
unless d
|
330
|
+
a = sub_style(a, styles: theme[:active])
|
331
|
+
c = sub_style(c, :green)
|
332
|
+
pending += 1
|
333
|
+
end
|
334
|
+
puts "#{pad_ord.(i, avail)}. #{a + c + b} (#{d ? 'locked' : 'latest'})"
|
329
335
|
end
|
330
336
|
footer.()
|
331
337
|
else
|
@@ -367,10 +373,6 @@ module Squared
|
|
367
373
|
@output[0] != false && (!@output[0].nil? || !@output[1].nil?)
|
368
374
|
end
|
369
375
|
|
370
|
-
def depend?
|
371
|
-
outdated? || !!@depend
|
372
|
-
end
|
373
|
-
|
374
376
|
def copy?
|
375
377
|
!!@copy
|
376
378
|
end
|
@@ -424,15 +426,11 @@ module Squared
|
|
424
426
|
end
|
425
427
|
|
426
428
|
def dev?
|
427
|
-
|
428
|
-
|
429
|
-
workspace.dev?(script: @output[1], pat: @dev, global: !@script || @script[:run].nil?)
|
429
|
+
!Node.prod? && workspace.dev?(script: @output[1], pat: @dev, **runargs)
|
430
430
|
end
|
431
431
|
|
432
432
|
def prod?
|
433
|
-
|
434
|
-
|
435
|
-
workspace.prod?(script: @output[1], pat: @prod, global: !@script || @script[:run].nil?)
|
433
|
+
Node.prod? || workspace.prod?(script: @output[1], pat: @prod, **runargs)
|
436
434
|
end
|
437
435
|
|
438
436
|
protected
|
@@ -467,6 +465,18 @@ module Squared
|
|
467
465
|
end
|
468
466
|
end
|
469
467
|
end
|
468
|
+
|
469
|
+
private
|
470
|
+
|
471
|
+
def confirm_outdated(rev, pkg, ver)
|
472
|
+
m = ver == :major
|
473
|
+
confirm("Upgrade to #{rev}? #{sub_style("#{pkg} #{ver}", styles: theme[:inline])} [#{m ? 'y/N' : 'Y/n'}] ",
|
474
|
+
default: m ? 'N' : 'Y', timeout: 60)
|
475
|
+
end
|
476
|
+
|
477
|
+
def runargs
|
478
|
+
{ ref: Node.ref, group: group, global: !@script || @script[:run].nil? }
|
479
|
+
end
|
470
480
|
end
|
471
481
|
end
|
472
482
|
end
|
@@ -4,13 +4,12 @@ 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
10
|
OPT_UPGRADE = [*OPT_FORCE, 'eager'].freeze
|
12
|
-
OPT_GENERAL = %w{venv isolated no-cache [v]erbose}.freeze
|
13
|
-
private_constant :
|
11
|
+
OPT_GENERAL = %w{venv isolated no-cache-dir [v]erbose}.freeze
|
12
|
+
private_constant :REQUIREMENTS, :OPT_USER, :OPT_FORCE, :OPT_UPGRADE, :OPT_GENERAL
|
14
13
|
|
15
14
|
class << self
|
16
15
|
def populate(*); end
|
@@ -35,23 +34,23 @@ module Squared
|
|
35
34
|
|
36
35
|
attr_reader :requirements
|
37
36
|
|
38
|
-
def initialize(
|
37
|
+
def initialize(*, **kwargs)
|
39
38
|
super
|
40
39
|
@reqindex = REQUIREMENTS.index { |file| base_path(file).exist? } || 0
|
41
40
|
@requirements = base_path(REQUIREMENTS[@reqindex])
|
42
|
-
initialize_build(
|
41
|
+
initialize_build(Python.ref, **kwargs)
|
43
42
|
end
|
44
43
|
|
45
|
-
@@tasks[
|
44
|
+
@@tasks[ref] = {
|
46
45
|
install: %i[user upgrade force]
|
47
46
|
}.freeze
|
48
47
|
|
49
48
|
def populate(*)
|
50
49
|
super
|
51
|
-
return unless outdated?
|
50
|
+
return unless outdated? && !@exclude.include?(Python.ref)
|
52
51
|
|
53
52
|
namespace name do
|
54
|
-
@@tasks[
|
53
|
+
@@tasks[Python.ref].each do |action, flags|
|
55
54
|
namespace action do
|
56
55
|
flags.each do |flag|
|
57
56
|
case action
|
@@ -66,7 +65,7 @@ module Squared
|
|
66
65
|
end
|
67
66
|
desc format_desc(action, flag, list + OPT_GENERAL)
|
68
67
|
task flag do |_, args|
|
69
|
-
depend(flag, opts:
|
68
|
+
depend(flag, opts: args.to_a, override: true)
|
70
69
|
end
|
71
70
|
end
|
72
71
|
end
|
@@ -94,7 +93,7 @@ module Squared
|
|
94
93
|
append_general opts, OPT_FORCE
|
95
94
|
end
|
96
95
|
cmd << (type == 1 ? '-r requirements.txt' : '.')
|
97
|
-
run(
|
96
|
+
run(sync: invoked_sync?('depend'))
|
98
97
|
when 3
|
99
98
|
run_s("#{@bin} setup.py install", sync: invoked_sync?('depend'))
|
100
99
|
end
|
@@ -107,10 +106,6 @@ module Squared
|
|
107
106
|
requirements.exist? ? @reqindex + 1 : 0
|
108
107
|
end
|
109
108
|
|
110
|
-
def depend?
|
111
|
-
outdated? || !!@depend
|
112
|
-
end
|
113
|
-
|
114
109
|
def outdated?
|
115
110
|
install_type > 0
|
116
111
|
end
|
@@ -131,8 +126,6 @@ module Squared
|
|
131
126
|
'--upgrade-strategy=eager'
|
132
127
|
when 'venv'
|
133
128
|
'--require-virtualenv'
|
134
|
-
when 'no-cache'
|
135
|
-
'--no-cache-dir'
|
136
129
|
else
|
137
130
|
(v ? "-#{v[0]}" : "--#{opt}")
|
138
131
|
end
|