Files
hose-use/scripts/build/build-plugin.mjs
gitea c71b20c25b chore: 按用途整理工程脚本与验证入口
将内部脚本归入 build、release、generate、dev 和 checks,保留公开安装脚本路径。
同步命令、CI、发布流程、脚本间调用及根目录定位,补齐脚本说明与完成报告。

验证:929 项测试、类型与版本检查通过;二进制及插件构建、冒烟与打包通过。
OpenAPI 产物不变;工作流 Schema 导出存在基线即可复现的 Zod transform 错误,单独记录。
2026-10-30 14:15:32 +08:00

31 lines
1.4 KiB
JavaScript

import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { spawnSync } from "node:child_process";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const root = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
const bun = process.env.BUN_BIN || "bun";
const args = process.argv.slice(2);
if (args.some(arg => !arg.startsWith("--outfile="))) {
throw new Error("Usage: build-plugin.mjs [--outfile=<path>]");
}
function run(args) {
const result = spawnSync(bun, args, {
cwd: root,
stdio: "inherit",
});
if (result.error) throw result.error;
if (result.status !== 0) {
throw new Error(`${bun} ${args.join(" ")} failed with status ${result.status}`);
}
}
const mcpOutput = resolve(args.find(arg => arg.startsWith("--outfile="))?.slice("--outfile=".length) || resolve(root, "dist/mcp/server.js"));
mkdirSync(dirname(mcpOutput), { recursive: true });
// The shared CLI uses bun:sqlite; the plugin manifest must use this runtime too.
// Embedded CommonJS loaders must use the bundle path, not the build host's absolute checkout path.
run(["build", "src/server.ts", "--minify", "--target=bun", "--define", "__filename=import.meta.path", "--outfile", mcpOutput]);
writeFileSync(mcpOutput, readFileSync(mcpOutput, "utf8").replace(/[ \t]+$/gm, ""));
console.log(`✓ Successfully bundled MCP server: ${mcpOutput}`);