#!/usr/bin/env node /** Compara duas execuções de scripts/seo-audit.mjs: node scripts/seo-compare.mjs antes.json depois.json */ import { readFileSync } from "node:fs"; const [beforePath, afterPath] = process.argv.slice(2); if (!beforePath || !afterPath) { console.error("uso: node scripts/seo-compare.mjs antes.json depois.json"); process.exit(1); } const before = JSON.parse(readFileSync(beforePath, "utf8")); const after = JSON.parse(readFileSync(afterPath, "utf8")); const key = (c) => `${c.scope}::${c.id}`; const prev = new Map(before.checks.map((c) => [key(c), c])); const next = new Map(after.checks.map((c) => [key(c), c])); console.log( `\nAntes: ${before.base} (${before.urls} URLs) Depois: ${after.base} (${after.urls} URLs)\n`, ); console.log("grupo antes depois"); for (const g of new Set([ ...Object.keys(before.groups), ...Object.keys(after.groups), ])) { const a = before.groups[g] ?? { ok: 0, total: 0 }; const b = after.groups[g] ?? { ok: 0, total: 0 }; console.log( `${g.padEnd(20)} ${`${a.ok}/${a.total}`.padEnd(9)} ${b.ok}/${b.total}`, ); } const fixed = []; const regressed = []; for (const [k, c] of next) { const p = prev.get(k); if (p && !p.ok && c.ok) fixed.push(c); if (p?.ok && !c.ok) regressed.push(c); if (!p && !c.ok) regressed.push({ ...c, detail: `novo e falhando: ${c.detail}` }); } console.log(`\nCorrigidos (${fixed.length}):`); for (const c of fixed) console.log(` + ${c.scope} ${c.id}`); console.log(`\nPiorou (${regressed.length}):`); for (const c of regressed) console.log(` - ${c.scope} ${c.id} ${c.detail ?? ""}`); process.exit(regressed.length ? 2 : 0);