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"; 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(root, "dist/mcp/server.js"); mkdirSync(dirname(mcpOutput), { recursive: true }); // The MCP bundle imports the generated embedded Skill manifest. Regenerate it // before bundling so version bumps and documentation edits cannot leave the // tracked bundle one build behind the source tree. run(["run", "scripts/generate-embedded-skill.mjs"]); run(["build", "src/server.ts", "--minify", "--target=node", "--outfile", mcpOutput]); writeFileSync(mcpOutput, readFileSync(mcpOutput, "utf8").replace(/[ \t]+$/gm, "")); run(["run", "build:binary"]);