45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
export const webBuildSurfaces = ["core", "admin", "portal"] as const;
|
|
|
|
export type WebBuildSurface = (typeof webBuildSurfaces)[number];
|
|
|
|
export const webBuildDirectories: Record<WebBuildSurface, string> = {
|
|
core: "build",
|
|
// Admin shares the immutable Core artifact, while the runtime gate below
|
|
// gives it a distinct host, process identity, and fail-closed environment.
|
|
admin: "build",
|
|
portal: "build-portal",
|
|
};
|
|
|
|
export const webServiceNames: Record<WebBuildSurface, "hivegrid-web" | "hivegrid-admin" | "hivegrid-portal"> = {
|
|
core: "hivegrid-web",
|
|
admin: "hivegrid-admin",
|
|
portal: "hivegrid-portal",
|
|
};
|
|
|
|
export function requireWebBuildSurface(env: Readonly<{ HIVEGRID_RUNTIME_SURFACE?: string }> = process.env, fallback?: WebBuildSurface): WebBuildSurface {
|
|
const surface = env.HIVEGRID_RUNTIME_SURFACE;
|
|
if (surface === "core" || surface === "admin" || surface === "portal") {
|
|
return surface;
|
|
}
|
|
if (surface === undefined && fallback) {
|
|
return fallback;
|
|
}
|
|
|
|
throw new Error("HIVEGRID_RUNTIME_SURFACE must be explicitly set to core, admin, or portal");
|
|
}
|
|
|
|
export function getWebBuildDirectory(surface: WebBuildSurface) {
|
|
return webBuildDirectories[surface];
|
|
}
|
|
|
|
export function getWebServiceName(surface: WebBuildSurface) {
|
|
return webServiceNames[surface];
|
|
}
|
|
|
|
export function getWebTestBuildSurfaceFallback(
|
|
env: Readonly<{ NODE_ENV?: string; VITEST?: string }> = process.env,
|
|
argv: readonly string[] = process.argv
|
|
): WebBuildSurface | undefined {
|
|
return env.NODE_ENV === "test" || env.VITEST === "true" || argv.some((argument) => /(?:^|[/\\])vitest(?:\.[cm]?js)?$/u.test(argument)) ? "core" : undefined;
|
|
}
|