Files
MTranServer/scripts/build.ts
xxnuo b9a3592524 docs: update
Update Dockerfile

Squashed commit of the following:

Author: xxnuo <54252779+xxnuo@users.noreply.github.com>

    fix: Building Docker images using Node.js

Author: xxnuo <54252779+xxnuo@users.noreply.github.com>

    feat: node docker version

Author: xxnuo <54252779+xxnuo@users.noreply.github.com>

    fix: warn language detection failed
2026-01-06 15:49:03 +08:00

49 lines
1.7 KiB
TypeScript

import { $ } from "bun";
import pkg from "../package.json";
const version = pkg.version;
const isDocker = Bun.argv.includes("--docker");
const allTargets = [
{ bun: "bun-darwin-x64", name: "darwin-amd64" },
{ bun: "bun-darwin-x64-baseline", name: "darwin-amd64-legacy" },
{ bun: "bun-darwin-arm64", name: "darwin-arm64" },
{ bun: "bun-linux-x64", name: "linux-amd64" },
{ bun: "bun-linux-x64-baseline", name: "linux-amd64-legacy" },
{ bun: "bun-linux-arm64", name: "linux-arm64" },
{ bun: "bun-linux-x64-musl", name: "linux-amd64-musl" },
{ bun: "bun-linux-x64-musl-baseline", name: "linux-amd64-musl-legacy" },
{ bun: "bun-linux-arm64-musl", name: "linux-arm64-musl" },
{ bun: "bun-windows-x64", name: "windows-amd64" },
{ bun: "bun-windows-x64-baseline", name: "windows-amd64-legacy" }
];
console.log("Cleaning dist...");
await $`rm -rf dist`;
await $`mkdir -p dist`;
console.log("Building UI...");
await $`cd ui && bun install && bun run build`;
console.log("Generating UI assets map...");
await $`bun run scripts/gen-ui-assets.ts`;
console.log("Generating Swagger assets map...");
await $`bun run scripts/gen-swagger-assets.ts`;
console.log("Generating routes and spec...");
await $`bun run gen`;
if (isDocker) {
console.log("Building for Docker...");
await $`bun run build:node`;
} else {
for (const target of allTargets) {
const ext = target.bun.includes("windows") ? ".exe" : "";
const outfile = `dist/mtranserver-${version}-${target.name}${ext}`;
console.log(`Building for ${target.bun} -> ${outfile}...`);
await $`bun build src/main.ts --compile --target=${target.bun} --outfile=${outfile} --minify --sourcemap`;
}
}
console.log("Build complete!");