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.19.0 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.18.1 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.18.0 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.17.0 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.16.1 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.16.0 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.15.6 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.15.5 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.15.4 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.15.3 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.15.2 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.15.1 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.15.0 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.14.0 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.13.0 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.12.0 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.11.2 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.11.1 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.11.0 lib/shopify_cli/app_type_detector.rb
shopify-cli-2.10.2 lib/shopify_cli/app_type_detector.rb