import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; import { pathToFileURL } from "node:url"; import ts from "../../web/node_modules/typescript/lib/typescript.js"; const [sourceArg, outputArg] = process.argv.slice(2); if (!sourceArg || !outputArg) throw new Error("usage: node generate-asset-catalog-v2.mjs SOURCE_CANONICAL OUTPUT_JSON"); const root = path.resolve(import.meta.dirname, "../.."); const sourcePath = path.join(root, "web/protocol/asset-catalog-v2.ts"); const temporaryPath = path.resolve(outputArg, "../asset-catalog-v2.generated.mjs"); const transpiled = ts.transpileModule(fs.readFileSync(sourcePath, "utf8"), { compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 }, fileName: sourcePath, reportDiagnostics: true, }); assert.deepEqual(transpiled.diagnostics, []); fs.mkdirSync(path.dirname(outputArg), { recursive: true }); fs.writeFileSync(temporaryPath, transpiled.outputText); try { const protocol = await import(`${pathToFileURL(temporaryPath)}?v=${Date.now()}`); const desktop = JSON.parse(fs.readFileSync(path.resolve(sourceArg), "utf8")); const manifest = await protocol.createAssetCatalogManifestV2FromDesktop(desktop, 1); fs.writeFileSync(path.resolve(outputArg), `${JSON.stringify(manifest, null, 2)}\n`); process.stdout.write(`asset-catalog-v2-generated catalogs=${manifest.catalogs.length} assets=${manifest.assets.length}\n`); } finally { fs.rmSync(temporaryPath, { force: true }); }