-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
27 lines (25 loc) · 1.2 KB
/
Copy pathbuild.ts
File metadata and controls
27 lines (25 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* 打包脚本:用内置的 `deno bundle` 把源码打成一个「自包含单文件」dist/main.js,供 Node.js 直接运行。
*
* 运行时代码只用通用的 node:* API 与 Web 全局,故产物在 Node 与 Deno 上都能跑:
* deno bundle 会把 npm 依赖(MCP SDK、zod)内联进产物,而 node:net / node:tls / node:fs
* 等保留为外部内置(由运行时提供)。
*
* 本脚本本身是构建工具,运行在 Deno 下(deno bundle 是 Deno 命令)。
* 运行:deno task build -> 产物 dist/main.js(带 #!/usr/bin/env node,可 `node dist/main.js` 执行)
*/
const out = new URL("./dist/main.js", import.meta.url).pathname;
const entry = new URL("./main.ts", import.meta.url).pathname;
const { code } = await new Deno.Command("deno", {
args: ["bundle", "--platform=deno", "-o", out, entry],
stdout: "inherit",
stderr: "inherit",
}).output();
if (code !== 0) Deno.exit(code);
// deno bundle 不会加入 shebang,这里补上,使 npm bin 与直接执行可用。
const SHEBANG = "#!/usr/bin/env node\n";
const src = await Deno.readTextFile(out);
if (!src.startsWith("#!")) {
await Deno.writeTextFile(out, SHEBANG + src);
}
console.error("已生成 dist/main.js");