import { mkdirSync, writeFileSync } from 'node:fs'; import { dirname, resolve } from 'node:path'; import { buildLegacyParityReport, formatLegacyParityReportMarkdown, } from './legacy-parity-report-lib'; type Args = { legacyPath: string; enterprisePath: string; outputPath: string; strictScope: boolean; }; const parseArgs = (argv: ReadonlyArray): Args => { let legacyPath = ''; let enterprisePath = ''; let outputPath = '.audit-reports/legacy-parity-report.md'; let strictScope = true; for (const arg of argv) { if (arg.startsWith('--legacy=')) { legacyPath = arg.slice('--legacy='.length).trim(); continue; } if (arg.startsWith('--enterprise=')) { enterprisePath = arg.slice('--enterprise='.length).trim(); continue; } if (arg.startsWith('--out=')) { outputPath = arg.slice('--out='.length).trim(); continue; } if (arg === '--allow-scope-mismatch') { strictScope = false; } } if (legacyPath.length === 0 || enterprisePath.length === 0) { throw new Error( 'Usage: node --import tsx scripts/build-legacy-parity-report.ts --legacy= --enterprise= [--out=] [--allow-scope-mismatch]' ); } return { legacyPath, enterprisePath, outputPath, strictScope, }; }; const main = (): void => { const args = parseArgs(process.argv.slice(2)); const report = buildLegacyParityReport({ legacyPath: args.legacyPath, enterprisePath: args.enterprisePath, strictScope: args.strictScope, }); const markdown = formatLegacyParityReportMarkdown(report); const outputPath = resolve(args.outputPath); mkdirSync(dirname(outputPath), { recursive: true }); writeFileSync(outputPath, `${markdown}\n`, 'utf8'); process.stdout.write( `[pumuki][legacy-parity] dominance=${report.dominance} compared_rules=${report.totals.comparedRules} output=${outputPath}\n` ); if (report.dominance === 'FAIL') { process.exitCode = 1; } }; try { main(); } catch (error) { const message = error instanceof Error ? error.message : 'Unknown error'; process.stderr.write(`[pumuki][legacy-parity] error: ${message}\n`); process.exitCode = 1; }