ci: verify anchor aliases are injected into dist
All checks were successful
CI / build-and-anchors (push) Successful in 54s

This commit is contained in:
2026-01-23 09:47:25 +01:00
parent fee143e86f
commit 800226a404

View File

@@ -0,0 +1,63 @@
import fs from "node:fs";
import path from "node:path";
const CWD = process.cwd();
const ALIASES_PATH = path.join(CWD, "src", "anchors", "anchor-aliases.json");
const DIST_DIR = path.join(CWD, "dist");
if (!fs.existsSync(ALIASES_PATH)) {
console.log(" Pas d'aliases => skip verify.");
process.exit(0);
}
if (!fs.existsSync(DIST_DIR)) {
console.error("❌ dist/ introuvable. Lance d'abord le build.");
process.exit(1);
}
const aliases = JSON.parse(fs.readFileSync(ALIASES_PATH, "utf8"));
let checked = 0;
let failed = 0;
for (const [route, mapping] of Object.entries(aliases)) {
const htmlPath = path.join(DIST_DIR, route.replace(/^\//, ""), "index.html");
if (!fs.existsSync(htmlPath)) {
console.error(`❌ HTML introuvable pour route=${route} => ${htmlPath}`);
failed++;
continue;
}
const html = fs.readFileSync(htmlPath, "utf8");
for (const [oldId, newId] of Object.entries(mapping)) {
checked++;
const oldNeedle = `id="${oldId}"`;
const newNeedle = `id="${newId}"`;
const oldPos = html.indexOf(oldNeedle);
const newPos = html.indexOf(newNeedle);
if (newPos === -1) {
console.error(`❌ newId absent: route=${route} newId=${newId}`);
failed++;
continue;
}
if (oldPos === -1) {
console.error(`❌ alias oldId non injecté: route=${route} oldId=${oldId} (newId=${newId})`);
failed++;
continue;
}
if (oldPos > newPos) {
console.error(`❌ alias placé APRÈS newId: route=${route} oldId=${oldId} newId=${newId}`);
failed++;
continue;
}
}
}
if (failed) {
console.error(`❌ verify-anchor-aliases-in-dist: failed=${failed} checked=${checked}`);
process.exit(1);
}
console.log(`✅ verify-anchor-aliases-in-dist: checked=${checked} (all good)`);