import { spawn } from "node:child_process"; import path from "node:path"; import { optionValue, pipelineDirectory, projectPath, projectRoot, readJson, resolveProject, } from "./lib/recipe.mjs"; const argv = process.argv.slice(2); const command = argv.shift() ?? "help"; function run(script, argumentsList = []) { return new Promise((resolve, reject) => { const child = spawn(process.execPath, [path.join(pipelineDirectory, script), ...argumentsList], { cwd: projectRoot, stdio: "inherit", windowsHide: true, }); child.once("error", reject); child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(script + " exited with " + code))); }); } function help() { console.log(`RuneWaker instance pipeline Usage: node scripts/runewaker-pipeline/cli.mjs discover node scripts/runewaker-pipeline/cli.mjs scaffold --id [--wdb file.wdb] node scripts/runewaker-pipeline/cli.mjs inspect-wdb --wdb node scripts/runewaker-pipeline/cli.mjs environment --recipe node scripts/runewaker-pipeline/cli.mjs refresh --recipe [--update-recipe] node scripts/runewaker-pipeline/cli.mjs actors --recipe node scripts/runewaker-pipeline/cli.mjs population --recipe node scripts/runewaker-pipeline/cli.mjs mechanics --recipe node scripts/runewaker-pipeline/cli.mjs offline --recipe node scripts/runewaker-pipeline/cli.mjs build --recipe node scripts/runewaker-pipeline/cli.mjs validate --recipe node scripts/runewaker-pipeline/cli.mjs prepare-all node scripts/runewaker-pipeline/cli.mjs build-all [--resume] [--only slug,...] node scripts/runewaker-pipeline/cli.mjs register-all node scripts/runewaker-pipeline/cli.mjs refresh-all [--server .\\HEALERMAN_RW] refresh and refresh-all are the only commands that connect to the temporary SQL extraction instance. offline, population, mechanics, validate, and the shipped game consume packaged files only.`); } async function populationRecipe() { const value = optionValue(argv, "--recipe"); if (!value) throw new Error(command + " requires --recipe ."); const file = resolveProject(value); return { file, recipe: await readJson(file) }; } if (command === "help" || command === "--help" || command === "-h") { help(); } else if (command === "discover") { await run("discover-instances.mjs", argv); } else if (command === "scaffold") { await run("scaffold-instance.mjs", argv); } else if (command === "inspect-wdb") { await run("inspect-wdb.mjs", argv); } else if (command === "environment") { await run("build-environment.mjs", argv); } else if (command === "refresh") { await run("refresh-population.mjs", argv); } else if (command === "actors") { await run("build-population.mjs", [...argv, "--actors-only"]); } else if (command === "population") { await run("build-population.mjs", argv); } else if (command === "mechanics") { await run("extract-mechanics.mjs", argv); } else if (command === "validate") { await run("validate-instance.mjs", argv); } else if (command === "prepare-all") { await run("prepare-all-instances.mjs", argv); } else if (command === "build-all") { await run("build-all-instances.mjs", argv); } else if (command === "register-all") { await run("generate-runtime-registry.mjs", argv); } else if (command === "refresh-all") { await run("refresh-all-instances.mjs", argv); } else if (command === "offline") { await run("build-population.mjs", argv); await run("extract-mechanics.mjs", argv); } else if (command === "build") { const { recipe } = await populationRecipe(); if (!recipe.files?.environmentRecipe) { throw new Error("Composite build requires files.environmentRecipe in " + projectPath(resolveProject(optionValue(argv, "--recipe"))) + "."); } await run("build-environment.mjs", ["--recipe", recipe.files.environmentRecipe]); await run("build-population.mjs", [...argv, "--actors"]); await run("extract-mechanics.mjs", argv); await run("validate-instance.mjs", argv); } else { help(); throw new Error("Unknown RuneWaker pipeline command: " + command); }