Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 2403de0

Browse files
authored
Fix for "X zip is required for packaging a theme" on Windows (#2667)
1 parent 62b82bc commit 2403de0

File tree

4 files changed

+95
-9
lines changed

4 files changed

+95
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ From version 2.6.0, the sections in this file adhere to the [keep a changelog](h
44

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

89
## Version 2.29.0 - 2022-10-19
910

lib/project_types/theme/commands/package.rb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ class Package < ShopifyCLI::Command::SubCommand
1818
release-notes.md
1919
]
2020

21+
ZIP = "zip"
22+
SEVEN_ZIP = "7z"
23+
2124
def call(args, _name)
2225
path = args.first || "."
2326

24-
check_prereq_command("zip")
27+
check_prereq_command
2528
zip_name = theme_name(path) + ".zip"
29+
2630
zip(zip_name, path, THEME_DIRECTORIES)
2731
@ctx.done(@ctx.message("theme.package.done", zip_name))
2832
end
@@ -33,13 +37,12 @@ def self.help
3337

3438
private
3539

36-
def check_prereq_command(command)
37-
cmd_path = @ctx.which(command)
38-
@ctx.abort(@ctx.message("theme.package.error.prereq_command_required", command)) if cmd_path.nil?
40+
def check_prereq_command
41+
@ctx.abort(@ctx.message("theme.package.error.prereq_command_required")) if command.nil?
3942
end
4043

4144
def zip(zip_name, path, files)
42-
@ctx.system("zip", "-r", zip_name, *files, chdir: path)
45+
@ctx.system(command, command_flags, zip_name, *files, chdir: path)
4346
end
4447

4548
def theme_name(path)
@@ -53,6 +56,18 @@ def theme_name(path)
5356

5457
[theme_name, theme_info["theme_version"]].compact.join("-")
5558
end
59+
60+
def command
61+
@command ||= if @ctx.which(ZIP)
62+
ZIP
63+
elsif @ctx.which(SEVEN_ZIP)
64+
SEVEN_ZIP
65+
end
66+
end
67+
68+
def command_flags
69+
@command_flags ||= command == ZIP ? "-r" : "a"
70+
end
5671
end
5772
end
5873
end

lib/project_types/theme/messages/messages.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ module Messages
302302
Usage: {{command:%s theme package [ ROOT ]}}
303303
HELP
304304
error: {
305-
prereq_command_required: "%1$s is required for packaging a theme. Please install %1$s "\
306-
"using the appropriate package manager for your system.",
305+
prereq_command_required: "zip or 7zip is required for packaging a theme. Please install "\
306+
"zip or 7zip using the appropriate package manager for your system.",
307307
missing_config: "Provide a config/settings_schema.json to package your theme",
308308
missing_theme_name: "Provide a theme_info.theme_name configuration in config/settings_schema.json",
309309
},

test/project_types/theme/commands/package_test.rb

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ class PackageTest < MiniTest::Test
88

99
def setup
1010
super
11-
@context.stubs(:which).with("zip").returns(true)
1211
end
1312

14-
def test_package_theme
13+
def test_zip_and_seven_zip_command_present
14+
@context.stubs(:which).with("zip").returns("path/to/zip")
15+
@context.stubs(:which).with("7z").returns("path/to/7z")
16+
1517
theme_root = File.join(ShopifyCLI::ROOT, "test/fixtures/theme")
18+
1619
@context.expects(:system).with(
1720
"zip",
1821
"-r",
@@ -33,6 +36,73 @@ def test_package_theme
3336
run_cmd("theme package #{theme_root}")
3437
end
3538

39+
def test_only_seven_zip_command_present
40+
@context.stubs(:which).with("zip").returns(nil)
41+
@context.stubs(:which).with("7z").returns("path/to/7z")
42+
43+
theme_root = File.join(ShopifyCLI::ROOT, "test/fixtures/theme")
44+
@context.expects(:system).with(
45+
"7z",
46+
"a",
47+
"Example-1.0.0.zip",
48+
*%w[
49+
assets
50+
config
51+
layout
52+
locales
53+
sections
54+
snippets
55+
templates
56+
release-notes.md
57+
],
58+
chdir: theme_root
59+
)
60+
61+
run_cmd("theme package #{theme_root}")
62+
end
63+
64+
def test_only_zip_command_present
65+
@context.stubs(:which).with("zip").returns("path/to/zip")
66+
@context.stubs(:which).with("7z").returns(nil)
67+
68+
theme_root = File.join(ShopifyCLI::ROOT, "test/fixtures/theme")
69+
@context.expects(:system).with(
70+
"zip",
71+
"-r",
72+
"Example-1.0.0.zip",
73+
*%w[
74+
assets
75+
config
76+
layout
77+
locales
78+
sections
79+
snippets
80+
templates
81+
release-notes.md
82+
],
83+
chdir: theme_root
84+
)
85+
86+
run_cmd("theme package #{theme_root}")
87+
end
88+
89+
def test_no_system_zip_command_present
90+
@context.stubs(:which).with("zip").returns(nil)
91+
@context.stubs(:which).with("7z").returns(nil)
92+
93+
theme_root = File.join(ShopifyCLI::ROOT, "test/fixtures/theme")
94+
95+
error = assert_raises(CLI::Kit::Abort) do
96+
run_cmd("theme package #{theme_root}")
97+
end
98+
99+
assert_equal(
100+
"{{x}} zip or 7zip is required for packaging a theme. Please install "\
101+
"zip or 7zip using the appropriate package manager for your system.",
102+
error.message
103+
)
104+
end
105+
36106
def test_invalid_theme
37107
theme_root = "."
38108
@context.expects(:system).never

0 commit comments

Comments
 (0)