#!/usr/bin/env node import fs from 'node:fs/promises' import path from 'node:path' import { fileURLToPath } from 'node:url' import yaml from 'js-yaml' const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) const REPO_ROOT = path.resolve(__dirname, '..') const SOURCE = path.join(REPO_ROOT, 'public/data/carte-o-source.yaml') const OUTPUT = path.join(REPO_ROOT, 'public/data/carte-o.json') // radius par niveau + nature (V1.2-N palette minimaliste) function getRadius(niveau, nature) { if (niveau === 0) return 30 if (nature === 'projet') return 18 if (niveau === 1) return 16 return 12 } // compat backward : nature -> family function getFamily(nature) { return nature === 'projet' ? 'ressource' : 'concept' } // V1.2-N : noeud central fusionne -> toutes les thematiques sont rattachees au centre // (les anciens groupes NCS_THEMATIQUES / MDCS_THEMATIQUES sont supprimes avec leurs sous-noeuds) async function main() { const raw = await fs.readFile(SOURCE, 'utf-8') const data = yaml.load(raw) const nodes = [] const edges = [] const edgeSet = new Set() function addEdge(source, target) { const key = source < target ? `${source}|${target}` : `${target}|${source}` if (edgeSet.has(key)) return edgeSet.add(key) edges.push({ source, target }) } function addNode(obj) { nodes.push({ id: obj.id, label: obj.label, niveau: obj.niveau, nature: obj.nature, statut: obj.statut, resume: obj.resume || null, radius: getRadius(obj.niveau, obj.nature), family: getFamily(obj.nature), }) } const centreId = data.centre.id addNode(data.centre) // concepts_force vide en V1.2-N (fusionne dans le centre) for (const cf of (data.concepts_force || [])) { addNode(cf) addEdge(centreId, cf.id) } // toutes les thematiques rattachees directement au noeud central for (const th of data.thematiques) { addNode(th) addEdge(centreId, th.id) } for (const proj of data.projets) { addNode(proj) for (const thId of (proj.liens_thematiques || [])) { addEdge(proj.id, thId) } } await fs.mkdir(path.dirname(OUTPUT), { recursive: true }) await fs.writeFile( OUTPUT, JSON.stringify({ version: data.version, generatedAt: new Date().toISOString(), nodes, edges, }, null, 2), 'utf-8', ) console.log(`[carte-o] OK : ${nodes.length} nodes / ${edges.length} edges -> ${OUTPUT}`) } main().catch(err => { console.error('[carte-o] FAIL', err) process.exit(1) }) // V1 scrape vault - reactiver en V1.2 pour enrichissement automatique // Source : scripts/build-carte-o.js@be7fc09 (scrape AEP/Articles globby + gray-matter + wikilinks edges)