Module: Extension::Loaders::Project
- Defined in:
- lib/project_types/extension/loaders/project.rb
Class Method Summary collapse
- .env_file_exists?(directory) ⇒ Boolean
- .handle_error(error, context:) ⇒ Object
- .load(context:, directory:, api_key:, registration_id:, api_secret:, env: {}) ⇒ Object
Class Method Details
.env_file_exists?(directory) ⇒ Boolean
45 46 47 |
# File 'lib/project_types/extension/loaders/project.rb', line 45 def self.env_file_exists?(directory) File.exist?(ShopifyCLI::Resources::EnvFile.path(directory)) end |
.handle_error(error, context:) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/project_types/extension/loaders/project.rb', line 29 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.("errors.missing_env_file_variables", missing_env_variables) += context.("errors.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.("errors.missing_push_options_ci", ) += context.("errors.missing_push_options_ci_solution", ShopifyCLI::TOOL_NAME) end raise ShopifyCLI::Abort, end |
.load(context:, directory:, api_key:, registration_id:, api_secret:, env: {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/project_types/extension/loaders/project.rb', line 6 def self.load(context:, directory:, api_key:, registration_id:, api_secret:, env: {}) env_overrides = { "SHOPIFY_API_KEY" => api_key, "SHOPIFY_API_SECRET" => api_secret, "EXTENSION_ID" => registration_id, }.compact.merge(env) 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 # This is a somewhat uncomfortable hack we use because `Project::at` is # a global cache and we can't rely on this class loading the project # first. Long-term we should move away from that global cache. project = ExtensionProject.at(directory) project.env = env project rescue SmartProperties::InitializationError, SmartProperties::MissingValueError => error handle_error(error, context: context) end |