Sha256: 988f3eead1fd0c4e975be2bd9a7b205cac67910997533cff6cf35b3dd72b3151

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require "shopify_cli"

module Extension
  module Models
    class DevelopmentServerRequirements
      SUPPORTED_EXTENSION_TYPES = [
        "checkout_ui_extension",
        "checkout_post_purchase",
        "product_subscription",
        "web_pixel_extension",
        "pos_ui_extension",
      ]

      class << self
        def supported?(type)
          if type_supported?(type) && type_enabled?(type)
            return true if binary_installed?
            warn_about_missing_binary
          end

          false
        end

        def beta_enabled?
          ShopifyCLI::Feature.enabled?(:extension_server_beta)
        end

        def type_supported?(type)
          SUPPORTED_EXTENSION_TYPES.include?(type.downcase)
        end

        # Some types are enabled unconditionally; others require beta_enabled
        def type_enabled?(type)
          beta_enabled? || "checkout_ui_extension" == type.downcase
        end

        private

        def binary_installed?
          Models::DevelopmentServer.new.executable_installed?
        end

        def warn_about_missing_binary
          CLI::UI::Frame.open(message("errors.development_server_binary_not_found.title"), color: :yellow) do
            context.puts(message("errors.development_server_binary_not_found.message"))
          end
        end

        def message(key)
          context.message(key)
        end

        def context
          @context ||= ShopifyCLI::Context.new
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shopify-cli-2.18.1 lib/project_types/extension/models/development_server_requirements.rb