scripts/parse-dwg.mjs parses a DWG in Node with the same acadrust wasm and Korean-text fixup as the viewer, prints an entity-type summary and can write the full parseResult JSON. Needs Node >= 22.18 (type stripping for fixDwgKoreanText.ts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.7 KiB
JavaScript
45 lines
1.7 KiB
JavaScript
#!/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 <file.dwg> # print summary
|
|
* node scripts/parse-dwg.mjs <file.dwg> 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 <file.dwg> [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}`);
|
|
}
|