Files
healer-man/scripts/manastorm-import/forensics-cli.mjs
T
2026-08-14 15:56:39 -04:00

71 lines
3.0 KiB
JavaScript

import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import {
generateManastormForensics,
renderManastormForensicsMarkdown,
} from "./forensics.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 === "--legacy-dbc-root") options.legacyDbcRoot = value;
else if (argument === "--aio-cache") options.aioCachePath = value;
else if (argument === "--audio-root") options.audioRoot = value;
else if (argument === "--output") options.outputPath = value;
else if (argument === "--affix-output") options.affixOutputPath = value;
else if (argument === "--markdown-output") options.markdownOutputPath = 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, "..", "HealerMan-Storage", "pipeline-work", "manastorm", "client-forensics.json"),
);
const markdownOutputPath = path.resolve(
options.markdownOutputPath
?? path.join(projectRoot, "..", "HealerMan-Storage", "pipeline-work", "manastorm", "CLIENT_FORENSICS.md"),
);
const affixOutputPath = path.resolve(
options.affixOutputPath
?? path.join(projectRoot, "src", "game", "generated", "manastormAffixes.json"),
);
const report = generateManastormForensics(options);
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
fs.writeFileSync(outputPath, `${JSON.stringify(report, null, 2)}\n`);
fs.mkdirSync(path.dirname(markdownOutputPath), { recursive: true });
fs.writeFileSync(markdownOutputPath, `${renderManastormForensicsMarkdown(report)}\n`);
fs.mkdirSync(path.dirname(affixOutputPath), { recursive: true });
fs.writeFileSync(affixOutputPath, `${JSON.stringify({
schemaVersion: 1,
sourceReportId: report.reportId,
spellDbcSha256: report.sources.spellDbc.sha256,
affixes: report.messages.affixDefinitions,
}, null, 2)}\n`);
console.log(
[
`Generated ${path.relative(projectRoot, outputPath).replaceAll("\\", "/")}`,
`generated ${path.relative(projectRoot, markdownOutputPath).replaceAll("\\", "/")}`,
`generated ${path.relative(projectRoot, affixOutputPath).replaceAll("\\", "/")}`,
`${report.messages.counts.uniqueAffixes} unique affixes`,
`${report.messages.counts.equipmentUnlocks} equipment unlock messages`,
`${report.aioContract.handlers.length} AIO handlers`,
`${report.audioEvidence.portalCueCount} portal audio cues`,
].join("; "),
);