scripts/porter-taxonomie-reseaux.mjs (rejouable, --verifier) recopie tels quels type_organisation, postures et taxonomie_source (= source) depuis data/taxonomie/organisations.json. classement(id, fiche, mapping) lit le champ de la fiche d'abord, le mapping en repli ; toMini passe la structure (les Org restent sur le mapping jusqu'à B4b-2). Le mapping reste comme trace (README). test-taxonomie : égalité 120 sur 120, classement identique fiche/mapping, repli, vocabulaire (44/44). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PWGVn2kurLPzxVc5F3mQJ5
64 lines
2.6 KiB
JavaScript
64 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* B4b-M3 : porte le type d'organisation et les postures de chaque structure dans
|
|
* `public/data/reseaux-bifurcation.json`, recopiés tels quels depuis
|
|
* `data/taxonomie/organisations.json` (clé `structure:<id>`) :
|
|
* type_organisation ← entree.type_organisation
|
|
* postures ← entree.postures
|
|
* taxonomie_source ← entree.source
|
|
* Rejouable : relancé, il réécrit les mêmes valeurs (aucun diff). Aucune valeur ne
|
|
* change, c'est un déplacement ; `scripts/test-taxonomie.mjs` le prouve (120 sur 120).
|
|
* Une structure sans entrée fait échouer le script (rien n'est écrit).
|
|
*
|
|
* Usage : node scripts/porter-taxonomie-reseaux.mjs (écrit)
|
|
* node scripts/porter-taxonomie-reseaux.mjs --verifier (n'écrit rien, code 1 si un écart)
|
|
*/
|
|
|
|
import { readFileSync, writeFileSync } from 'node:fs'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { dirname, join } from 'node:path'
|
|
|
|
const racine = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
const cheminReseaux = join(racine, 'public', 'data', 'reseaux-bifurcation.json')
|
|
const cheminMapping = join(racine, 'data', 'taxonomie', 'organisations.json')
|
|
const verifier = process.argv.includes('--verifier')
|
|
|
|
const brut = readFileSync(cheminReseaux, 'utf8')
|
|
const reseaux = JSON.parse(brut)
|
|
const mapping = JSON.parse(readFileSync(cheminMapping, 'utf8'))
|
|
|
|
const sansEntree = []
|
|
const ecarts = []
|
|
for (const s of reseaux.structures) {
|
|
const e = mapping.entrees[`structure:${s.id}`]
|
|
if (!e) {
|
|
sansEntree.push(s.id)
|
|
continue
|
|
}
|
|
const voulu = { type_organisation: e.type_organisation, postures: e.postures, taxonomie_source: e.source }
|
|
for (const [k, v] of Object.entries(voulu)) {
|
|
if (JSON.stringify(s[k]) !== JSON.stringify(v)) {
|
|
ecarts.push(`${s.id}.${k}`)
|
|
s[k] = structuredClone(v)
|
|
}
|
|
}
|
|
}
|
|
|
|
if (sansEntree.length) {
|
|
console.error(`Structures sans entrée dans le mapping (rien n'est écrit) : ${sansEntree.join(', ')}`)
|
|
process.exit(1)
|
|
}
|
|
|
|
if (verifier) {
|
|
console.log(ecarts.length ? `${ecarts.length} champs à porter : ${ecarts.slice(0, 10).join(', ')}${ecarts.length > 10 ? '…' : ''}` : `À jour : ${reseaux.structures.length} structures portent leur taxonomie.`)
|
|
process.exit(ecarts.length ? 1 : 0)
|
|
}
|
|
|
|
if (!ecarts.length) {
|
|
console.log(`Rien à écrire : ${reseaux.structures.length} structures déjà à jour.`)
|
|
} else {
|
|
const eol = brut.includes('\r\n') ? '\r\n' : '\n'
|
|
writeFileSync(cheminReseaux, JSON.stringify(reseaux, null, 2).replace(/\n/g, eol), 'utf8')
|
|
console.log(`${ecarts.length} champs portés sur ${reseaux.structures.length} structures.`)
|
|
}
|