Open History to see the last commit
1// Regenerates lib/riv-schema.json from `rive schema`: the field type of every core property
2// key (how to skip it in a .riv) and which type keys are Components (counted as artboard
3// objects). Run: node scripts/gen-riv-schema.mjs
4import { execFileSync } from 'node:child_process';
5import { writeFileSync } from 'node:fs';
6
7const run = (...a) => JSON.parse(execFileSync('rive', ['schema', ...a, '--json'], { maxBuffer: 64 << 20 }).toString());
8const names = run('--list');
9const keys = {};
10const fieldTypes = new Set();
11const components = [];
12const typeKeys = {};
13for (const name of names) {
14 const t = run(name, '--all');
15 typeKeys[name] = t.typeKey;
16 if (name === 'Component' || t.extends?.includes('Component')) components.push(t.typeKey);
17 for (const p of t.properties) {
18 fieldTypes.add(p.type);
19 keys[p.key] = p.type;
20 }
21}
22console.log([...fieldTypes].sort().join(', '));
23writeFileSync(new URL('../lib/riv-schema.json', import.meta.url), JSON.stringify({ keys, components: components.sort((a, b) => a - b), typeKeys }) + '\n');
24console.log(`${names.length} types, ${Object.keys(keys).length} keys`);