48 lines
1.7 KiB
JavaScript
48 lines
1.7 KiB
JavaScript
import { spawn } from "node:child_process";
|
|
import { createRequire } from "node:module";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { stageWebClientSourcemaps } from "./stage-web-sourcemaps.mjs";
|
|
import { stagePortalPublicAssets } from "./stage-portal-public-assets.mjs";
|
|
import { verifyWebBuildSurfaces } from "./verify-web-build-surfaces.mjs";
|
|
|
|
const rootDirectory = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
const webDirectory = path.join(rootDirectory, "apps", "web");
|
|
const require = createRequire(import.meta.url);
|
|
const reactRouterPackageDirectory = path.dirname(require.resolve("@react-router/dev/package.json"));
|
|
const reactRouterCli = path.join(reactRouterPackageDirectory, "bin.js");
|
|
|
|
for (const surface of ["core", "portal"]) {
|
|
await runReactRouterBuild(surface);
|
|
if (surface === "portal") {
|
|
stagePortalPublicAssets(rootDirectory);
|
|
}
|
|
}
|
|
verifyWebBuildSurfaces(rootDirectory);
|
|
if (process.env.HIVEGRID_BUILD_SOURCEMAPS === "1") {
|
|
await stageWebClientSourcemaps(rootDirectory);
|
|
}
|
|
|
|
function runReactRouterBuild(surface) {
|
|
return new Promise((resolve, reject) => {
|
|
const child = spawn(process.execPath, [reactRouterCli, "build", "."], {
|
|
cwd: webDirectory,
|
|
env: {
|
|
...process.env,
|
|
HIVEGRID_RUNTIME_SURFACE: surface,
|
|
VITE_OTEL_SERVICE_NAME: surface === "portal" ? "hivegrid-portal" : process.env.VITE_OTEL_SERVICE_NAME || "hivegrid-web",
|
|
},
|
|
stdio: "inherit",
|
|
});
|
|
|
|
child.once("error", reject);
|
|
child.once("exit", (code, signal) => {
|
|
if (code === 0) {
|
|
resolve();
|
|
return;
|
|
}
|
|
reject(new Error(`React Router ${surface} build failed (${signal ?? `exit ${code}`})`));
|
|
});
|
|
});
|
|
}
|