squared 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,8 +4,8 @@ module Squared
4
4
  module Workspace
5
5
  module Project
6
6
  class Git < Base
7
- OPT_PULL = %w[all tags prune ff-only autostash dry-run].freeze
8
- OPT_FETCH = %w[tags prune prune-tags depth=n dry-run].freeze
7
+ OPT_FETCH = %w[all tags prune append atomic unshallow dry-run depth=i deepen=i since=d jobs=i].freeze
8
+ OPT_PULL = %w[ff ff-only edit autostash squash verify <fetch].freeze
9
9
  private_constant :OPT_PULL, :OPT_FETCH
10
10
 
11
11
  class << self
@@ -17,7 +17,7 @@ module Squared
17
17
  namespace(name = ws.task_name('git')) do
18
18
  all = ws.task_join(name, 'all')
19
19
 
20
- desc ws.task_name("#{all}[git?=rebase|stash,depend?]", desc: true)
20
+ desc Common::Format.message(*"#{all}[git?=rebase|stash,depend?]".split(':'))
21
21
  task 'all', [:git, :depend] do |_, args|
22
22
  cmd = case args.git
23
23
  when 'rebase'
@@ -63,7 +63,8 @@ module Squared
63
63
  reset: %i[head soft mixed hard merge keep submodules].freeze,
64
64
  restore: %i[worktree staged overlay].freeze,
65
65
  rev: %i[commit branch].freeze,
66
- show: %i[oneline pretty format].freeze
66
+ show: %i[oneline pretty format].freeze,
67
+ tag: %i[add delete list merged].freeze
67
68
  }.freeze
68
69
 
69
70
  def initialize(*, **)
@@ -85,7 +86,7 @@ module Squared
85
86
  flags.each do |flag|
86
87
  case action
87
88
  when :pull, :fetch
88
- desc format_desc(action, flag, flag == :pull ? OPT_PULL : OPT_FETCH)
89
+ desc format_desc(action, flag, action == :pull ? OPT_PULL : OPT_FETCH)
89
90
  task flag, [:opts] do |_, args|
90
91
  __send__(action, flag, opts: args.to_a)
91
92
  end
@@ -102,6 +103,32 @@ module Squared
102
103
  __send__(action, flag, files)
103
104
  end
104
105
  end
106
+ when :tag
107
+ case flag
108
+ when :list
109
+ desc format_desc(action, flag, 'pattern*')
110
+ task flag, [:pattern] do |_, args|
111
+ tag(flag, args.to_a)
112
+ end
113
+ when :merged
114
+ desc format_desc(action, flag, 'commit,pattern*')
115
+ task flag, [:commit, :pattern] do |_, args|
116
+ commit = guard_params(action, flag, args: args, key: :commit)
117
+ tag(flag, args.to_a.drop(1), commit: commit)
118
+ end
119
+ when :delete
120
+ desc format_desc(action, flag, 'name+')
121
+ task flag, [:name] do |_, args|
122
+ name = guard_params(action, flag, args: args.to_a)
123
+ tag(flag, name)
124
+ end
125
+ else
126
+ desc format_desc(action, flag, 'name,message?,commit?')
127
+ task flag, [:name, :message, :commit] do |_, args|
128
+ name = guard_params(action, flag, args: args, key: :name)
129
+ tag(flag, [name], message: args.message, commit: args.commit)
130
+ end
131
+ end
105
132
  when :stash
106
133
  if flag == :push
107
134
  desc format_desc(action, flag, 'pathspec*')
@@ -130,7 +157,7 @@ module Squared
130
157
  desc format_desc(action, flag, 'index?=0,pathspec*')
131
158
  task flag, [:pathspec] do |_, args|
132
159
  files = args.to_a
133
- diff(flag, files, index: /^\d+$/.match?(files[0]) && !option('index') ? files.shift.to_i : 0)
160
+ diff(flag, files, index: /\A\d+\z/.match?(files[0]) && !option('index') ? files.shift.to_i : 0)
134
161
  end
135
162
  when :cached
136
163
  desc format_desc(action, flag, 'pathspec*')
@@ -139,9 +166,9 @@ module Squared
139
166
  end
140
167
  when :branch
141
168
  desc format_desc(action, flag, 'name,pathspec*')
142
- task flag, [:name, :pathspec] do |_, args|
169
+ task flag, [:name] do |_, args|
143
170
  branch = guard_params(action, flag, args: args, key: :name)
144
- diff(flag, args.to_a[1..-1] || [], branch: branch)
171
+ diff(flag, args.to_a.drop(1), branch: branch)
145
172
  end
146
173
  when :files
147
174
  desc format_desc(action, flag, 'path1,path2')
@@ -173,7 +200,7 @@ module Squared
173
200
  detach = args.detach
174
201
  commit = args.commit
175
202
  end
176
- guard_params(action, flag, args: { create: create }, key: :create, pat: /^b$/i) if create
203
+ guard_params(action, flag, args: { create: create }, key: :create, pat: /\Ab\z/i) if create
177
204
  checkout(flag, branch: branch, create: create, commit: commit, detach: detach)
178
205
  end
179
206
  when :detach
@@ -191,7 +218,7 @@ module Squared
191
218
  if flag == :head
192
219
  desc format_desc(action, flag, 'ref,pathspec+')
193
220
  task flag, [:ref, :pathspec] do |_, args|
194
- files = guard_params(action, flag, args: args.to_a[1..-1] || [])
221
+ files = guard_params(action, flag, args: args.to_a.drop(1))
195
222
  reset(flag, files, ref: args.ref)
196
223
  end
197
224
  else
@@ -202,17 +229,14 @@ module Squared
202
229
  end
203
230
  when :show
204
231
  if flag == :oneline
205
- desc format_desc(action, flag, 'object+')
232
+ desc format_desc(action, flag, 'object*')
206
233
  task flag, [:object] do |_, args|
207
- objs = guard_params(action, flag, args: args.to_a)
208
- show(objs, pretty: 'oneline', abbrev: true)
234
+ show(args.to_a, pretty: 'oneline', abbrev: true)
209
235
  end
210
236
  else
211
- desc format_desc(action, flag, 'format,object+')
237
+ desc format_desc(action, flag, 'format,object*')
212
238
  task flag, [:format, :object] do |_, args|
213
- format = guard_params(action, flag, args: args, key: :format)
214
- objs = guard_params(action, flag, args: args.to_a[1..-1] || [])
215
- show(objs, "#{flag}": format)
239
+ show(args.to_a.drop(1), "#{flag}": args.format)
216
240
  end
217
241
  end
218
242
  end
@@ -237,8 +261,8 @@ module Squared
237
261
  append_pull opts, OPT_PULL, flag
238
262
  sub = if verbose
239
263
  [
240
- { pat: /^(.+)(\|\s+\d+\s+)([^-]*)(-+)(.*)$/, styles: :red, index: 4 },
241
- { pat: /^(.+)(\|\s+\d+\s+)(\++)(-*)(.*)$/, styles: :green, index: 3 }
264
+ { pat: /\A(.+)(\|\s+\d+\s+)([^-]*)(-+)(.*)\z/, styles: :red, index: 4 },
265
+ { pat: /\A(.+)(\|\s+\d+\s+)(\++)(-*)(.*)\z/, styles: :green, index: 3 }
242
266
  ]
243
267
  end
244
268
  source(sync: sync, sub: sub, **threadargs)
@@ -272,16 +296,16 @@ module Squared
272
296
  def status
273
297
  cmd = git_session 'status', option('long') ? '--long' : '--short'
274
298
  if (val = option('ignore-submodules', ignore: false))
275
- cmd << "--ignore-submodules=#{case val
276
- when '0', 'none'
277
- 'none'
278
- when '1', 'untracked'
279
- 'untracked'
280
- when '2', 'dirty'
281
- 'dirty'
282
- else
283
- 'all'
284
- end}"
299
+ cmd << shell_option('ignore-submodules', case val
300
+ when '0', 'none'
301
+ 'none'
302
+ when '1', 'untracked'
303
+ 'untracked'
304
+ when '2', 'dirty'
305
+ 'dirty'
306
+ else
307
+ 'all'
308
+ end, escape: false)
285
309
  end
286
310
  append_pathspec
287
311
  out, banner = source(io: true)
@@ -291,10 +315,10 @@ module Squared
291
315
  end
292
316
  ret = write_lines(out, banner: banner, sub: if verbose
293
317
  [
294
- { pat: /^(.)([A-Z])(.+)$/, styles: :red, index: 2 },
295
- { pat: /^([A-Z])(.+)$/, styles: :green },
296
- { pat: /^(\?\?)(.+)$/, styles: :red },
297
- { pat: /^(## )(.+)(\.{3})(.+)$/,
318
+ { pat: /\A(.)([A-Z])(.+)\z/, styles: :red, index: 2 },
319
+ { pat: /\A([A-Z])(.+)\z/, styles: :green },
320
+ { pat: /\A(\?\?)(.+)\z/, styles: :red },
321
+ { pat: /\A(## )(.+)(\.{3})(.+)\z/,
298
322
  styles: [nil, :green, nil, :red], index: -1 }
299
323
  ]
300
324
  end)
@@ -339,18 +363,39 @@ module Squared
339
363
  cmd << "--#{flag}" << commit
340
364
  else
341
365
  cmd << "--#{flag}"
342
- append_ours
366
+ append_first %w[ours theirs]
343
367
  append_head
344
368
  append_pathspec files
345
369
  end
346
370
  source
347
371
  end
348
372
 
373
+ def tag(flag, refs, message: nil, commit: nil)
374
+ cmd = git_session 'tag'
375
+ case flag
376
+ when :add
377
+ if option('sign')
378
+ cmd << '--sign'
379
+ else
380
+ out = cmd.to_s
381
+ cmd << '--annotate' if %w[-s --sign -u --local-user].none? { |val| out.include?(" #{val}") }
382
+ end
383
+ append_message message
384
+ append_value(refs, escape: false)
385
+ append_head commit
386
+ when :delete, :list, :merged
387
+ cmd << shell_option(flag, commit)
388
+ append_option(%w[contains sort] + (flag == :list ? ['merged'] : []), equals: true) unless flag == :delete
389
+ append_value(refs, escape: false)
390
+ end
391
+ source
392
+ end
393
+
349
394
  def rev(flag, ref: nil, size: nil)
350
395
  git_session 'rev-parse', if flag == :branch
351
396
  '--abbrev-ref'
352
397
  else
353
- (n = size.to_i) > 0 ? "--short=#{[n, 5].max}" : '--verify'
398
+ (n = size.to_i) > 0 ? shell_option('short', [n, 5].max, escape: false) : '--verify'
354
399
  end
355
400
  append_commit ref
356
401
  source
@@ -375,7 +420,7 @@ module Squared
375
420
  def diff(flag, files = [], branch: nil, index: 0)
376
421
  cmd = git_session 'diff'
377
422
  unless flag == :files
378
- if /^#[0-9a-f]{5,40}\#$/.match?(sha = files.first)
423
+ if /\A#\h{5,40}\#\z/.match?(sha = files.first)
379
424
  sha = sha[1..-2]
380
425
  files.shift
381
426
  else
@@ -383,7 +428,7 @@ module Squared
383
428
  end
384
429
  end
385
430
  if (val = option('unified')).to_i > 0
386
- cmd << "--unified=#{val}"
431
+ cmd << shell_option('unified', val, escape: false)
387
432
  end
388
433
  append_nocolor
389
434
  case flag
@@ -422,12 +467,29 @@ module Squared
422
467
  end
423
468
  origin = nil
424
469
  branch = nil
470
+ upstream = false
425
471
  source('git fetch --no-tags --quiet', io: true, banner: false)
426
472
  source('git branch -vv --list', io: true, banner: false).first.each do |val|
427
- next unless (data = %r{^\* [^\[]+(?<= )\[([\w.-/]+?)/([\w.-]+)\] }.match(val))
428
-
429
- origin = data[1]
430
- branch = data[2]
473
+ next unless (data = /\A\*\s(\S+)\s+(\h+)(?:\s\[(.+?)(?=\]\s)\])?\s/.match(val))
474
+
475
+ branch = data[1]
476
+ sha = data[2]
477
+ if !data[3]
478
+ unless (origin = option('repository', prefix: 'git', ignore: false))
479
+ out = source('git log -n1 --format=%h%d', io: true, stdout: true, banner: false).first
480
+ if (data = /\A#{sha} \(HEAD -> #{Regexp.escape(branch)}, (.+?)\)\z/.match(out))
481
+ split_escape(data[1]).each do |val|
482
+ next unless val.end_with?("/#{branch}")
483
+
484
+ origin = val[0..val.size - branch.size - 2]
485
+ break
486
+ end
487
+ end
488
+ end
489
+ upstream = !origin.nil?
490
+ elsif (data = Regexp.new("\\A(.+)/#{Regexp.escape(branch)}\\z").match(data[3]))
491
+ origin = data[1]
492
+ end
431
493
  break
432
494
  end
433
495
  raise_error('commit', 'work tree is not usable') unless origin && branch
@@ -445,6 +507,7 @@ module Squared
445
507
  end
446
508
  a = ['git add --verbose']
447
509
  b = ['git push']
510
+ b << '--set-upstream' if upstream
448
511
  if dry_run?
449
512
  a << '--dry-run'
450
513
  b << '--dry-run'
@@ -460,27 +523,25 @@ module Squared
460
523
 
461
524
  def restore(flag, files)
462
525
  git_session 'restore', "--#{flag}"
463
- append_ours
526
+ append_first %w[ours theirs]
464
527
  append_pathspec(files, expect: true)
465
528
  source(stdout: true)
466
529
  end
467
530
 
468
531
  def show(objs, pretty: nil, format: nil, abbrev: nil)
469
532
  cmd = git_session 'show'
470
- case (flag = pretty&.downcase)
471
- when 'oneline', 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'raw'
472
- cmd << "--pretty=#{flag}"
473
- else
474
- if pretty
475
- cmd << "--pretty=#{shell_escape("tformat:#{pretty}", quote: true)}"
476
- elsif format
477
- cmd << "--format=#{shell_escape(format, quote: true)}"
478
- end
533
+ if (flag = pretty || format)
534
+ cmd << case (val = flag.downcase)
535
+ when 'oneline', 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'raw'
536
+ shell_option('format', val, escape: false)
537
+ else
538
+ shell_option('pretty', flag, escape: false, quote: true)
539
+ end
479
540
  end
480
541
  if (abbrev ||= option('abbrev')) == true
481
542
  cmd << '--abbrev-commit'
482
543
  elsif abbrev.to_i > 0
483
- cmd << "--abbrev=#{abbrev}"
544
+ cmd << shell_option('abbrev', abbrev, escape: false)
484
545
  end
485
546
  append_value objs
486
547
  source(exception: false)
@@ -493,10 +554,10 @@ module Squared
493
554
  cmd = session_done(cmd)
494
555
  log.info cmd
495
556
  banner = format_banner(cmd.gsub(File.join(path, ''), ''), banner: banner)
496
- cmd = cmd.sub(/^git\b/, "git --work-tree #{shell_quote(path)} --git-dir #{shell_quote(gitpath)}")
557
+ cmd = cmd.sub(/\Agit\b/, "git --work-tree=#{shell_quote(path)} --git-dir=#{shell_quote(gitpath)}")
497
558
  begin
498
559
  if io
499
- [IO.popen(cmd), banner]
560
+ [stdout ? `#{cmd}` : IO.popen(cmd), banner]
500
561
  elsif stdin? ? sync : stdout
501
562
  print_item banner
502
563
  ret = `#{cmd}`
@@ -562,8 +623,8 @@ module Squared
562
623
  if size > 0
563
624
  styles = theme.fetch(:banner, []).reject { |s| s.to_s.end_with?('!') }
564
625
  styles << :bold if styles.size <= 1
565
- puts print_footer("#{size} #{size == 1 ? type.sub(/s$/, '') : type}",
566
- sub: { styles: styles, pat: /^(\d+)(.+)$/ })
626
+ puts print_footer("#{size} #{size == 1 ? type.sub(/s\z/, '') : type}",
627
+ sub: { styles: styles, pat: /\A(\d+)(.+)\z/ })
567
628
  else
568
629
  puts empty_status("No #{type} were #{action}", 'grep', grep)
569
630
  end
@@ -571,11 +632,14 @@ module Squared
571
632
 
572
633
  def append_pull(opts, list, flag = nil)
573
634
  append_submodules flag
635
+ list = list.grep_v(/[^a-z\-]/)
574
636
  opts.each do |opt|
575
- if list.include?(opt)
637
+ if list.include?(opt) || opt.match(/^(?:de(?:pth|epen)|jobs)=\d+$/)
576
638
  @session << "--#{opt}"
577
- elsif opt.match(/^depth=(\d+)$/)
578
- @session << "--depth=#{$1}"
639
+ elsif opt.match(/^(?:shallow-)?since=(.+)$/) && (val = Date.parse($1))
640
+ @session << shell_option('shallow-since', val.strftime('%F %T'), escape: false, quote: true)
641
+ elsif opt.end_with?('!') && list.include?(opt = opt[0..-2])
642
+ @session << "--no-#{opt}"
579
643
  end
580
644
  end
581
645
  end
@@ -598,19 +662,13 @@ module Squared
598
662
  end
599
663
 
600
664
  def append_message(val)
601
- @session << "--message \"#{double_quote(val)}\"" if val
665
+ @session << "--message=\"#{double_quote(val)}\"" unless val.to_s.empty?
602
666
  end
603
667
 
604
- def append_head
605
- @session << (option('head') || option('tree-ish'))
606
- end
668
+ def append_head(val = nil)
669
+ return @session << val if val
607
670
 
608
- def append_ours
609
- if option('ours')
610
- @session << '--ours'
611
- elsif option('theirs')
612
- @session << '--theirs'
613
- end
671
+ append_first(%w[head tree-ish object], flag: false, ignore: false)
614
672
  end
615
673
 
616
674
  def append_submodules(flag = nil)
@@ -12,11 +12,11 @@ module Squared
12
12
  end
13
13
 
14
14
  def batchargs
15
- [ref, { refresh: %i[build copy] }]
15
+ [ref, { refresh: %i[build copy] }].freeze
16
16
  end
17
17
 
18
18
  def aliasargs
19
- [ref, { refresh: :build }]
19
+ [ref, { refresh: :build }].freeze
20
20
  end
21
21
 
22
22
  def bannerargs
@@ -38,6 +38,7 @@ module Squared
38
38
  install: %i[force frozen dedupe].freeze,
39
39
  outdated: %i[major minor patch].freeze,
40
40
  bump: %i[major minor patch].freeze,
41
+ update: nil,
41
42
  run: nil
42
43
  }.freeze
43
44
 
@@ -89,6 +90,11 @@ module Squared
89
90
  end
90
91
  end
91
92
  end
93
+ when :update
94
+ desc format_desc(action, nil, 'packages*')
95
+ task action, [:packages] do |_, args|
96
+ update args.to_a
97
+ end
92
98
  end
93
99
  else
94
100
  namespace action do
@@ -97,7 +103,7 @@ module Squared
97
103
  when :install
98
104
  desc format_desc(action, flag)
99
105
  task flag do
100
- depend(flag)
106
+ depend flag
101
107
  end
102
108
  when :outdated
103
109
  desc format_desc(action, flag, %w[prune interactive dry-run].freeze, arg: 'opts?')
@@ -128,7 +134,7 @@ module Squared
128
134
  into = @copy[:into] if @copy.key?(:into)
129
135
  workspace = @copy[:workspace] if @copy.key?(:workspace)
130
136
  glob = @copy[:include]
131
- pass = @copy[:exclude]
137
+ exclude = @copy[:exclude]
132
138
  scope = @copy[:scope]
133
139
  also = @copy[:also]
134
140
  create = @copy[:create]
@@ -138,7 +144,7 @@ module Squared
138
144
  items += as_a(also) if also
139
145
  return if items.empty?
140
146
 
141
- print_item unless @output[0] || !verbose || task_invoked?(/^copy(?::#{Node.ref}|$)/)
147
+ print_item unless @output[0] || !verbose || task_invoked?(/\Acopy(?::#{Node.ref}|$)/)
142
148
  items.each do |dir|
143
149
  case dir
144
150
  when Pathname
@@ -150,7 +156,7 @@ module Squared
150
156
  log.warn message("copy project :#{dir}", hint: 'not found') unless dest
151
157
  when Hash
152
158
  glob = dir[:include]
153
- pass = dir[:exclude]
159
+ exclude = dir[:exclude]
154
160
  from = dir[:from] if dir.key?(:from)
155
161
  into = dir[:into] if dir.key?(:into)
156
162
  scope = dir[:scope] if dir.key?(:scope)
@@ -179,7 +185,7 @@ module Squared
179
185
  doc = JSON.parse(file.read)
180
186
  doc['name']
181
187
  rescue StandardError => e
182
- log.warn e
188
+ log.error e
183
189
  raise if exception
184
190
  end
185
191
  end
@@ -194,7 +200,7 @@ module Squared
194
200
  end
195
201
  target.each do |src, to|
196
202
  glob.each { |val| log.info "cp #{from.join(val)} #{to}" }
197
- copy_d(src, to, glob: glob, create: create, pass: pass, verbose: verbose)
203
+ copy_d(src, to, glob: glob, create: create, pass: exclude, verbose: verbose)
198
204
  end
199
205
  end
200
206
  end
@@ -237,7 +243,7 @@ module Squared
237
243
  end
238
244
  cmd << '--prod' if flag && prod?
239
245
  if (val = option('public-hoist-pattern', ignore: false))
240
- split_escape(val).each { |opt| cmd << "--public-hoist-pattern=#{shell_escape(opt, quote: true)}" }
246
+ split_escape(val).each { |opt| cmd << shell_option('public-hoist-pattern', opt, quote: true) }
241
247
  end
242
248
  cmd << '--ignore-workspace' if env('NODE_WORKSPACES', equals: '0')
243
249
  append_nocolor option('no-color')
@@ -262,7 +268,7 @@ module Squared
262
268
  end
263
269
  end
264
270
 
265
- def outdated(rev = nil, opts: [])
271
+ def outdated(rev = nil, opts: [], sync: invoked_sync?('outdated', rev))
266
272
  dryrun = opts.include?('dry-run')
267
273
  if pnpm? && read_packagemanager(version: '7.15')
268
274
  cmd = 'pnpm outdated'
@@ -273,22 +279,28 @@ module Squared
273
279
  end
274
280
  log.info cmd
275
281
  banner = format_banner("#{cmd}#{dryrun ? ' --dry-run' : ''}")
276
- if invoked_sync?('outdated', rev)
277
- print_item banner
278
- banner = nil
282
+ print_item banner if sync
283
+ begin
284
+ data = pwd_set { `#{cmd} --json --loglevel=error` }
285
+ json = JSON.parse(doc = dependfile.read)
286
+ rescue StandardError => e
287
+ log.error e
288
+ raise if exception
289
+
290
+ warn log_message(Logger::WARN, e) if warning?
291
+ return
292
+ else
293
+ dep1 = json['dependencies'] || {}
294
+ dep2 = json['devDependencies'] || {}
295
+ target = json['name']
279
296
  end
280
- data = nil
281
- pwd_set { data = `#{cmd} --json --loglevel=error` }
282
- json = JSON.parse(doc = dependfile.read)
283
- dep1 = json['dependencies'] || {}
284
- dep2 = json['devDependencies'] || {}
285
297
  found = []
286
298
  avail = []
287
299
  rev ||= (prod? ? :patch : :minor)
288
300
  inter = opts.include?('interactive')
289
301
  unless data.empty?
290
302
  JSON.parse(data).each_pair do |key, val|
291
- val = val.find { |obj| obj['dependent'] == json['name'] } if val.is_a?(Array)
303
+ val = val.find { |obj| obj['dependent'] == target } if val.is_a?(Array)
292
304
  next unless val && (file = dep1[key] || dep2[key]) && file != '*'
293
305
 
294
306
  latest = val['latest']
@@ -301,8 +313,9 @@ module Squared
301
313
  avail << [key, file, latest, true]
302
314
  next
303
315
  end
316
+ current = val['current'] || file
304
317
  want = rev == :major && (ver = latest.match(SEM_VER)) && !ver[6] ? latest : val['wanted']
305
- next unless (val['current'] != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
318
+ next unless (current != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
306
319
 
307
320
  f = semscan(file)
308
321
  w = semscan(want)
@@ -330,7 +343,7 @@ module Squared
330
343
  end
331
344
  found << [key, file, want, index, major, f, w]
332
345
  elsif !major
333
- avail << [key, file, latest, false]
346
+ avail << [key, file, latest, latest != current]
334
347
  end
335
348
  end
336
349
  end
@@ -351,7 +364,7 @@ module Squared
351
364
  end
352
365
  puts print_footer(empty_status(msg, hint, pending + val))
353
366
  end
354
- print_item banner if banner
367
+ print_item banner unless sync
355
368
  if !found.empty?
356
369
  col1 = size_col.(found, 0) + 4
357
370
  col2 = size_col.(found, 1) + 4
@@ -417,7 +430,7 @@ module Squared
417
430
  end
418
431
  end
419
432
 
420
- def bump(flag = nil, sync: invoked_sync?('bump', flag))
433
+ def bump(flag = nil)
421
434
  return unless (ver = version)
422
435
 
423
436
  seg = semscan(ver, fill: false)
@@ -450,8 +463,8 @@ module Squared
450
463
  major = flag == :major
451
464
  emphasize("version: #{out}", title: name, border: borderstyle, sub: [
452
465
  headerstyle,
453
- { pat: /^(version:)( )(\S+)(.*)$/, styles: color(major ? :green : :yellow), index: 3 },
454
- { pat: /^(version:)(.*)$/, styles: theme[major ? :major : :active] }
466
+ { pat: /\A(version:)( )(\S+)(.*)\z/, styles: color(major ? :green : :yellow), index: 3 },
467
+ { pat: /\A(version:)(.*)\z/, styles: theme[major ? :major : :active] }
455
468
  ])
456
469
  elsif stdin?
457
470
  puts out
@@ -461,10 +474,33 @@ module Squared
461
474
  end
462
475
  rescue StandardError => e
463
476
  log.debug e
464
- raise if sync
477
+ raise if exception
465
478
  end
466
479
  end
467
480
 
481
+ def update(pkgs = [])
482
+ if (yarn = dependtype(:yarn)) > 0
483
+ cmd = session 'yarn'
484
+ if yarn > 1
485
+ cmd << 'up'
486
+ else
487
+ cmd << 'upgrade'
488
+ cmd << '--ignore-engines' unless option('ignore-engines', equals: '0')
489
+ end
490
+ elsif pnpm?
491
+ cmd = session 'pnpm', 'update'
492
+ cmd << '--prod' if prod?
493
+ append_nocolor option('no-color')
494
+ else
495
+ cmd = session 'npm', 'update'
496
+ cmd << '--omit=dev' if prod?
497
+ append_nocolor option('no-color')
498
+ end
499
+ append_loglevel
500
+ append_value pkgs
501
+ run
502
+ end
503
+
468
504
  def compose(opts, flags = nil, script: false)
469
505
  return unless opts && script
470
506
 
@@ -615,19 +651,19 @@ module Squared
615
651
  end
616
652
  elsif pnpm?
617
653
  if silent
618
- @session << '--reporter=silent'
654
+ @session << shell_option('reporter', 'silent', escape: false)
619
655
  level ||= 'error'
620
656
  end
621
657
  case level
622
658
  when 'debug', 'info', 'warn', 'error'
623
- @session << "--loglevel=#{level}"
659
+ @session << shell_option('loglevel', level, escape: false)
624
660
  end
625
661
  elsif silent
626
- @session << '--loglevel=silent'
662
+ @session << shell_option('loglevel', 'silent', escape: false)
627
663
  else
628
664
  case level
629
665
  when 'error', 'warn', 'notice', 'http', 'info', 'verbose', 'silly'
630
- @session << "--loglevel=#{level}"
666
+ @session << shell_option('loglevel', level, escape: false)
631
667
  end
632
668
  end
633
669
  end