Files
archicratie-edition/scripts/check-anchor-aliases.mjs
archicratia 60d88939b0
All checks were successful
CI / build-and-anchors (push) Successful in 1m25s
SMOKE / smoke (push) Successful in 11s
CI / build-and-anchors (pull_request) Successful in 1m20s
Seed from NAS prod snapshot 20260130-190531
2026-01-31 10:51:38 +00:00

64 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import fs from "node:fs";
import path from "node:path";
const ALIASES_PATH = path.join(process.cwd(), "src", "anchors", "anchor-aliases.json");
if (!fs.existsSync(ALIASES_PATH)) {
console.log(" Aucun fichier d'aliases (src/anchors/anchor-aliases.json). Skip.");
process.exit(0);
}
let data;
try {
data = JSON.parse(fs.readFileSync(ALIASES_PATH, "utf8"));
} catch (e) {
console.error("❌ JSON invalide dans src/anchors/anchor-aliases.json");
console.error(e?.message || e);
process.exit(1);
}
if (!data || typeof data !== "object" || Array.isArray(data)) {
console.error("❌ Le JSON doit être un objet { route: { oldId: newId } }");
process.exit(1);
}
let pages = 0;
let aliases = 0;
for (const [route, mapping] of Object.entries(data)) {
pages++;
if (typeof route !== "string" || !route.trim()) {
console.error("❌ Route invalide (clé): doit être une string non vide", { route });
process.exit(1);
}
// Optionnel mais sain : routes de type "/xxx/yyy/"
if (!route.startsWith("/") || !route.endsWith("/")) {
console.error("❌ Route invalide: doit commencer et finir par '/'", { route });
process.exit(1);
}
if (!mapping || typeof mapping !== "object" || Array.isArray(mapping)) {
console.error("❌ Mapping invalide: doit être un objet { oldId: newId }", { route });
process.exit(1);
}
for (const [oldId, newId] of Object.entries(mapping)) {
if (typeof oldId !== "string" || typeof newId !== "string") {
console.error("❌ oldId/newId doivent être des strings", { route, oldId, newId });
process.exit(1);
}
if (!oldId.trim() || !newId.trim()) {
console.error("❌ oldId/newId ne doivent pas être vides", { route, oldId, newId });
process.exit(1);
}
if (oldId === newId) {
console.error("❌ oldId doit différer de newId", { route, oldId });
process.exit(1);
}
aliases++;
}
}
console.log(`✅ anchor-aliases.json OK: pages=${pages} aliases=${aliases}`);