feat: add initial version of xd2fig tool
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import fs from 'node:fs';
|
||||
import { readCanvas, prettyPrintSchema } from '../src/figfile.js';
|
||||
const [,, canvasPath, outDir] = process.argv;
|
||||
const r = readCanvas(new Uint8Array(fs.readFileSync(canvasPath)));
|
||||
console.log('version', r.version, 'codecs', r.codecs, 'extra chunks', r.extraChunks.length);
|
||||
fs.mkdirSync(outDir, { recursive: true });
|
||||
fs.writeFileSync(`${outDir}/schema.kiwi.txt`, prettyPrintSchema(r.schema));
|
||||
const replacer = (k, v) => v instanceof Uint8Array ? `<bytes ${v.length}>` : v;
|
||||
fs.writeFileSync(`${outDir}/message.json`, JSON.stringify(r.message, replacer, 1));
|
||||
const m = r.message;
|
||||
console.log('message keys', Object.keys(m), 'type', m.type, 'nodes', m.nodeChanges?.length, 'blobs', m.blobs?.length);
|
||||
const types = {};
|
||||
for (const n of m.nodeChanges) types[n.type] = (types[n.type] || 0) + 1;
|
||||
console.log(types);
|
||||
Reference in New Issue
Block a user