Files
2026-08-14 15:56:39 -04:00

76 lines
3.1 KiB
JavaScript

import path from "node:path";
import { fileURLToPath } from "node:url";
import {
generateManastormCatalog,
writeManastormCatalog,
writeManastormRuntimeCatalog,
writeManastormCatalogSummary,
} from "./importer.mjs";
const scriptDirectory = path.dirname(fileURLToPath(import.meta.url));
const projectRoot = path.resolve(scriptDirectory, "..", "..");
function parseArguments(arguments_) {
const options = { projectRoot };
for (let index = 0; index < arguments_.length; index += 1) {
const argument = arguments_[index];
const value = arguments_[index + 1];
if (!argument.startsWith("--") || !value || value.startsWith("--")) {
throw new Error(`Expected --option value, received ${JSON.stringify(argument)}.`);
}
index += 1;
if (argument === "--realm-dbc-root") options.realmDbcRoot = value;
else if (argument === "--map") options.mapPath = value;
else if (argument === "--dungeon-encounters") options.dungeonEncounterPath = value;
else if (argument === "--dungeon-encounter-extras") options.dungeonEncounterExtraPath = value;
else if (argument === "--spell") options.spellPath = value;
else if (argument === "--spell-icons") options.spellIconPath = value;
else if (argument === "--icon-directory") options.iconDirectory = value;
else if (argument === "--output") options.outputPath = value;
else if (argument === "--runtime-output") options.runtimeOutputPath = value;
else if (argument === "--summary-output") options.summaryOutputPath = value;
else throw new Error(`Unknown option ${argument}.`);
}
return options;
}
const options = parseArguments(process.argv.slice(2));
const outputPath = path.resolve(
options.outputPath
?? path.join(projectRoot, "src", "game", "generated", "manastormCatalog.json"),
);
const catalog = generateManastormCatalog(options);
const byteLength = writeManastormCatalog(catalog, outputPath);
const runtimeOutputPath = options.runtimeOutputPath
? path.resolve(options.runtimeOutputPath)
: options.outputPath
? null
: path.join(projectRoot, "src", "game", "generated", "manastormRuntimeCatalog.json");
const runtimeByteLength = runtimeOutputPath
? writeManastormRuntimeCatalog(catalog, runtimeOutputPath)
: 0;
const summaryOutputPath = options.summaryOutputPath
? path.resolve(options.summaryOutputPath)
: options.outputPath
? null
: path.join(projectRoot, "src", "game", "manastormCatalogSummary.ts");
if (summaryOutputPath) writeManastormCatalogSummary(catalog, summaryOutputPath);
console.log(
[
`Generated ${path.relative(projectRoot, outputPath).replaceAll("\\", "/")}`,
...(summaryOutputPath
? [`summary ${path.relative(projectRoot, summaryOutputPath).replaceAll("\\", "/")}`]
: []),
...(runtimeOutputPath
? [`runtime ${path.relative(projectRoot, runtimeOutputPath).replaceAll("\\", "/")} (${runtimeByteLength} bytes)`]
: []),
`${catalog.counts.sourceRows} source rows`,
`${catalog.counts.maps} maps`,
`${catalog.counts.encounters} encounters`,
`${catalog.counts.messages} messages`,
`${catalog.counts.validationIssues} validation warning(s)`,
`${byteLength} bytes`,
].join("; "),
);