#!/usr/bin/env node /** * Checks a folder of exports for duplicates BEFORE it reaches the panel. * * Runs the panel's own loader, so the classification cannot drift apart from * what the panel does: whatever the panel would report, this prints. Read-only - * it never writes, moves or deletes anything. * * node scripts/audit-duplicates.js [путь-к-каталогу] */ import path from 'node:path'; import { loadAll } from '../server/load.js'; const DUPLICATE_CODES = new Set([ 'duplicate-columns', 'duplicate-rows', 'conflicting-rows', 'merged-company-rows', 'duplicate-files', ]); const dir = path.resolve(process.argv[2] ?? process.env.DATA_DIR ?? 'data'); const data = await loadAll(dir); const warnings = data.meta.warnings.filter((item) => DUPLICATE_CODES.has(item.code)); const rejects = data.meta.rejects ?? []; console.log(`Каталог: ${dir}`); console.log(`Прочитано: ${new Date(data.meta.loadedAt).toLocaleString('ru-RU')}\n`); const width = Math.max(...data.meta.files.map((item) => item.file.length), 10); console.log(` ${'Файл'.padEnd(width)} прочитано принято отброшено`); for (const file of data.meta.files) { const mark = file.exists ? '' : ' (файла нет)'; console.log(` ${file.file.padEnd(width)} ${String(file.rawRows ?? 0).padStart(9)}` + ` ${String(file.rows ?? 0).padStart(7)} ${String(file.rejected ?? 0).padStart(9)}${mark}`); } if (warnings.length === 0) { console.log('\nДублей не найдено: повторов имён колонок нет, повторов строк нет.'); } else { console.log(`\nНайдено (${warnings.length}):`); for (const item of warnings) console.log(` ${item.file}: ${item.message}`); } if (rejects.length > 0) { console.log(`\nОтброшенные строки (${rejects.length}), первые пять:`); for (const item of rejects.slice(0, 5)) { console.log(` ${item.file}: ${item.reason}`); console.log(` ${JSON.stringify(item.raw)}`); } } // Отдельно: строки, потерянные не из-за дублей, - чтобы аудит не выглядел // «всё хорошо», когда файл вообще не разобрался. const other = data.meta.warnings.filter((item) => !DUPLICATE_CODES.has(item.code)); if (other.length > 0) { console.log(`\nПрочие замечания к качеству данных (${other.length}):`); for (const item of other) console.log(` ${item.file}: ${item.message}`); }