2025-09-11 23:48:23 +00:00
|
|
|
import fs from "node:fs";
|
|
|
|
|
import { inspect, parseArgs } from "node:util";
|
|
|
|
|
import { parseMissionScript } from "@/src/mission";
|
2025-12-01 08:17:27 +00:00
|
|
|
import { getLocalFilePath, getMissionList } from "@/src/manifest";
|
2025-09-11 23:48:23 +00:00
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
|
const { values, positionals } = parseArgs({
|
|
|
|
|
allowPositionals: true,
|
|
|
|
|
options: {
|
|
|
|
|
name: {
|
|
|
|
|
type: "string",
|
|
|
|
|
short: "n",
|
|
|
|
|
},
|
|
|
|
|
list: {
|
|
|
|
|
type: "boolean",
|
|
|
|
|
short: "l",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (values.list) {
|
|
|
|
|
if (values.name || positionals[0]) {
|
|
|
|
|
console.error("Cannot specify --list (-l) with other options.");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2025-12-01 08:17:27 +00:00
|
|
|
console.log(getMissionList().join("\n"));
|
2025-09-11 23:48:23 +00:00
|
|
|
return;
|
|
|
|
|
} else if (
|
|
|
|
|
(values.name && positionals[0]) ||
|
|
|
|
|
(!values.name && !positionals[0])
|
|
|
|
|
) {
|
|
|
|
|
console.error(
|
2025-11-29 17:08:20 +00:00
|
|
|
"Must specify exactly one of --name (-n) or a positional filename.",
|
2025-09-11 23:48:23 +00:00
|
|
|
);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let missionFile = positionals[0];
|
|
|
|
|
if (values.name) {
|
2025-12-01 08:17:27 +00:00
|
|
|
const resourcePath = `missions/${values.name.toLowerCase()}.mis`;
|
|
|
|
|
missionFile = getLocalFilePath(resourcePath);
|
2025-09-11 23:48:23 +00:00
|
|
|
}
|
|
|
|
|
const missionScript = fs.readFileSync(missionFile, "utf8");
|
|
|
|
|
console.log(
|
|
|
|
|
inspect(parseMissionScript(missionScript), {
|
2025-11-16 19:36:10 +00:00
|
|
|
colors: true,
|
2025-09-11 23:48:23 +00:00
|
|
|
depth: Infinity,
|
2025-11-29 17:08:20 +00:00
|
|
|
}),
|
2025-09-11 23:48:23 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const code = await run();
|
|
|
|
|
process.exit(code ?? 0);
|