MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / buildFrontend

Function buildFrontend

scripts/static-build.mjs:15–82  ·  view source on GitHub ↗
(config, args = {})

Source from the content-addressed store, hash-verified

13import { buildNpmScriptCommand } from "./dev-safe.mjs";
14
15export function buildFrontend(config, args = {}) {
16 const buildDir = join(config.canvasPath, "build");
17
18 if (args.skipBuild) {
19 if (!existsSync(buildDir)) {
20 logError(
21 "--skip-build was passed but build/ does not exist. Run without --skip-build first.",
22 );
23 process.exit(1);
24 }
25 logStep("build", "Skipping frontend build (--skip-build)");
26 logService("build", `Reusing existing build/ at ${buildDir}`, c.dim);
27 logService(
28 "build",
29 "Source edits will NOT appear until you run without --skip-build (or `npm run build`).",
30 c.yellow,
31 );
32 return;
33 }
34
35 logStep("build", "Building frontend (npm run build:app)...");
36 logService(
37 "build",
38 "This typically takes 30-60s; cached as build/ for --skip-build reuse",
39 c.dim,
40 );
41
42 const cmd = buildNpmScriptCommand("build:app");
43 const buildEnv = {
44 ...process.env,
45 // Bake the session API key — used by the frontend for both agent-server
46 // and automation auth via the `X-Session-API-Key` header.
47 VITE_SESSION_API_KEY: config.sessionApiKey,
48 // Bake a description of the runtime services in this dev stack so the
49 // frontend can populate the agent's <RUNTIME_SERVICES> system-prompt
50 // block when creating a conversation.
51 VITE_RUNTIME_SERVICES_INFO: JSON.stringify(
52 buildAutomationRuntimeServicesInfo(config),
53 ),
54 // Intentionally do NOT set VITE_BACKEND_BASE_URL: leaving it unset makes
55 // the runtime fall back to window.location.origin, which keeps the build
56 // portable across localhost, LAN hosts, and tunnels such as ngrok.
57 };
58 if (config.viteWorkingDir) {
59 buildEnv.VITE_WORKING_DIR = config.viteWorkingDir;
60 }
61
62 const result = spawnSync(cmd.command, cmd.args, {
63 cwd: config.canvasPath,
64 stdio: "inherit",
65 env: buildEnv,
66 });
67
68 if (result.status !== 0) {
69 logError(`Build failed with exit code ${result.status ?? "null"}`);
70 process.exit(result.status ?? 1);
71 }
72

Callers 1

mainFunction · 0.90

Calls 6

logErrorFunction · 0.90
logStepFunction · 0.90
logServiceFunction · 0.90
buildNpmScriptCommandFunction · 0.90
logSuccessFunction · 0.90

Tested by

no test coverage detected