2025-04-17 15:31:56 +00:00
|
|
|
import esbuild from "esbuild";
|
2026-05-25 12:37:42 +00:00
|
|
|
import { rm } from "fs/promises";
|
2025-04-17 15:31:56 +00:00
|
|
|
import process from "process";
|
2026-05-25 08:57:12 +00:00
|
|
|
import bundleConfig from "./scripts/lib/esbuild-bundle-config.js";
|
2026-06-06 09:04:58 +00:00
|
|
|
import packagingContract from "./scripts/lib/packaging-contract.js";
|
2025-04-17 15:31:56 +00:00
|
|
|
|
|
|
|
|
const prod = (process.argv[2] === "production");
|
2026-05-25 08:57:12 +00:00
|
|
|
const {
|
|
|
|
|
createMainBundleBuildOptions
|
|
|
|
|
} = bundleConfig;
|
2026-06-06 08:49:00 +00:00
|
|
|
const {
|
|
|
|
|
RENDER_HOST_STANDALONE_OUTPUT_FILES
|
2026-06-06 09:04:58 +00:00
|
|
|
} = packagingContract;
|
2026-05-25 12:37:42 +00:00
|
|
|
|
|
|
|
|
async function removeStaleRenderHostOutputs() {
|
2026-06-06 08:49:00 +00:00
|
|
|
await Promise.all(RENDER_HOST_STANDALONE_OUTPUT_FILES.map(async (relativePath) => {
|
2026-05-25 12:37:42 +00:00
|
|
|
await rm(relativePath, { force: true });
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await removeStaleRenderHostOutputs();
|
|
|
|
|
|
2026-06-06 09:04:58 +00:00
|
|
|
const context = await esbuild.context(createMainBundleBuildOptions({ prod }));
|
2025-04-17 15:31:56 +00:00
|
|
|
|
|
|
|
|
if (prod) {
|
|
|
|
|
await context.rebuild();
|
2026-05-25 08:57:12 +00:00
|
|
|
await context.dispose();
|
2025-04-17 15:31:56 +00:00
|
|
|
process.exit(0);
|
|
|
|
|
} else {
|
|
|
|
|
await context.watch();
|
|
|
|
|
}
|