// node gen-data.cjs: writes data.js (window.DOC) from the equine draft document, so every name and // count of the boards comes from document.json and none is typed by hand. const fs = require('fs') const path = require('path') const SRC = path.join(__dirname, '../../../supabase/seed/anatomical-sheets/equine/draft/document.json') const doc = JSON.parse(fs.readFileSync(SRC, 'utf8')) const node = (n) => ({ id: n.id, fr: n.name.fr, en: n.name.en, // absent = the core's default `Inherited` (crates/core/src/domain/sheet/schema.rs:186-188) status: n.review_status || 'inherited', refs: (n.reference_ids || []).length, children: (n.children || []).map(node), }) const out = { views: doc.views.map((v) => ({ id: v.id, fr: v.name.fr, parent: v.parent_view_id, vb: v.view_box })), categories: doc.categories.map((c) => ({ id: c.id, fr: c.name.fr, color: c.color })), annotations: doc.annotations.map((a) => ({ id: a.id, view: a.view_id, kind: a.kind, cat: a.category_id, lat: a.laterality, fr: a.name ? a.name.fr : null, zone: a.finding_zone_id, region: a.vertebral_region_code, g: a.geometry.type === 'circle' ? ['c', a.geometry.cx, a.geometry.cy, a.geometry.r] : ['p', a.geometry.points], })), zones: doc.finding_zones.map((z) => ({ id: z.id, fr: z.name.fr, families: z.categories.map((c) => ({ id: c.id, kind: c.kind, fr: c.name.fr, children: c.children.map(node) })), })), } const body = 'window.DOC = ' + JSON.stringify(out) + '\n' fs.writeFileSync(path.join(__dirname, 'data.js'), '// generated by gen-data.cjs from document.json\n' + body) console.log('annotations', out.annotations.length, 'zones', out.zones.length, 'bytes', body.length)