将内部脚本归入 build、release、generate、dev 和 checks,保留公开安装脚本路径。 同步命令、CI、发布流程、脚本间调用及根目录定位,补齐脚本说明与完成报告。 验证:929 项测试、类型与版本检查通过;二进制及插件构建、冒烟与打包通过。 OpenAPI 产物不变;工作流 Schema 导出存在基线即可复现的 Zod transform 错误,单独记录。
36 lines
1.8 KiB
JavaScript
36 lines
1.8 KiB
JavaScript
import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
import { spawnSync } from "node:child_process";
|
|
import { tmpdir } from "node:os";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
|
const args = process.argv.slice(2);
|
|
if (args.some(arg => !arg.startsWith("--out-dir="))) {
|
|
throw new Error("Usage: package-plugin.mjs [--out-dir=<path>]");
|
|
}
|
|
const outputDir = resolve(args.find(arg => arg.startsWith("--out-dir="))?.slice("--out-dir=".length) || resolve(root, "dist/bin"));
|
|
const { version } = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
const archive = join(outputDir, `hose-use-plugin-v${version}.tar.gz`);
|
|
const stage = mkdtempSync(join(tmpdir(), "hose-plugin-package-"));
|
|
|
|
function run(command, commandArgs) {
|
|
const result = spawnSync(command, commandArgs, { cwd: root, stdio: "inherit" });
|
|
if (result.error) throw result.error;
|
|
if (result.status !== 0) throw new Error(`${command} failed with status ${result.status}`);
|
|
}
|
|
|
|
try {
|
|
// Explicit package inputs keep credentials, local notes and dependencies out of the archive.
|
|
for (const path of [".zcode-plugin/plugin.json", ".mcp.json", "skills"]) {
|
|
cpSync(join(root, path), join(stage, path), { recursive: true });
|
|
}
|
|
// Always build from current source; never package a stale local dist/ bundle.
|
|
run(process.execPath, [join(root, "scripts/build/build-plugin.mjs"), `--outfile=${join(stage, "dist/mcp/server.js")}`]);
|
|
mkdirSync(outputDir, { recursive: true });
|
|
run("tar", ["-czf", archive, "-C", stage, ".zcode-plugin", ".mcp.json", "skills", "dist"]);
|
|
console.log(`✓ Packaged plugin: ${archive}`);
|
|
} finally {
|
|
rmSync(stage, { recursive: true, force: true });
|
|
}
|