lib/sewing_kit/webpack/compiler.rb in sewing_kit-0.130.0 vs lib/sewing_kit/webpack/compiler.rb in sewing_kit-0.130.1
- old
+ new
@@ -1,8 +1,9 @@
# frozen_string_literal: true
-require 'sewing_kit/webpack/webpack'
+require "sewing_kit/webpack/webpack"
+
module SewingKit
module Webpack
class Compiler
class NodeNotInstalled < StandardError
def initialize
@@ -17,11 +18,11 @@
end
end
def compile
raise NodeNotInstalled unless node_installed?
- raise NodeSewingKitNotRunnable, node_env unless File.exist?('node_modules/.bin/sewing-kit')
+ raise NodeSewingKitNotRunnable, node_env unless File.exist?("node_modules/.bin/sewing-kit")
result = Kernel.system(
environment,
*command,
chdir: Rails.root.to_s,
@@ -38,41 +39,45 @@
private
def command
[
- 'node_modules/.bin/sewing-kit',
- 'build',
- '--mode',
+ "node_modules/.bin/sewing-kit",
+ "build",
+ "--mode",
node_env,
].concat(options).reject(&:empty?)
end
def environment
- environment = {
- 'NODE_ENV' => node_env,
- }
-
- if defined?(ShopifyCloud)
- environment['SK_ASSET_DIR'] = ShopifyCloud::AssetUploader.asset_directory
- end
-
- environment
+ {
+ "NODE_ENV" => node_env,
+ "SK_ASSET_DIR" => asset_dir,
+ }.filter { |_, v| v }
end
def node_env
- ENV['NODE_ENV'] || Rails.env.to_s
+ ENV["NODE_ENV"] || Rails.env.to_s
end
+ def asset_dir
+ directory = SewingKit.configuration.build_options&.dig(:asset_directory)
+
+ return nil if directory == false
+ return ShopifyCloud::AssetUploader.asset_directory if directory.nil? && defined?(ShopifyCloud)
+
+ directory
+ end
+
def options
- build_options = SewingKit.configuration.build_options
+ build_options = SewingKit.configuration.build_options&.except(:asset_directory)
return [] unless build_options
- build_options.map { |key, value| ["--#{key.to_s.tr('_', '-')}", value.to_s] }.flatten
+ build_options.map { |key, value| ["--#{key.to_s.tr("_", "-")}", value.to_s] }.flatten
end
def node_installed?
- Kernel.system('node --version')
+ Kernel.system("node --version")
end
end
end
end