Sha256: 673700ad53ac41789c9180819cf1c58de66350d7b15ddf3b7e021e58453c13b3

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Nextgen
  module Actions::Yarn
    def add_yarn_packages(*packages, dev: false)
      add = dev ? "add -D" : "add"
      yarn_command "#{add} #{packages.map(&:shellescape).join(" ")}"
    end
    alias add_yarn_package add_yarn_packages

    def remove_yarn_packages(*packages, capture: false)
      yarn_command "remove #{packages.map(&:shellescape).join(" ")}", capture:
    end
    alias remove_yarn_package remove_yarn_packages

    def add_package_json_scripts(scripts)
      scripts.each do |name, script|
        cmd = "npm pkg set scripts.#{name.to_s.shellescape}=#{script.shellescape}"
        say_status :run, cmd.truncate(60), :green
        run! cmd, verbose: false
      end
    end
    alias add_package_json_script add_package_json_scripts

    def yarn_command(cmd, capture: false)
      say_status :yarn, cmd, :green
      output = run! "yarn #{cmd}", capture: true, verbose: false
      return output if capture
      return puts(output) unless output.match?(/^success /)

      puts output.lines.grep(/^(warning|success) /).join
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nextgen-0.18.0 lib/nextgen/actions/yarn.rb
nextgen-0.17.1 lib/nextgen/actions/yarn.rb
nextgen-0.17.0 lib/nextgen/actions/yarn.rb
nextgen-0.16.0 lib/nextgen/actions/yarn.rb