AGC 小红书导出 pack:--zip-out 默认 ../.export/xhs-minitool.zip
- pack.mjs:--zip-out 默认 ../.export/xhs-minitool.zip(假设 cwd 是 game/ 子工程,落到项目根 .export/),仍可显式覆盖;USAGE 同步 - SKILL.md:步骤 3 写明默认落点与 game/ 假设 - .pack.test.mjs:补默认落点用例(cwd=game/ 时 zip 落在项目根 .export/) - manifest:vite-export-xhs-minitool 指纹与 version 同步到 2026-08-26.61
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"schemaVersion": "agc-skill-pack.v1",
|
||||
"version": "2026-08-26.60",
|
||||
"version": "2026-08-26.61",
|
||||
"skills": [
|
||||
{
|
||||
"name": "agc-unity-editor",
|
||||
@@ -204,7 +204,7 @@
|
||||
"scripts/validate.mjs",
|
||||
"scripts/vite.config.xhs-minitool.mjs"
|
||||
],
|
||||
"sha256": "1488810b869df35f1d5283b09b57d1f73b7d56ca6fad74052d141414768a3150"
|
||||
"sha256": "9a4ebd56d9fe30dacacec35ab2af941ea08cffc3764564a6d0331bb251cfc612"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+1
-2
@@ -12,8 +12,7 @@ metadata:
|
||||
1. 复制 (并按实际情况修改) `scripts/vite.config.xhs-minitool.mjs` 作为vite构建配置, 这个配置保证了产物符合小红书小工具的规范.
|
||||
2. 使用 `scripts/validate.mjs` 验证上述配置构建产物目录, 这个脚本实现了一些硬性检查, 此外有一些手动检查项:
|
||||
`references/manual-checks.md`
|
||||
3. 使用 `scripts/pack.mjs` 打包成zip; 产物必须是 **项目根**的 `.export/xhs-minitool.zip`, 而 `--zip-out` 相对 cwd
|
||||
解析:所以例如 npm 脚本挂在 `game/` 子工程时写 `../.export/xhs-minitool.zip`
|
||||
3. 使用 `scripts/pack.mjs` 打包成zip; `--zip-out` 默认 **`../.export/xhs-minitool.zip`** (假设 cwd 是 `game/` 子工程, 产物落在 **项目根** `.export/xhs-minitool.zip`; 相对 cwd 解析)
|
||||
4. 跑通流程后请把需要的脚本配置复制 (agc_install_skill_resource )到项目里 (以免依赖skill), 并形成最终的打包脚本
|
||||
|
||||
* 不干扰正常的web构建
|
||||
|
||||
+10
@@ -81,6 +81,16 @@ test('干净产物目录仍能正常打包', () => {
|
||||
assert.ok(existsSync(zipOut), 'zip 未生成');
|
||||
});
|
||||
|
||||
test('--zip-out 默认 ../.export/xhs-minitool.zip(假设 cwd 是 game/)', () => {
|
||||
const game = join(BASE, 'default-layout', 'game');
|
||||
writeBuiltDir(join('default-layout', 'game', 'dist-xhs-minitool'));
|
||||
assert.equal(packMinitool({ cwd: game }), 0);
|
||||
assert.ok(
|
||||
existsSync(join(BASE, 'default-layout', '.export', 'xhs-minitool.zip')),
|
||||
'默认落点不在项目根的 .export/',
|
||||
);
|
||||
});
|
||||
|
||||
test('pack 只打 zip,不再改写产物目录', () => {
|
||||
const root = writeBuiltDir('no-rewrite');
|
||||
// 故意留一份「构建后还没收尾」的 index.html:type=module / crossorigin / 根路径脚本。
|
||||
|
||||
+12
-11
@@ -27,17 +27,24 @@ const MIB = 1024 * 1024;
|
||||
const ZIP_HARD_LIMIT = 10 * MIB;
|
||||
const ZIP_RECOMMENDED = 2 * MIB;
|
||||
|
||||
/**
|
||||
* 默认落点:假设 npm 脚本挂在 `game/` 子工程(cwd = `game/`),宿主在**项目根**
|
||||
* `.export/xhs-minitool.zip` 找产物,所以默认写 `../.export/xhs-minitool.zip`。
|
||||
* 脚本挂在项目根 `package.json`(cwd = 项目根)时用 `--zip-out .export/xhs-minitool.zip` 覆盖。
|
||||
*/
|
||||
const DEFAULT_ZIP_OUT = join('..', '.export', 'xhs-minitool.zip');
|
||||
|
||||
const FORBIDDEN_ENTRY =
|
||||
/(^|\/)(?:node_modules|\.git)\/|(^|\/)\.DS_Store$|\.map$|(^|\/)(?:vite|webpack|rollup)\.config\.[^/]+$/i;
|
||||
|
||||
const USAGE = `用法:node pack.mjs [--vite-built-dir <dir>] --zip-out <path>
|
||||
const USAGE = `用法:node pack.mjs [--vite-built-dir <dir>] [--zip-out <path>]
|
||||
|
||||
把 vite 构建产物打成根目录带 index.html 的 zip;产物应先由 vite.config.xhs-minitool.mjs 收尾。
|
||||
|
||||
--vite-built-dir <dir> vite 的构建输出目录,必须与 vite config 的 build.outDir 一致。默认 dist-xhs-minitool。
|
||||
该目录出现白名单之外的文件类型时直接报错退出并列出文件,不会删除任何文件。
|
||||
本脚本不改写该目录,只读它来打 zip。
|
||||
--zip-out <path> 落点(例如 AGC 导出面板要求的 .export/xhs-minitool.zip):
|
||||
--zip-out <path> 落点。默认 ${DEFAULT_ZIP_OUT}(假设 cwd 是 game/ 子工程,产物落在项目根的 .export/xhs-minitool.zip);
|
||||
相对路径按当前工作目录解析,父目录不存在会自动建。`;
|
||||
|
||||
/**
|
||||
@@ -247,16 +254,13 @@ function warnIfWorkdirRelative(cwd, zipPath, zipOut) {
|
||||
* @param {{
|
||||
* cwd?: string,
|
||||
* viteBuiltDir?: string,
|
||||
* zipOut: string,
|
||||
* zipOut?: string,
|
||||
* }} options
|
||||
*/
|
||||
export function packMinitool(options = {}) {
|
||||
if (!options.zipOut) {
|
||||
throw new Error('缺少 --zip-out:打包要给出 zip 的落点');
|
||||
}
|
||||
const cwd = resolve(options.cwd || process.cwd());
|
||||
const viteBuiltDir = resolve(cwd, options.viteBuiltDir || 'dist-xhs-minitool');
|
||||
const zipPath = resolve(cwd, options.zipOut);
|
||||
const zipPath = resolve(cwd, options.zipOut || DEFAULT_ZIP_OUT);
|
||||
|
||||
warnIfWorkdirRelative(cwd, zipPath, options.zipOut);
|
||||
|
||||
@@ -315,14 +319,11 @@ if (isMainModule()) {
|
||||
let zipOut;
|
||||
try {
|
||||
viteBuiltDir = takeFlag('--vite-built-dir');
|
||||
zipOut = takeFlag('--zip-out');
|
||||
zipOut = takeFlag('--zip-out') || DEFAULT_ZIP_OUT;
|
||||
// 不认识的参数当场拒绝:否则调用方以为它生效了,产物落到别处还查不出来。
|
||||
if (raw.length > 0) {
|
||||
throw new Error(`不认识的参数:${raw.join(' ')}`);
|
||||
}
|
||||
if (!zipOut) {
|
||||
throw new Error('缺少 --zip-out');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err instanceof Error ? err.message : err);
|
||||
console.error(USAGE);
|
||||
|
||||
Reference in New Issue
Block a user