26 lines
1 KiB
JavaScript
26 lines
1 KiB
JavaScript
import { resolve } from 'node:path';
|
|
import { pathToFileURL } from 'node:url';
|
|
import { checkRenderedOutput } from './lib/rendered-output.mjs';
|
|
|
|
async function main() {
|
|
const distRoot = process.argv[2] ?? 'dist';
|
|
const result = await checkRenderedOutput({ distRoot });
|
|
const issues = [
|
|
...result.headingIssues.map(({ file, h1Count }) => `${file} contains ${h1Count} H1 headings; expected exactly 1`),
|
|
...result.unpublishedPaths.map((path) => `unpublished to-be-studied path reached built output: ${path}`),
|
|
];
|
|
|
|
if (issues.length > 0) {
|
|
throw new Error(`Rendered-output check failed with ${issues.length} issue(s):\n${issues.map((issue) => `- ${issue}`).join('\n')}`);
|
|
}
|
|
|
|
console.log(`Rendered-output check passed: ${result.htmlFilesChecked} published pages, exactly one H1 each, no to-be-studied paths.`);
|
|
}
|
|
|
|
const invokedPath = process.argv[1] ? pathToFileURL(resolve(process.argv[1])).href : '';
|
|
if (invokedPath === import.meta.url) {
|
|
main().catch((error) => {
|
|
console.error(error.message);
|
|
process.exitCode = 1;
|
|
});
|
|
}
|