1
0
Files
DiAL/scripts/build.ts
lanyuanxiaoyao ccd16a583e feat: 跨平台发布打包,支持 7 个目标平台交叉编译和 tar.gz 分发
- 新增 scripts/release.ts,支持 7 个编译目标(linux/darwin/windows + musl 变体)
- 从 build.ts 提取共享构建逻辑到 build-common.ts,现有 build 行为不变
- 使用 tar-stream + node:zlib 创建 tar.gz,精确控制 Unix 权限位
- SHA256 校验和文件格式兼容 sha256sum -c
- 支持 --target 参数选择特定平台编译
- 新增 devDependency: tar-stream、@types/tar-stream
- 更新 README.md 和 DEVELOPMENT.md 文档
- 同步 openspec specs
2026-05-20 23:24:36 +08:00

53 lines
1.3 KiB
TypeScript

import { rm } from "node:fs/promises";
import { join } from "node:path";
import { buildDir, cleanup, codeGeneration, projectRoot, viteBuild } from "./build-common";
const executablePath = join(projectRoot, "dist/dial-server");
async function build() {
try {
await viteBuild();
await codeGeneration();
await bunCompile();
await cleanup();
console.log(`Built executable: ${executablePath}`);
} catch (error) {
await cleanup();
console.error("Build failed:", error);
process.exit(1);
}
}
async function bunCompile() {
console.log("Step 3/3: Bun compile...");
await rm(executablePath, { force: true });
const target = process.env["BUN_TARGET"] ?? process.env["BUILD_TARGET"];
const result = await Bun.build({
compile: target
? {
autoloadBunfig: true,
autoloadDotenv: true,
outfile: executablePath,
target: target as Bun.Build.CompileTarget,
}
: {
autoloadBunfig: true,
autoloadDotenv: true,
outfile: executablePath,
},
entrypoints: [join(buildDir, "server-entry.ts")],
minify: true,
sourcemap: "linked",
});
if (!result.success) {
console.error("Bun compile failed:", result.logs);
await cleanup();
process.exit(1);
}
}
await build();