Incognito-Wiki/scripts/check-internal-links.mjs

18 lines
715 B
JavaScript

import { resolve } from 'node:path';
import { checkInternalLinks } from './lib/internal-links.mjs';
const distRoot = resolve(process.argv[2] || 'dist');
const base = process.env.BASE || '/';
const result = await checkInternalLinks({ distRoot, base });
console.log(`Checked ${result.linksChecked} internal links across ${result.filesScanned} built HTML files.`);
for (const { source, href, resolvedPath } of result.broken) {
console.error(`Broken internal link in ${source}: ${href} -> ${resolvedPath}`);
}
if (result.broken.length > 0) {
console.error(`Internal-link check failed: ${result.broken.length} broken link(s).`);
process.exitCode = 1;
} else {
console.log('Found 0 broken internal links.');
}