(config, args = {})
| 22 | } |
| 23 | |
| 24 | export function buildFrontend(config, args = {}) { |
| 25 | const buildDir = join(config.canvasPath, "build"); |
| 26 | |
| 27 | if (args.skipBuild) { |
| 28 | if (!existsSync(buildDir)) { |
| 29 | logError( |
| 30 | "--skip-build was passed but build/ does not exist. Run without --skip-build first.", |
| 31 | ); |
| 32 | process.exit(1); |
| 33 | } |
| 34 | logStep("build", "Skipping frontend build (--skip-build)"); |
| 35 | logService("build", `Reusing existing build/ at ${buildDir}`, c.dim); |
| 36 | logService( |
| 37 | "build", |
| 38 | "Source edits will NOT appear until you run without --skip-build (or `npm run build`).", |
| 39 | c.yellow, |
| 40 | ); |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | logStep("build", "Building frontend (npm run build:app)..."); |
| 45 | logService( |
| 46 | "build", |
| 47 | "This typically takes 30-60s; cached as build/ for --skip-build reuse", |
| 48 | c.dim, |
| 49 | ); |
| 50 | |
| 51 | const cmd = buildNpmScriptCommand("build:app"); |
| 52 | // The static server injects runtime configuration after applying the |
| 53 | // bind-host policy, so the reusable build itself must remain key-free. |
| 54 | const buildEnv = buildFrontendEnv(config); |
| 55 | |
| 56 | const result = spawnSync(cmd.command, cmd.args, { |
| 57 | cwd: config.canvasPath, |
| 58 | stdio: "inherit", |
| 59 | env: buildEnv, |
| 60 | }); |
| 61 | |
| 62 | if (result.status !== 0) { |
| 63 | logError(`Build failed with exit code ${result.status ?? "null"}`); |
| 64 | process.exit(result.status ?? 1); |
| 65 | } |
| 66 | |
| 67 | if (!existsSync(join(buildDir, "index.html"))) { |
| 68 | logError( |
| 69 | `Build completed but ${join(buildDir, "index.html")} is missing. ` + |
| 70 | "Did react-router build write somewhere unexpected?", |
| 71 | ); |
| 72 | process.exit(1); |
| 73 | } |
| 74 | |
| 75 | logSuccess("Build complete"); |
| 76 | } |
no test coverage detected