53 lines
2.4 KiB
JavaScript
53 lines
2.4 KiB
JavaScript
import { readFile, mkdir, writeFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { buildOriginNativeMaterialProvenance } from "./lib/origin-native-material-provenance.mjs";
|
|
|
|
function parseArgs(argv) {
|
|
const args = {};
|
|
for (let index = 0; index < argv.length; index += 1) {
|
|
const name = argv[index];
|
|
if (!name.startsWith("--")) throw new Error(`Unexpected argument: ${name}`);
|
|
const value = argv[++index];
|
|
if (!value || value.startsWith("--")) throw new Error(`Missing value for ${name}.`);
|
|
args[name.slice(2)] = value;
|
|
}
|
|
for (const name of ["metadata", "assembly", "semantics", "output-dir"]) {
|
|
if (!args[name]) throw new Error(`Missing --${name}.`);
|
|
}
|
|
return args;
|
|
}
|
|
|
|
async function readJson(file) {
|
|
return JSON.parse(await readFile(file, "utf8"));
|
|
}
|
|
|
|
const args = parseArgs(process.argv.slice(2));
|
|
const [metadata, assembly, semantics] = await Promise.all([
|
|
readJson(args.metadata),
|
|
readJson(args.assembly),
|
|
readJson(args.semantics),
|
|
]);
|
|
const conversionReports = new Map();
|
|
for (const override of assembly.stagedOverrides ?? []) {
|
|
const visualPath = path.resolve(process.cwd(), override.file.replaceAll("\\", path.sep));
|
|
const conversionPath = path.join(path.dirname(visualPath), "conversion-report.json");
|
|
const report = await readJson(conversionPath);
|
|
conversionReports.set(override.resource.replaceAll("/", "\\").toLowerCase(), report);
|
|
}
|
|
const output = buildOriginNativeMaterialProvenance({ metadata, assembly, semantics, conversionReports });
|
|
const outputDirectory = path.resolve(args["output-dir"]);
|
|
await mkdir(outputDirectory, { recursive: true });
|
|
await Promise.all([
|
|
writeFile(path.join(outputDirectory, "import-metadata.json"), `${JSON.stringify(output.metadata, null, 2)}\n`),
|
|
writeFile(path.join(outputDirectory, "native-material-alpha-report.json"), `${JSON.stringify(output.alphaReport, null, 2)}\n`),
|
|
writeFile(path.join(outputDirectory, "native-material-semantics-report.json"), `${JSON.stringify(output.semanticsReport, null, 2)}\n`),
|
|
]);
|
|
console.log(JSON.stringify({
|
|
outputDirectory,
|
|
stagedOverrides: output.metadata.nativeMaterialAlpha.resources.length,
|
|
alphaMaterials: output.alphaReport.resources.reduce((count, row) => count + row.nativeAlpha.materials.length, 0),
|
|
additiveMaterials: output.semanticsReport.nativeAdditiveMaterials.length,
|
|
unlitMaterials: output.semanticsReport.khrMaterialsUnlit.length,
|
|
packageAssetsPreserved: output.metadata.assets?.length ?? 0,
|
|
}, null, 2));
|