#!/usr/bin/env node // deriva-reguli.mjs: writes REGULI.json, the table of the rules the enrolled verifiers name, DERIVED from their code (reguli.mjs). // node deriva-reguli.mjs derives and writes REGULI.json; refuses (1) if a rule is unmapped, unmarked or gone // node deriva-reguli.mjs --verifica derives and compares with REGULI.json: LA ZI (0), DIFERIT (1), NEMASURAT (2: a source not here) import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { deriva } from './reguli.mjs'; const F = path.join(path.dirname(fileURLToPath(import.meta.url)), 'REGULI.json'); const { tabel, probleme, nemasurat } = await deriva(); for (const p of probleme) console.log('REFUSED: ' + p); for (const n of nemasurat) console.log('NOT MEASURED: ' + n); if (probleme.length) process.exitCode = 1; else if (nemasurat.length) process.exitCode = 2; else { const text = JSON.stringify(tabel, null, 1) + '\n'; const n = Object.values(tabel.verifiers).reduce((s, v) => s + v.rules.length, 0); if (process.argv.includes('--verifica')) { const egal = fs.existsSync(F) && fs.readFileSync(F, 'utf8').replace(/\r\n/g, '\n') === text; console.log(egal ? `LA ZI (${n} rules of ${Object.keys(tabel.verifiers).length} verifiers)` : 'DIFERIT: REGULI.json is not what the code derives now'); process.exitCode = egal ? 0 : 1; } else { fs.writeFileSync(F, text); console.log(`written REGULI.json: ${n} rules of ${Object.keys(tabel.verifiers).length} verifiers; not enrolled: ` + tabel.notEnrolled.map((x) => x.verifier + ' (' + x.refusalSites + ' refusal sites)').join(', ')); } }