Sha256: d8478a5b44be266b692517a8d0eb03c224f8bcfd43cf71c464cfdc653dc17a54

Contents?: true

Size: 1.21 KB

Versions: 49

Compression:

Stored size: 1.21 KB

Contents

require "json"

module ShopifyCLI
  class AppTypeDetector
    Error = Class.new(StandardError)
    MissingShopifyCLIYamlError = Class.new(Error)
    TypeNotFoundError = Class.new(Error)
    class InvalidTypeError < Error
      attr_reader :project_type
      def initialize(message, project_type:)
        @project_type = project_type
        super(message)
      end
    end

    def self.detect(project_directory:)
      require "yaml" # takes 20ms, so deferred as late as possible.

      shopify_cli_yml_path = File.join(project_directory, Constants::Files::SHOPIFY_CLI_YML)
      unless File.exist?(shopify_cli_yml_path)
        raise MissingShopifyCLIYamlError,
          "#{Constants::Files::SHOPIFY_CLI_YML} was not found in directory #{project_directory}"
      end
      shopify_cli = YAML.load_file(shopify_cli_yml_path)
      case shopify_cli["project_type"]&.to_sym
      when :node, :rails, :php
        shopify_cli["project_type"].to_sym
      when nil
        raise TypeNotFoundError, "Couldn't detect the project type in directory: #{project_directory}"
      else
        raise InvalidTypeError.new("The project found '' is not supported",
          project_type: shopify_cli["project_type"])
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

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