Module: Script::Loaders::Project
- Defined in:
- lib/project_types/script/loaders/project.rb
Class Method Summary collapse
- .env_file_exists?(directory) ⇒ Boolean
- .handle_error(error, context:) ⇒ Object
- .load(directory:, api_key:, uuid:, api_secret:, context: ShopifyCLI::Context.new) ⇒ Object
Class Method Details
.env_file_exists?(directory) ⇒ Boolean
41 42 43 |
# File 'lib/project_types/script/loaders/project.rb', line 41 def self.env_file_exists?(directory) File.exist?(ShopifyCLI::Resources::EnvFile.path(directory)) end |
.handle_error(error, context:) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/project_types/script/loaders/project.rb', line 26 def self.handle_error(error, context:) if ShopifyCLI::Environment.interactive? properties_hash = { api_key: "SHOPIFY_API_KEY", secret: "SHOPIFY_API_SECRET" } missing_env_variables = error.properties.map { |p| properties_hash[p.name] }.compact.join(", ") = context.("script.error.missing_env_file_variables", missing_env_variables) += context.("script.error.missing_env_file_variables_solution", ShopifyCLI::TOOL_NAME) else properties_hash = { api_key: "--api-key", secret: "--api-secret" } = error.properties.map { |p| properties_hash[p.name] }.compact.join(", ") = context.("script.error.missing_push_options_ci", ) += context.("script.error.missing_push_options_ci_solution", ShopifyCLI::TOOL_NAME) end raise ShopifyCLI::Abort, end |
.load(directory:, api_key:, uuid:, api_secret:, context: ShopifyCLI::Context.new) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/project_types/script/loaders/project.rb', line 6 def self.load(directory:, api_key:, uuid:, api_secret:, context: ShopifyCLI::Context.new) env_overrides = { "SHOPIFY_API_KEY" => api_key, "SHOPIFY_API_SECRET" => api_secret, "UUID" => uuid, }.compact env_file_present = env_file_exists?(directory) env = if env_file_present ShopifyCLI::Resources::EnvFile.read(directory, overrides: env_overrides) else ShopifyCLI::Resources::EnvFile.from_hash(env_overrides) end project = ShopifyCLI::Project.at(directory) project.env = env project rescue SmartProperties::InitializationError, SmartProperties::InvalidValueError => error handle_error(error, context: context) end |