diff --git a/scripts/parse-dwg.mjs b/scripts/parse-dwg.mjs new file mode 100644 index 0000000..c042e4a --- /dev/null +++ b/scripts/parse-dwg.mjs @@ -0,0 +1,44 @@ +#!/usr/bin/env node +/** + * Parse a DWG in Node — no browser, no Viewer2D. Same acadrust wasm and + * Korean-text fixup as src/viewer2d/dwgParser.ts. + * + * Usage: + * node scripts/parse-dwg.mjs # print summary + * node scripts/parse-dwg.mjs out.json # also write full parseResult + * + * Needs Node >= 22.18 (imports fixDwgKoreanText.ts via built-in type stripping). + */ +import { readFileSync, writeFileSync } from 'node:fs'; +import { initSync, parse_dwg_json } from '../src/viewer2d/acadrust-dwg/acadrust_dwg.js'; +import { fixDwgKoreanText } from '../src/viewer2d/fixDwgKoreanText.ts'; + +const [inPath, outPath] = process.argv.slice(2); +if (!inPath) { + console.error('usage: node scripts/parse-dwg.mjs [out.json]'); + process.exit(1); +} + +const wasmUrl = new URL('../src/viewer2d/acadrust-dwg/acadrust_dwg_bg.wasm', import.meta.url); +initSync({ module: readFileSync(wasmUrl) }); + +const t0 = performance.now(); +const result = fixDwgKoreanText(JSON.parse(parse_dwg_json(readFileSync(inPath)))); +const ms = performance.now() - t0; + +const entities = result.entities ?? []; +const byType = {}; +for (const e of entities) byType[e.type] = (byType[e.type] ?? 0) + 1; + +console.log(`file : ${inPath}`); +console.log(`version : ${result.version}`); +console.log(`parse : ${ms.toFixed(0)} ms`); +console.log(`entities : ${entities.length}`); +console.table(Object.entries(byType).sort((a, b) => b[1] - a[1]).map(([type, count]) => ({ type, count }))); +console.log(`tables : ${Object.keys(result.tables ?? {}).join(', ')}`); +if (result.stats) console.log('stats :', result.stats); + +if (outPath) { + writeFileSync(outPath, JSON.stringify(result, null, 2)); + console.log(`wrote : ${outPath}`); +}