Class: ShopifyCLI::AppTypeDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/app_type_detector.rb

Defined Under Namespace

Classes: InvalidTypeError

Constant Summary collapse

Error =
Class.new(StandardError)
MissingShopifyCLIYamlError =
Class.new(Error)
TypeNotFoundError =
Class.new(Error)

Class Method Summary collapse

Class Method Details

.detect(project_directory:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/shopify_cli/app_type_detector.rb', line 16

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