#!/usr/bin/env node "use strict"; const { execFileSync } = require("child_process"); const path = require("path"); const { readAreaConfig } = require("./lib/area-config"); const { parseArgs } = require("./compile-native-roads"); const { startWorkbench } = require("../packages/road-compiler/workbench/server"); const repoRoot = path.resolve(__dirname, ".."); const args = parseArgs(process.argv.slice(2)); const configPath = path.resolve(args.config || path.join(repoRoot, "config", "areas", "nantaizi-lake-innovation-valley.json")); const area = readAreaConfig(configPath, { repoRoot }); const port = Number(args.port || 8787); if (args.noCompile !== "true") compileFresh(); startWorkbench({ area, configPath, repoRoot, readAreaConfig, port, debug: args.debug === "true", junctionReference: args.junctionReference ? path.resolve(args.junctionReference) : null, compileFresh, }); function compileFresh() { try { return execFileSync(process.execPath, [path.join(repoRoot, "scripts", "compile-native-roads.js"), "--config", configPath], { cwd: repoRoot, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }); } catch (error) { throw new Error(`Native road compilation failed: ${String(error.stderr || error.stdout || error.message).trim()}`); } }