Sha256: 293697ffc918d7b89b2a29d5a143f3a55380dafa3b4ab3c6118481ae1e69421e

Contents?: true

Size: 1.62 KB

Versions: 25

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true
require "pathname"
require "json"

module Theme
  class Command
    class Package < ShopifyCLI::Command::SubCommand
      recommend_default_ruby_range

      THEME_DIRECTORIES = %w[
        assets
        config
        layout
        locales
        sections
        snippets
        templates
        release-notes.md
      ]

      def call(args, _name)
        path = args.first || "."

        check_prereq_command("zip")
        zip_name = theme_name(path) + ".zip"
        zip(zip_name, path, THEME_DIRECTORIES)
        @ctx.done(@ctx.message("theme.package.done", zip_name))
      end

      def self.help
        ShopifyCLI::Context.message("theme.package.help", ShopifyCLI::TOOL_NAME, ShopifyCLI::TOOL_NAME)
      end

      private

      def check_prereq_command(command)
        cmd_path = @ctx.which(command)
        @ctx.abort(@ctx.message("theme.package.error.prereq_command_required", command)) if cmd_path.nil?
      end

      def zip(zip_name, path, files)
        @ctx.system("zip", "-r", zip_name, *files, chdir: path)
      end

      def theme_name(path)
        settings_schema = Pathname.new(path).join("config/settings_schema.json")
        @ctx.abort(@ctx.message("theme.package.error.missing_config")) unless settings_schema.file?

        content = settings_schema.read
        theme_info = JSON.parse(content).find { |section| section["name"] == "theme_info" }
        theme_name = theme_info&.dig("theme_name")
        @ctx.abort(@ctx.message("theme.package.error.missing_theme_name")) unless theme_name

        [theme_name, theme_info["theme_version"]].compact.join("-")
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
shopify-cli-2.29.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.28.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.27.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.26.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.25.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.24.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.23.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.22.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.21.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.20.1 lib/project_types/theme/commands/package.rb
shopify-cli-2.20.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.19.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.18.1 lib/project_types/theme/commands/package.rb
shopify-cli-2.18.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.17.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.16.1 lib/project_types/theme/commands/package.rb
shopify-cli-2.16.0 lib/project_types/theme/commands/package.rb
shopify-cli-2.15.6 lib/project_types/theme/commands/package.rb
shopify-cli-2.15.5 lib/project_types/theme/commands/package.rb
shopify-cli-2.15.4 lib/project_types/theme/commands/package.rb