小红书导出 skill:新增确定的 zip 落点参数并写清 AGC 接入契约
- pack.mjs 新增 --zip-out <path>:相对当前工作目录解析、父目录自动创建,供「产物必须落在项目根 .export/ 下」的调用方指定落点;原 --zip <name> 默认行为不变。 - SKILL.md 增加「被 AGC 导出面板调用时」一节:三条硬契约(脚本名 build:xhs-minitool、非空 .export/xhs-minitool.zip、--out-dir 只指向构建输出目录)与拷贝到 .export/ 后如何定位项目根。 - vite.config.xhs-minitool.mjs 的注释点明 build.outDir 与 pack 的 --out-dir 必须一致,配错会删源码。 - manifest.json 同步 sha256 与版本 2026-08-26.41(文件清单不变,仍 36 个)。
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"schemaVersion": "agc-skill-pack.v1",
|
||||
"version": "2026-08-26.40",
|
||||
"version": "2026-08-26.41",
|
||||
"skills": [
|
||||
{
|
||||
"name": "agc-unity-editor",
|
||||
@@ -204,7 +204,7 @@
|
||||
"scripts/validate.mjs",
|
||||
"scripts/vite.config.xhs-minitool.mjs"
|
||||
],
|
||||
"sha256": "c5cae916577f1192972da5a986d8226ba56fbef1462243ca9e2b2d6bdd66ff58"
|
||||
"sha256": "9799b44c6de4c375148abdeb9dcbbe8c0acdf0eea11511c9f9da2cda96f6af7c"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+12
-1
@@ -3,7 +3,7 @@ name: vite-export-xhs-minitool
|
||||
description: >-
|
||||
vite 项目导出适配小红书小工具的制品
|
||||
metadata:
|
||||
version: "1.6.0"
|
||||
version: "1.7.0"
|
||||
---
|
||||
|
||||
1. 新增 `scripts/vite.config.xhs-minitool.mjs` (示例)作为vite构建配置, 这个配置保证了产物符合小红书小工具的规范.
|
||||
@@ -13,6 +13,17 @@ metadata:
|
||||
|
||||
3. 使用 `scripts/pack.mjs` 打包成zip
|
||||
|
||||
## 被 AGC 导出面板调用时
|
||||
|
||||
宿主只按三条硬契约校验, 接入的项目 MUST 逐条满足:
|
||||
|
||||
- npm 包 (声明 `package.json` 的那层目录) MUST 声明脚本 `build:xhs-minitool`.
|
||||
- 该脚本跑完 MUST 在项目根留下非空的 `.export/xhs-minitool.zip`; 用 `pack.mjs --zip-out <项目根>/.export/xhs-minitool.zip` 指定落点, 不要依赖默认文件名.
|
||||
- `pack.mjs --out-dir` MUST 只指向 vite 构建输出目录: 它会就地删掉该目录里白名单之外的扩展名文件, 指向源码目录会删掉用户代码.
|
||||
|
||||
把示例脚本拷贝到 `<项目根>/.export/` 下再改 (拷贝是项目自己的代码, 允许改路径与入口);
|
||||
拷贝自身的位置就是项目根: `dirname(import.meta.url)/..`.
|
||||
|
||||
* 如果使用了外部能力, 参考platform-abstract skill对项目先重构
|
||||
|
||||
以下是其他参考文档, 非必要不读
|
||||
|
||||
+14
-3
@@ -46,9 +46,13 @@ const ALLOWED = new Set([
|
||||
const FORBIDDEN_ENTRY =
|
||||
/(^|\/)(?:node_modules|\.git)\/|(^|\/)\.DS_Store$|\.map$|(^|\/)(?:vite|webpack|rollup)\.config\.[^/]+$/i;
|
||||
|
||||
const USAGE = `用法:node pack.mjs [--out-dir <dir>] [--zip <name>] [--skip-validate] [--no-strict]
|
||||
const USAGE = `用法:node pack.mjs [--out-dir <dir>] [--zip <name>] [--zip-out <path>] [--skip-validate] [--no-strict]
|
||||
|
||||
把 vite dist-xhs-minitool 产物整理成符合小红书规范、根目录带 index.html 的 zip。`;
|
||||
把 vite dist-xhs-minitool 产物整理成符合小红书规范、根目录带 index.html 的 zip。
|
||||
|
||||
--zip <name> 只给文件名时用:写到当前工作目录下。
|
||||
--zip-out <path> 需要指定落点(例如 AGC 导出面板要求的 .export/xhs-minitool.zip)时用:
|
||||
相对路径按当前工作目录解析,父目录不存在会自动建。`;
|
||||
|
||||
function walk(dir) {
|
||||
const out = [];
|
||||
@@ -296,6 +300,7 @@ function readPackageName(cwd) {
|
||||
* cwd?: string,
|
||||
* outDir?: string,
|
||||
* zipName?: string,
|
||||
* zipOut?: string,
|
||||
* publicDir?: string,
|
||||
* skipValidate?: boolean,
|
||||
* strict?: boolean,
|
||||
@@ -305,13 +310,18 @@ export function packMinitool(options = {}) {
|
||||
const cwd = resolve(options.cwd || process.cwd());
|
||||
const outDir = resolve(cwd, options.outDir || 'dist-xhs-minitool');
|
||||
const zipName = options.zipName || `${readPackageName(cwd)}-xhs-tool.zip`;
|
||||
const zipPath = resolve(cwd, zipName);
|
||||
// `zipOut` 优先:调用方(如 .export/ 下的项目拷贝)要的是确定的落点,而不是"当前目录下叫什么名字"。
|
||||
const zipPath = options.zipOut
|
||||
? resolve(cwd, options.zipOut)
|
||||
: resolve(cwd, zipName);
|
||||
const publicDir = resolve(cwd, options.publicDir || 'public');
|
||||
const strict = options.strict !== false;
|
||||
|
||||
if (!existsSync(outDir)) {
|
||||
throw new Error(`缺少输出目录 ${outDir}`);
|
||||
}
|
||||
// 落点的父目录可能还不存在(`.export/` 是宿主按需创建的),先建再写。
|
||||
mkdirSync(dirname(zipPath), { recursive: true });
|
||||
|
||||
for (const icon of ['icon-192.svg', 'icon-512.svg']) {
|
||||
const dest = join(outDir, 'icons', icon);
|
||||
@@ -375,6 +385,7 @@ if (isMainModule()) {
|
||||
const code = packMinitool({
|
||||
outDir: getFlagValue('--out-dir'),
|
||||
zipName: getFlagValue('--zip'),
|
||||
zipOut: getFlagValue('--zip-out'),
|
||||
skipValidate: flags.has('--skip-validate'),
|
||||
strict: !flags.has('--no-strict'),
|
||||
});
|
||||
|
||||
+3
@@ -8,6 +8,9 @@
|
||||
* import { defineMinitoolConfig } from '<此文件路径>';
|
||||
* export default defineMinitoolConfig({ plugins: [...] });
|
||||
*
|
||||
* 下面 build.outDir 的值与打包脚本的 --out-dir 是同一个目录,两处必须一致:
|
||||
* pack.mjs 会就地删掉该目录里白名单之外的扩展名文件,配错会删掉源码。
|
||||
*
|
||||
* 约束来源:minitool-zip-builder/references/js-compatibility.md、css-compatibility.md、
|
||||
* zip-artifact-spec.md —— Chrome 61 / ES2017 基线、相对路径、IIFE 单入口、无 sourcemap。
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user