Sha256: 488121428cd72b119f2c9d2f649a082cf7e7af115584587875cd3a6bc7c5af08

Contents?: true

Size: 1.89 KB

Versions: 36

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

module Script
  module Loaders
    module Project
      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

      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(", ")
          message = context.message("script.error.missing_env_file_variables", missing_env_variables)
          message += context.message("script.error.missing_env_file_variables_solution", ShopifyCLI::TOOL_NAME)
        else
          properties_hash = { api_key: "--api-key", secret: "--api-secret" }
          missing_options = error.properties.map { |p| properties_hash[p.name] }.compact.join(", ")
          message = context.message("script.error.missing_push_options_ci", missing_options)
          message += context.message("script.error.missing_push_options_ci_solution", ShopifyCLI::TOOL_NAME)
        end
        raise ShopifyCLI::Abort, message
      end

      def self.env_file_exists?(directory)
        File.exist?(ShopifyCLI::Resources::EnvFile.path(directory))
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
shopify-cli-2.36.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.35.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.34.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.33.1 lib/project_types/script/loaders/project.rb
shopify-cli-2.33.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.32.1 lib/project_types/script/loaders/project.rb
shopify-cli-2.32.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.31.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.30.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.29.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.28.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.27.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.26.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.25.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.24.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.23.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.22.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.21.0 lib/project_types/script/loaders/project.rb
shopify-cli-2.20.1 lib/project_types/script/loaders/project.rb
shopify-cli-2.20.0 lib/project_types/script/loaders/project.rb