Sha256: f43cecc63c35e1e13a7f58d9b53190264a1ad01db70c4252f76c8c2c0df97d37

Contents?: true

Size: 1.23 KB

Versions: 7

Compression:

Stored size: 1.23 KB

Contents

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

        TEMPLATE_REQUIRED_TYPES = [
          "checkout_ui_extension",
        ]

        property! :ctx
        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 = 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

7 entries across 7 versions & 1 rubygems

Version Path
shopify-cli-2.6.5 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.6.4 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.6.3 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.6.2 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.6.1 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.6.0 lib/project_types/extension/forms/questions/ask_template.rb
shopify-cli-2.5.0 lib/project_types/extension/forms/questions/ask_template.rb