Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ From version 2.6.0, the sections in this file adhere to the [keep a changelog](h

### Fixed
* [#2668](https://github.com/Shopify/shopify-cli/pull/2668): Introduce `--only/--ignore` in the `shopify theme serve` help message
* [#2667](https://github.com/Shopify/shopify-cli/pull/2667): Fix for "X zip is required for packaging a theme" on Windows

## Version 2.29.0 - 2022-10-19

Expand Down
25 changes: 20 additions & 5 deletions lib/project_types/theme/commands/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ class Package < ShopifyCLI::Command::SubCommand
release-notes.md
]

ZIP = "zip"
SEVEN_ZIP = "7z"
Comment thread
mgmanzella marked this conversation as resolved.

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

check_prereq_command("zip")
check_prereq_command
zip_name = theme_name(path) + ".zip"

zip(zip_name, path, THEME_DIRECTORIES)
@ctx.done(@ctx.message("theme.package.done", zip_name))
end
Expand All @@ -33,13 +37,12 @@ def self.help

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?
def check_prereq_command
@ctx.abort(@ctx.message("theme.package.error.prereq_command_required")) if command.nil?
end

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

def theme_name(path)
Expand All @@ -53,6 +56,18 @@ def theme_name(path)

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

def command
@command ||= if @ctx.which(ZIP)
ZIP
elsif @ctx.which(SEVEN_ZIP)
SEVEN_ZIP
end
end
Comment thread
karreiro marked this conversation as resolved.

def command_flags
@command_flags ||= command == ZIP ? "-r" : "a"
end
end
end
end
4 changes: 2 additions & 2 deletions lib/project_types/theme/messages/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ module Messages
Usage: {{command:%s theme package [ ROOT ]}}
HELP
error: {
prereq_command_required: "%1$s is required for packaging a theme. Please install %1$s "\
"using the appropriate package manager for your system.",
prereq_command_required: "zip or 7zip is required for packaging a theme. Please install "\
"zip or 7zip using the appropriate package manager for your system.",
missing_config: "Provide a config/settings_schema.json to package your theme",
Comment thread
mgmanzella marked this conversation as resolved.
missing_theme_name: "Provide a theme_info.theme_name configuration in config/settings_schema.json",
},
Expand Down
74 changes: 72 additions & 2 deletions test/project_types/theme/commands/package_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ class PackageTest < MiniTest::Test

def setup
super
@context.stubs(:which).with("zip").returns(true)
end

def test_package_theme
def test_zip_and_seven_zip_command_present
@context.stubs(:which).with("zip").returns("path/to/zip")
@context.stubs(:which).with("7z").returns("path/to/7z")

theme_root = File.join(ShopifyCLI::ROOT, "test/fixtures/theme")

@context.expects(:system).with(
"zip",
"-r",
Expand All @@ -33,6 +36,73 @@ def test_package_theme
run_cmd("theme package #{theme_root}")
end

def test_only_seven_zip_command_present
@context.stubs(:which).with("zip").returns(nil)
@context.stubs(:which).with("7z").returns("path/to/7z")

theme_root = File.join(ShopifyCLI::ROOT, "test/fixtures/theme")
@context.expects(:system).with(
"7z",
"a",
"Example-1.0.0.zip",
*%w[
assets
config
layout
locales
sections
snippets
templates
release-notes.md
],
chdir: theme_root
)

run_cmd("theme package #{theme_root}")
end

def test_only_zip_command_present
@context.stubs(:which).with("zip").returns("path/to/zip")
@context.stubs(:which).with("7z").returns(nil)

theme_root = File.join(ShopifyCLI::ROOT, "test/fixtures/theme")
@context.expects(:system).with(
"zip",
"-r",
"Example-1.0.0.zip",
*%w[
assets
config
layout
locales
sections
snippets
templates
release-notes.md
],
chdir: theme_root
)

run_cmd("theme package #{theme_root}")
end

def test_no_system_zip_command_present
@context.stubs(:which).with("zip").returns(nil)
@context.stubs(:which).with("7z").returns(nil)

theme_root = File.join(ShopifyCLI::ROOT, "test/fixtures/theme")

error = assert_raises(CLI::Kit::Abort) do
run_cmd("theme package #{theme_root}")
end

assert_equal(
"{{x}} zip or 7zip is required for packaging a theme. Please install "\
"zip or 7zip using the appropriate package manager for your system.",
error.message
)
end

def test_invalid_theme
theme_root = "."
@context.expects(:system).never
Expand Down