Sha256: c44d9964b684720de665d28e766becf11227a89322eaea461f42e9a59ea35ec9

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module Extension
  module Forms
    module Questions
      class AskTemplate
        include ShopifyCLI::MethodObject

        TEMPLATE_REQUIRED_TYPES = [
          "checkout_ui_extension",
        ]

        property! :ctx
        property :template, accepts: Models::ServerConfig::Development::VALID_TEMPLATES
        property :prompt,
          accepts: ->(prompt) { prompt.respond_to?(:call) },
          default: -> { CLI::UI::Prompt.method(:ask) }

        def call(project_details)
          return project_details unless template_required?(project_details)
          project_details.template = template || choose_interactively
          project_details
        end

        private

        def template_required?(project_details)
          return false unless extension_server_beta?
          type = project_details&.type&.identifier
          TEMPLATE_REQUIRED_TYPES.include?(type.downcase)
        end

        def extension_server_beta?
          ShopifyCLI::Shopifolk.check && ShopifyCLI::Feature.enabled?(:extension_server_beta)
        end

        def choose_interactively
          prompt.call(ctx.message("create.ask_template")) do |handler|
            Models::ServerConfig::Development::VALID_TEMPLATES.each do |template|
              handler.option(template) { template }
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shopify-cli-2.6.6 lib/project_types/extension/forms/questions/ask_template.rb