Sha256: 368685daa3e0727fa0b1fd6491ca091cb0af6cc90f0232bf07992600211b784f

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

require "stimulus_reflex/installer"

if !package_json.exist?
  say "⏩ No package.json file found. Skipping."

  return
end

# run yarn install only when packages are waiting to be added or removed
add = package_list.exist? ? package_list.readlines.map(&:chomp) : []
dev = dev_package_list.exist? ? dev_package_list.readlines.map(&:chomp) : []
drop = drop_package_list.exist? ? drop_package_list.readlines.map(&:chomp) : []

json = JSON.parse(package_json.read)

if add.present? || dev.present? || drop.present?

  add.each do |package|
    matches = package.match(/(.+)@(.+)/)
    name, version = matches[1], matches[2]
    json["dependencies"] = {} unless json["dependencies"]
    json["dependencies"][name] = version
  end

  dev.each do |package|
    matches = package.match(/(.+)@(.+)/)
    name, version = matches[1], matches[2]
    json["devDependencies"] = {} unless json["devDependencies"]
    json["devDependencies"][name] = version
  end

  drop.each do |package|
    json["dependencies"].delete(package)
    json["devDependencies"].delete(package)
  end

  package_json.write JSON.pretty_generate(json)

  system "yarn install --silent"
else
  say "⏩ No yarn depdencies to add or remove. Skipping."
end

if bundler == "esbuild" && json["scripts"]["build"] != "node esbuild.config.mjs"
  json["scripts"]["build:default"] = json["scripts"]["build"]
  json["scripts"]["build"] = "node esbuild.config.mjs"
  package_json.write JSON.pretty_generate(json)
  say "✅ Your yarn build script has been updated to use esbuild.config.mjs"
else
  say "⏩ Your yarn build script is already setup. Skipping."
end

complete_step :yarn

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stimulus_reflex-3.5.0.rc2 lib/install/yarn.rb
stimulus_reflex-3.5.0.rc1 lib/install/yarn.rb
stimulus_reflex-3.5.0.pre10 lib/install/yarn.rb