Class: Squared::Workspace::Project::Node
- Defined in:
- lib/squared/workspace/project/node.rb
Constant Summary
Constants included from Common
Instance Attribute Summary
Attributes inherited from Base
#dependfile, #exception, #group, #name, #parent, #path, #pipe, #project, #theme, #verbose, #workspace
Class Method Summary collapse
- .aliasargs ⇒ Object
- .bannerargs ⇒ Object
- .batchargs ⇒ Object
- .config?(val) ⇒ Boolean
- .populate ⇒ Object
- .prod? ⇒ Boolean
- .tasks ⇒ Object
Instance Method Summary collapse
- #bump(flag, val = nil) ⇒ Object
- #compose(opts, flags = nil, script: false, args: nil, from: nil) ⇒ Object
- #copy(from: 'build', into: 'node_modules', workspace: false, scope: nil, also: nil, create: nil, link: false, force: false, override: false, **kwargs) ⇒ Object
- #copy? ⇒ Boolean
- #depend(flag = nil, sync: invoked_sync?('depend', flag), packages: [], save: nil, exact: nil) ⇒ Object
- #depend? ⇒ Boolean
- #dependtype(prog) ⇒ Object
- #dev? ⇒ Boolean
-
#initialize(**kwargs) ⇒ Node
constructor
A new instance of Node.
- #outdated(flag = nil, opts = [], sync: invoked_sync?('outdated', flag)) ⇒ Object
- #outdated? ⇒ Boolean
- #pack(opts = []) ⇒ Object
- #package(flag, opts = [], from: nil) ⇒ Object
- #packagename ⇒ Object
- #pnpm? ⇒ Boolean
- #populate ⇒ Object
- #prod? ⇒ Boolean
- #publish(flag = nil, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, dryrun: nil) ⇒ Object
- #ref ⇒ Object
- #refresh? ⇒ Boolean
- #update ⇒ Object
- #update? ⇒ Boolean
- #version ⇒ Object
- #workspaces? ⇒ Boolean
- #yarn? ⇒ Boolean
Methods inherited from Git
#branch, #checkout, #clone, #clone?, #commit, #diff, #enabled?, #fetch, #generate, #logx, #ls_files, #ls_remote, #pull, #rebase, #reset, #restore, #rev_parse, #show, #stash, #status, #tag
Methods inherited from Base
#add, #allref, #as, as_path, #basepath, #build, #build?, #clean, #clean?, #doc, #doc?, #enabled?, #error, #event, #exclude?, #first, #generate, #graph, #graph?, #has?, #initialize_build, #initialize_env, #initialize_events, #initialize_logger, #initialize_ref, #inject, #inspect, #last, #lint, #lint?, #localname, #log, ref, #ref?, #script?, #task_include?, #test, #test?, to_s, #to_s, #to_sym, #variable_set, #with
Methods included from Common::Format
Constructor Details
#initialize(**kwargs) ⇒ Node
Returns a new instance of Node.
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/squared/workspace/project/node.rb', line 93 def initialize(*, **kwargs) super if @pass.include?(Node.ref) initialize_ref(Node.ref) initialize_logger(**kwargs) else initialize_build(Node.ref, prod: prod?, **kwargs) initialize_env(**kwargs) end @pm = {} @dependfile = basepath('package.json') end |
Class Method Details
.aliasargs ⇒ Object
64 65 66 |
# File 'lib/squared/workspace/project/node.rb', line 64 def aliasargs [ref, { refresh: :build }].freeze end |
.bannerargs ⇒ Object
68 69 70 |
# File 'lib/squared/workspace/project/node.rb', line 68 def %i[version dependfile].freeze end |
.batchargs ⇒ Object
60 61 62 |
# File 'lib/squared/workspace/project/node.rb', line 60 def batchargs [ref, { refresh: %i[build copy] }].freeze end |
.config?(val) ⇒ Boolean
76 77 78 79 80 |
# File 'lib/squared/workspace/project/node.rb', line 76 def config?(val) return false unless (val = as_path(val)) val.join('package.json').exist? end |
.populate ⇒ Object
54 |
# File 'lib/squared/workspace/project/node.rb', line 54 def populate(*); end |
.prod? ⇒ Boolean
72 73 74 |
# File 'lib/squared/workspace/project/node.rb', line 72 def prod? ENV['NODE_ENV'] == 'production' end |
.tasks ⇒ Object
56 57 58 |
# File 'lib/squared/workspace/project/node.rb', line 56 def tasks %i[outdated update publish].freeze end |
Instance Method Details
#bump(flag, val = nil) ⇒ Object
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
# File 'lib/squared/workspace/project/node.rb', line 630 def bump(flag, val = nil) return unless (cur = version) if flag == :version return unless val else seg = semscan(cur, fill: false) case flag when :major if seg[0] != '0' || seg[2].nil? seg[0] = seg[0].succ else seg[2] = seg[2].succ end when :minor if seg[0] == '0' seg[4] &&= seg[4].succ else seg[2] = seg[2].succ end when :patch seg[4] &&= seg[4].succ end return if (val = seg.join) == cur end begin doc = dependfile.read if doc.sub!(/"version"\s*:\s*"#{cur}"/, "\"version\": \"#{val}\"") unless dryrun? dependfile.write(doc) log.info "bump version #{cur} to #{val} (#{flag})" on :first, :bump end if verbose major = flag == :major emphasize("version: #{val}", title: name, border: borderstyle, sub: [ headerstyle, { pat: /\A(version:)( )(\S+)(.*)\z/, styles: color(major ? :green : :yellow), index: 3 }, { pat: /\A(version:)(.*)\z/, styles: theme[major ? :major : :active] } ]) elsif stdin? puts val end on :last, :bump unless dryrun? else raise_error('not found', hint: 'version') end rescue StandardError => e log.debug e raise if exception end end |
#compose(opts, flags = nil, script: false, args: nil, from: nil) ⇒ Object
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 |
# File 'lib/squared/workspace/project/node.rb', line 699 def compose(opts, flags = nil, script: false, args: nil, from: nil, **) return unless opts if script ret = session dependbin, 'run' raise_error("#{dependbin} run script: given #{opts}", hint: from) unless append_any(opts) append_any flags if flags append_loglevel append_any(args, delim: true) if args ret else case opts when String opts when Hash append_hash(opts).join(' ') when Enumerable opts.to_a.join(' ') else raise_error("#{project}: given #{opts}", hint: from) end end end |
#copy(from: 'build', into: 'node_modules', workspace: false, scope: nil, also: nil, create: nil, link: false, force: false, override: false, **kwargs) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/squared/workspace/project/node.rb', line 221 def copy(from: 'build', into: 'node_modules', workspace: false, scope: nil, also: nil, create: nil, link: false, force: false, override: false, **kwargs) return if @copy == false if @copy && !override return super if runnable?(@copy) from = @copy[:from] if @copy.key?(:from) into = @copy[:into] if @copy.key?(:into) workspace = @copy[:workspace] if @copy.key?(:workspace) link = @copy[:link] if @copy.key?(:link) force = @copy[:force] if @copy.key?(:link) glob = @copy[:include] exclude = @copy[:exclude] scope = @copy[:scope] also = @copy[:also] create = @copy[:create] else glob = kwargs[:include] exclude = kwargs[:exclude] end items = [] items << @workspace.home if build? && path != @workspace.home && @workspace.home? items += as_a(also) if also return if items.empty? on :first, :copy print_item unless @output[0] || !verbose || task_invoked?(/^copy(?::#{Node.ref}|$)/) items.each do |dir| case dir when Pathname dest = dir when String dest = @workspace.rootpath(dir) when Symbol dest = @workspace.find(name: dir)&.path log.warn ("copy project :#{dir}", hint: 'not found') unless dest when Hash glob = dir[:include] exclude = dir[:exclude] from = dir[:from] if dir.key?(:from) into = dir[:into] if dir.key?(:into) scope = dir[:scope] if dir.key?(:scope) link = dir[:link] if dir.key?(:link) force = dir[:force] if dir.key?(:force) dest = dir[:target] create = dir[:create] workspace = dir[:workspace] dest = items.first unless dest && dest != true when Project::Base dest = dir.path else raise_error("given: #{dir}", hint: 'unknown') end next unless from && dest&.directory? from = basepath(from) glob = as_a(glob || '**/*') target = [] if workspace Dir.glob(from.join('*')).each do |path| next unless (path = Pathname.new(path)).directory? sub = if (proj = @workspace.find(path)) proj.packagename elsif (file = path.join('package.json')).exist? begin doc = JSON.parse(file.read) rescue StandardError => e log.error e raise if exception else doc['name'] end end if sub target << [path, dest.join(into, sub)] else log.debug ("package.json in \"#{path}\"", hint: 'not found') end end else target << [from, dest.join(into, scope || project)] end target.each do |src, to| glob.each { |val| log.info "cp #{from.join(val)} #{to}" } begin copy_dir(src, to, glob, create: create, link: link, force: force, pass: exclude, verbose: verbose) rescue StandardError => e log.error e ret = on(:error, :copy, e) raise if exception && ret != true end end end on :last, :copy end |
#copy? ⇒ Boolean
727 728 729 |
# File 'lib/squared/workspace/project/node.rb', line 727 def copy? super || @copy.is_a?(Hash) end |
#depend(flag = nil, sync: invoked_sync?('depend', flag), packages: [], save: nil, exact: nil) ⇒ Object
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/squared/workspace/project/node.rb', line 319 def depend(flag = nil, *, sync: invoked_sync?('depend', flag), packages: [], save: nil, exact: nil, **) if @depend && !flag super elsif outdated? return update if !flag && env('NODE_UPDATE') if (yarn = dependtype(:yarn)) > 0 cmd = session 'yarn' if flag == :add cmd << 'add' cmd << "--#{save}" unless save == 'prod' cmd << '--exact' if exact else cmd << 'install' cmd << '--ignore-engines' if yarn == 1 && !option('ignore-engines', equals: '0') end elsif pnpm? cmd = session 'pnpm' if flag == :add cmd << 'add' cmd << "--save-#{save}" cmd << '--save-exact' if exact else cmd << 'install' end if (val = option('public-hoist-pattern', ignore: false)) split_escape(val).each { |opt| cmd << shell_option('public-hoist-pattern', opt) } end cmd << '--ignore-workspace' if env('NODE_WORKSPACES', equals: '0') append_nocolor else cmd = session 'npm', 'install' if flag == :add cmd << "--save-#{save}" cmd << '--save-exact' if exact cmd.merge(packages.map { |pkg| shell_escape(pkg) }) end cmd << '--workspaces=false' if env('NODE_WORKSPACES', equals: '0') cmd << '--package-lock=false' if option('package-lock', equals: '0') append_nocolor end append_loglevel run(from: :depend, sync: sync) end end |
#depend? ⇒ Boolean
723 724 725 |
# File 'lib/squared/workspace/project/node.rb', line 723 def depend? @depend != false && (!@depend.nil? || outdated?) end |
#dependtype(prog) ⇒ Object
803 804 805 806 807 808 |
# File 'lib/squared/workspace/project/node.rb', line 803 def dependtype(prog) return @pm[prog] if @pm.key?(prog) meth = :"#{prog}?" respond_to?(meth) && __send__(meth) ? @pm[prog] : 0 end |
#dev? ⇒ Boolean
795 796 797 |
# File 'lib/squared/workspace/project/node.rb', line 795 def dev? super && (!Node.prod? || (@dev == true && !prod?)) end |
#outdated(flag = nil, opts = [], sync: invoked_sync?('outdated', flag)) ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
# File 'lib/squared/workspace/project/node.rb', line 365 def outdated(flag = nil, opts = [], sync: invoked_sync?('outdated', flag)) dryrun = opts.include?('dry-run') if pnpm? && read_packagemanager(version: '7.15', update: true) cmd = session 'pnpm', 'outdated' dryrun ||= dryrun?('pnpm') else cmd = session 'npm', 'outdated' dryrun ||= dryrun?('npm') end unless dryrun log.info cmd.to_s on :first, :outdated end = (cmd.temp(dryrun ? ' --dry-run' : nil)) print_item if sync begin data = pwd_set { `#{cmd.temp('--json', '--loglevel=error')}` } doc = dependfile.read json = JSON.parse(doc) rescue StandardError => e log.error e unless dryrun ret = on(:error, :outdated, e) raise if exception && ret != true end warn (Logger::WARN, e) if warning? return else dep1 = json['dependencies'] || {} dep2 = json['devDependencies'] || {} target = json['name'] end found = [] avail = [] rev = flag || (prod? ? :patch : :minor) inter = opts.include?('interactive') unless data.empty? JSON.parse(data).each_pair do |key, val| val = val.find { |obj| obj['dependent'] == target } if val.is_a?(Array) next unless val && (file = dep1[key] || dep2[key]) && file != '*' latest = val['latest'] ch = file[0] if ch =~ /[~^]/ file = file[1..-1] elsif inter && rev == :major major = true else avail << [key, file, latest, true] next end current = val['current'] || file want = rev == :major && (ver = latest.match(SEM_VER)) && !ver[6] ? latest : val['wanted'] next unless (current != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER)) f = semscan(file) w = semscan(want) a = f[0] b = f[2] c = w[0] d = w[2] case rev when :major upgrade = a == '0' ? c == '0' || c == '1' : true when :minor upgrade = ch == '^' && (a == '0' ? c == '0' && b == d : a == c) when :patch upgrade = a == c && b == d && f[4] != w[4] end if upgrade && !w[5] next if file == want index = if a != c 1 elsif b != d a == '0' ? 1 : 3 else 5 end found << [key, file, want, index, major, f, w] elsif !major avail << [key, file, latest, latest != current] end end end pending = 0 modified = 0 size_col = ->(items, i) { items.map { |a| a[i] }.max_by(&:size).size } pad_ord = lambda do |val, ord| ret = val.succ.to_s ord.size > 9 ? ret.rjust(ord.size.to_s.size) : ret end = lambda do |val, size| next unless verbose msg, hint = if modified == -1 ['Packages were updated', 'more possible'] else ['No packages were updated', 'possible'] end possible = pending + val puts (empty_status(msg, hint, possible == size ? 0 : possible)) end print_item unless sync if !found.empty? col1 = size_col.(found, 0) + 4 col2 = size_col.(found, 1) + 4 found.each_with_index do |item, i| a, b, c, d, e = item f = inter && (rev != :major || e || semmajor?(item[5], item[6])) if f && !confirm_outdated(a, c, d, e) cur = -1 else cur = modified doc.sub!(/("#{Regexp.escape(a)}"\s*:\s*)"([~^])#{e ? '?' : ''}#{Regexp.escape(b)}"/) do |capture| if $2 == '~' && rev != :patch cur = -1 pending += 1 capture else modified += 1 "#{$1}\"#{$2 || (d == 1 && e ? '^' : '')}#{c}\"" end end end a = a.ljust(col1) b = b.ljust(col2) b = sub_style(b, styles: theme[:current]) if theme[:current] c = if cur == -1 'SKIP' elsif modified == cur 'FAIL' elsif d == 1 a = sub_style(a, styles: theme[:major]) sub_style(c, :bold, styles: color(:green)) else sub_style(c, pat: SEM_VER, styles: color(:green), index: d) end puts "#{pad_ord.(i, found)}. #{a + b + c}" end pending = avail.reduce(pending) { |a, b| a + (b[3] ? 0 : 1) } if dryrun || (modified == 0 && pending > 0) .(modified, found.size) elsif modified > 0 modified = -1 .(0, found.size) File.write(dependfile, doc) commit(:add, refs: ['package.json'], pass: true) install if opts.include?('prune') end elsif !avail.empty? col1 = size_col.(avail, 0) + 4 col2 = size_col.(avail, 1) col3 = size_col.(avail, 2) + 4 avail.each_with_index do |item, i| a, b, c, d = item a = a.ljust(col1) b = sub_style(b.ljust(col2), styles: color(d ? :red : :yellow)) c = c.ljust(col3) unless d a = sub_style(a, styles: theme[:active]) c = sub_style(c, styles: color(:green)) pending += 1 end puts "#{pad_ord.(i, avail)}. #{a + c + b} (#{d ? 'locked' : 'latest'})" end .(0, avail.size) else puts 'No updates were found' end on :last, :outdated unless dryrun end |
#outdated? ⇒ Boolean
731 732 733 |
# File 'lib/squared/workspace/project/node.rb', line 731 def outdated? dependfile.exist? end |
#pack(opts = []) ⇒ Object
684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
# File 'lib/squared/workspace/project/node.rb', line 684 def pack(opts = []) return unless version cmd = session dependbin, 'pack' if dependtype(:yarn) > 1 out = option_sanitize(opts, OPT_BERRY[:pack]).first cmd << quote_option('out', Pathname.pwd.join("#{project}-#{version}.tgz")) unless session_arg?('out') else out = option_sanitize(opts, pnpm? ? OPT_PNPM[:pack] : OPT_NPM[:pack] + OPT_NPM[:common]).first cmd << quote_option('pack-destination', Dir.pwd) unless session_arg?('pack-destination') end option_clear out run(from: :pack) end |
#package(flag, opts = [], from: nil) ⇒ Object
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/squared/workspace/project/node.rb', line 576 def package(flag, opts = [], from: nil) if (yarn = dependtype(:yarn)) > 0 cmd = session 'yarn', if flag == :update flag = yarn == 1 ? 'upgrade' : 'up' else flag end out = option_sanitize(opts, if yarn == 1 OPT_PNPM[:install_base] + OPT_YARN.fetch(flag, []) + OPT_YARN[:common] else OPT_BERRY[flag] end).first append_loglevel option_clear out elsif pnpm? cmd = session 'pnpm', flag list = OPT_PNPM[:install_base] + OPT_PNPM.fetch(flag, []) + OPT_PNPM[:common] list += OPT_PNPM[:install_as] unless flag == :dedupe out = option_sanitize(opts, list, no: OPT_PNPM[:"#{flag}_no"]).first append_nocolor append_loglevel option_clear out else cmd = session 'npm', flag list = OPT_NPM[:install_base] + OPT_NPM.fetch(flag, []) + OPT_NPM[:common] list += OPT_NPM[:install_as] unless flag == :dedupe opts, pat = option_sanitize(opts, list, no: OPT_NPM[:install_no]) out = [] err = [] opts.each do |opt| if opt =~ pat case $1 when 'w', 'workspace' cmd << (%r{[\\/]}.match?($2) ? quote_option($1, basepath($2)) : shell_option($1, $2)) end elsif opt.include?('=') err << opt else out << opt end end cmd << '--save=true' if option('save') append_nocolor append_loglevel if flag == :dedupe option_clear out else append_value(out, escape: true) end option_clear err end run(from: from || :"package:#{flag}") end |
#packagename ⇒ Object
814 815 816 |
# File 'lib/squared/workspace/project/node.rb', line 814 def packagename read_packagemanager :name end |
#pnpm? ⇒ Boolean
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 |
# File 'lib/squared/workspace/project/node.rb', line 764 def pnpm? (@pm[:pnpm] ||= if basepath('pnpm-lock.yaml', ascend: dependext).exist? begin require 'yaml' doc = YAML.load_file(basepath('node_modules/.modules.yaml', ascend: dependext)) @pm[:_] = doc['packageManager'] case doc['nodeLinker'] when 'hoisted' 1 when 'pnp' 3 else 4 end rescue StandardError => e log.debug e 4 end else (read_packagemanager || read_install)&.start_with?('pnpm') ? 4 : 0 end) > 0 end |
#populate ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/squared/workspace/project/node.rb', line 110 def populate(*, **) super return unless outdated? && ref?(Node.ref) namespace name do @@tasks[Node.ref].each do |action, flags| next if @pass.include?(action) if flags.nil? case action when 'add' format_desc action, nil, 'save?=prod|dev|optional|peer,name+' task action, [:save] do |_, args| save = param_guard(action, 'save', args: args, key: :save) if save.start_with?('=') exact = true save = save[1..-1] end case save when 'prod', 'dev', 'optional', 'peer' packages = args.extras else save = 'prod' packages = args.to_a end param_guard(action, 'name', args: packages) depend(:add, packages: packages, save: save, exact: exact) end when 'run' next if (list = read_scripts).empty? format_desc action, nil, "command+|#{indexchar}index|#,pattern*" task action, [:command] do |_, args| if args.command == '#' format_list(list, "run[#{indexchar}N]", 'scripts', grep: args.extras, from: dependfile.to_s) else cmd = param_guard(action, 'command', args: args.to_a) cmd.each do |val| if (data = indexitem(val)) n, opts = data if (item = list[n - 1]) val = opts ? "#{item.first} #{opts}" : item.first elsif exception indexerror n, list else next log.warn "run script #{n} of #{list.size} (out of range)" end end run compose(val, script: true) end end end when 'pack' format_desc action, nil, 'opts*' task action do |_, args| pack args.to_a end end else namespace action do flags.each do |flag| case action when 'outdated' format_desc(action, flag, %w[prune interactive dry-run].freeze, arg: 'opts?') task flag do |_, args| outdated flag, args.to_a end when 'package' format_desc(action, flag, 'opts*', after: flag == :dedupe ? nil : 'name*') task flag do |_, args| package flag, args.to_a end when 'bump' if flag == :version format_desc action, flag, 'version' task flag, [:version] do |_, args| version = param_guard(action, flag, args: args, key: :version) bump flag, version end else format_desc action, flag task flag do bump flag end end when 'publish' format_desc(action, flag, 'otp?,dry-run?=true', before: flag == :tag ? 'tag' : nil) task flag do |_, args| if flag == :latest otp, dryrun = args.to_a else args = param_guard(action, flag, args: args.to_a) tag, otp, dryrun = args end check = ->(val) { val == 'dry-run' || val == 'true' } if check.(otp) dryrun = true otp = nil elsif dryrun dryrun = check.(dryrun) end publish(flag, otp: otp, tag: tag, dryrun: dryrun) end end end end end end end end |
#prod? ⇒ Boolean
799 800 801 |
# File 'lib/squared/workspace/project/node.rb', line 799 def prod? @prod != false && (Node.prod? || super) end |
#publish(flag = nil, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, dryrun: nil) ⇒ Object
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/squared/workspace/project/node.rb', line 542 def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, dryrun: nil, **) if !version || read_packagemanager(:private) warn (Logger::WARN, 'invalid task "publish"', subject: name, hint: version ? 'private' : nil) return end cmd = session 'npm', 'publish' otp = option('otp') if otp.nil? tag = option('tag') if tag.nil? dryrun = dryrun?('npm') if dryrun.nil? cmd << basic_option('otp', otp) if otp cmd << shell_option('tag', tag) if tag if dryrun cmd << '--dry-run' else from = :publish log.info cmd.to_s end if sync run(from: from, sync: sync) else on :first, from pwd_set(from: from, dryrun: dryrun) do require 'open3' = (cmd.to_s) Open3.popen2e(cmd.done) do |_, out| write_lines(out, banner: , sub: npmnotice + [ { pat: /^(.+)(Tarball .+)$/, styles: :blue, index: 2 } ]) end end on :last, from end end |
#ref ⇒ Object
106 107 108 |
# File 'lib/squared/workspace/project/node.rb', line 106 def ref Node.ref end |
#refresh? ⇒ Boolean
739 740 741 |
# File 'lib/squared/workspace/project/node.rb', line 739 def refresh? !Node.prod? end |
#update ⇒ Object
538 539 540 |
# File 'lib/squared/workspace/project/node.rb', line 538 def update(*) package('update', from: :update) end |
#update? ⇒ Boolean
735 736 737 |
# File 'lib/squared/workspace/project/node.rb', line 735 def update? outdated? end |
#version ⇒ Object
810 811 812 |
# File 'lib/squared/workspace/project/node.rb', line 810 def version super || (@version = read_packagemanager(:version)) end |
#workspaces? ⇒ Boolean
787 788 789 790 791 792 793 |
# File 'lib/squared/workspace/project/node.rb', line 787 def workspaces? if pnpm? basepath('pnpm-workspace.yaml').exist? else read_packagemanager(:workspaces).is_a?(Array) end end |
#yarn? ⇒ Boolean
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 |
# File 'lib/squared/workspace/project/node.rb', line 743 def yarn? (@pm[:yarn] ||= if basepath('yarn.lock', ascend: dependext).exist? if (rc = basepath('.yarnrc.yml', ascend: dependext)).exist? begin require 'yaml' doc = YAML.load_file(rc) doc.nodeLinker == 'node-modules' ? 2 : 3 rescue StandardError => e log.debug e 3 end else 1 end elsif (ver = read_packagemanager || read_install)&.start_with?('yarn') ver == 'yarn' || ver.include?('@1') ? 1 : 3 else 0 end) > 0 end |