Sha256: 15f2f3fc9fe21e48c19e6661a248826c6edfb209b4720b792f47bb20744c2331

Contents?: true

Size: 1.99 KB

Versions: 8

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true
require "shopify_cli"

module Extension
  module Commands
    class Push < ExtensionCommand
      TIME_DISPLAY_FORMAT = "%B %d, %Y %H:%M:%S %Z"

      def call(args, name)
        Commands::Register.new(@ctx).call(args, name) unless project.registered?
        Commands::Build.new(@ctx).call(args, name)

        CLI::UI::Frame.open(@ctx.message("push.frame_title")) do
          updated_draft_version = update_draft
          show_message(updated_draft_version)
        end
      end

      def self.help
        <<~HELP
          Push the current extension to Shopify.
            Usage: {{command:#{ShopifyCli::TOOL_NAME} push}}
        HELP
      end

      private

      def show_message(draft)
        draft.validation_errors.empty? ? output_success_messages(draft) : output_validation_errors(draft)
      end

      def output_success_messages(draft)
        @ctx.puts(@ctx.message("push.success_confirmation", project.title, format_time(draft.last_user_interaction_at)))
        @ctx.puts(@ctx.message("push.success_info", draft.location))
      end

      def output_validation_errors(draft)
        @ctx.puts(@ctx.message("push.pushed_with_errors", format_time(draft.last_user_interaction_at)))

        draft.validation_errors.each do |error|
          @ctx.puts(format("{{x}} %s: %s", error.field.last, error.message))
        end

        @ctx.puts(@ctx.message("push.push_with_errors_info"))
      end

      def format_time(time)
        time.utc.strftime(TIME_DISPLAY_FORMAT)
      end

      def with_waiting_text
        @ctx.puts(@ctx.message("push.waiting_text"))
        yield
      end

      def update_draft
        with_waiting_text do
          Tasks::UpdateDraft.call(
            context: @ctx,
            api_key: project.app.api_key,
            registration_id: project.registration_id,
            config: specification_handler.config(@ctx),
            extension_context: specification_handler.extension_context(@ctx)
          )
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shopify-cli-1.14.0 lib/project_types/extension/commands/push.rb
shopify-cli-1.13.1 lib/project_types/extension/commands/push.rb
shopify-cli-1.13.0 lib/project_types/extension/commands/push.rb
shopify-cli-1.12.0 lib/project_types/extension/commands/push.rb
shopify-cli-1.11.0 lib/project_types/extension/commands/push.rb
shopify-cli-1.10.0 lib/project_types/extension/commands/push.rb
shopify-cli-1.9.1 lib/project_types/extension/commands/push.rb
shopify-cli-1.9.0 lib/project_types/extension/commands/push.rb