27 lines
1.1 KiB
JavaScript
27 lines
1.1 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";
|
|
|
|
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 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}`);
|