import { spawn } from "node:child_process"; import path from "node:path"; import { optionValue, pipelineDirectory, projectRoot, readJson, } from "./lib/recipe.mjs"; const argv = process.argv.slice(2); const sourceRoot = path.resolve(process.env.RUNEWAKER_ROOT ?? path.join(projectRoot, "../rom-pvt-server-backups/Runewaker")); const config = await readJson(path.join(sourceRoot, "Tools", "dungeon_config.json")); const dungeons = config.dungeons ?? []; const zones = dungeons.map((entry) => Number(entry.base_zone)); const zoneObjects = dungeons.map((entry) => Number(entry.zone_obj_template)); const server = optionValue(argv, "--server", process.env.RUNEWAKER_SQL_SERVER ?? ".\\HEALERMAN_RW"); const output = path.join(projectRoot, "runewaker-export-work", "all-instances-forensic-raw.json"); const suffix = "all_" + new Date().toISOString().replace(/[^0-9]/g, "").slice(0, 14); const script = path.join(pipelineDirectory, "refresh-all-instances.ps1"); function run(executable, args, label) { return new Promise((resolve, reject) => { console.log("[runewaker-forensics] " + label); const child = spawn(executable, args, { cwd: projectRoot, stdio: "inherit", windowsHide: true }); child.once("error", reject); child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(label + " exited with " + code + "."))); }); } await run("powershell.exe", [ "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", script, "-ServerInstance", server, "-GlobalBackup", path.join(projectRoot, "../rom-pvt-server-backups/OneForAll/SQL/databases/ROM_Global.bak"), "-ObjectBackup", path.join(projectRoot, "../rom-pvt-server-backups/OneForAll/SQL/databases/ObjectEdit.bak"), "-ZoneIds", zones.join(","), "-ZoneObjectTemplateIds", zoneObjects.join(","), "-DatabaseSuffix", suffix, "-OutputFile", output, ], "restore read-only temporary databases, export all configured zones, and drop the temporary databases"); await run(process.execPath, [path.join(pipelineDirectory, "prepare-all-instances.mjs")], "regenerate portable recipes and snapshots"); console.log("[runewaker-forensics] refresh complete; stop the extraction-only SQL service before building or playing.");