为什么 Shopify 在使用 Powershell 压缩时不接受我的主题的 zip 文件

Why wont Shopify accept my theme's zip file when compressed using Powershell

我正在尝试创建一个工作流程,用于基于同一主题设计多个 Shopify 主题。我写了一个简单的 PowerShell 脚本,它收集必要的文件并将它们压缩成一个 zip 文件。

这是我的脚本的简化版本:

# Copy all files from the base theme to my temporary folder
Copy-Item $baseTheme"*" $tempFolder -recurse -force -exclude ".git"

# Include the files specific to the current theme
Copy-Item $specificTheme"assets"    $tempFolder -recurse -force
Copy-Item $specificTheme"config"    $tempFolder -recurse -force
Copy-Item $specificTheme"layout"    $tempFolder -recurse -force
Copy-Item $specificTheme"snippets"  $tempFolder -recurse -force
Copy-Item $specificTheme"templates" $tempFolder -recurse -force

# Compress the temporary folder
Compress-Archive $tempFolder $zipFileName

当我手动执行这些步骤并使用 Send To > Compressed (zipped) folder 在 Windows 中创建 zip 文件时,Shopify 对 zip 文件非常满意。

但是,当我上传此脚本的结果时,出现以下错误:

There was 1 error:

zip does not contain a valid theme: missing template "layout/theme.liquid", missing template "templates/index.liquid", missing template "templates/collection.liquid", missing template "templates/product.liquid", missing template "templates/page.liquid", missing template "templates/cart.liquid", and missing template "templates/blog.liquid"

我已经对 zip 文件进行了两次和三次检查,所有需要的文件都存在。我弄乱了 PowerShell 中压缩文件夹的 -CompressionLevel of Compress-Archive. I've tried other methods。都没有运气。

我真的看不出脚本的结果和手动压缩有什么区别。有什么想法吗?

这看起来像是存档文件中的文件夹结构有问题。

如果您检查通过 PowerShell 创建的存档文件,它显示的结构是否与手动创建的文件相同?

This link 显示了 Shopify 主题的预期文件夹结构:

index.liquid
product.liquid
collection.liquid
cart.liquid
blog.liquid
article.liquid
page.liquid
list_collections.liquid
search.liquid
404.liquid
gift_cards.liquid
customers/account.liquid
customers/activate.liquid
customers/addresses.liquid
customers/login.liquid
customers/order.liquid
customers/register.liquid
customers/reset_password.liquid
password.liquid
settings_schema.json
theme.liquid (layout file)

我正在回答我自己的问题,但我不是解决问题的人。我在 shopify forum 上针对这个问题发布了一个 link,一个名叫 Adrian 的人发布了以下答案。

Short version. Download 7-ZIP and use the test archive facility. Zips created with compress-archive show no folders whereas those created with the Send To zip in Windows do. The folders do exist inside the actual archive though so I'd say the header info is malformed.

Looks like there is a structural error within the files that compress-archive creates that Windows is happy with but the, probably Unix-based, Shopify servers don't accept.

我安装了 7-Zip 并使用 Test Archive 功能评估了这两个文件夹。这是(截断的)输出:

使用 Compress-Archive 压缩

Archives: 1
Files: 77
There are no errors.

使用 Send-To Zip 上下文菜单压缩

Archives: 1
Folders: 6
Files: 76
There are no errors.

此时,我很高兴知道发生了什么。但为了真正解决这个问题,我更新了我的 PowerShell 脚本以使用 7-Zip 压缩文件夹。

我替换了这个:

# Compress the temporary folder
Compress-Archive $tempFolder $zipFileName

有了这个:

# Compress the temporary folder
& "c:\Program Files-Zipz.exe" a -tzip $zipFile $tempFolder

我将存档上传到 Shopify,一切正常。

现在,我真的对安装 运行 第三方软件来执行(我认为)应该是一项基本 OS 任务的事情并不那么兴奋。我已将此问题报告给 Microsoft here。谁知道呢,也许他们会修好它。