Some checks failed
Release production image / production-image (push) Has been cancelled
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import process from 'node:process';
|
|
|
|
const root = process.cwd();
|
|
const markdown = [];
|
|
const walk = (directory) => {
|
|
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
if (entry.name === '.git' || entry.name === 'node_modules') continue;
|
|
const absolute = path.join(directory, entry.name);
|
|
if (entry.isDirectory()) walk(absolute);
|
|
else if (entry.name.endsWith('.md')) markdown.push(absolute);
|
|
}
|
|
};
|
|
walk(root);
|
|
const failures = [];
|
|
for (const file of markdown) {
|
|
const text = fs.readFileSync(file, 'utf8');
|
|
for (const match of text.matchAll(/\[[^\]]*\]\(([^)]+)\)/g)) {
|
|
const raw = match[1].trim().replace(/^<|>$/g, '');
|
|
const target = raw.split('#')[0];
|
|
if (!target || /^[a-z][a-z0-9+.-]*:/i.test(target)) continue;
|
|
const resolved = path.resolve(path.dirname(file), decodeURIComponent(target));
|
|
if (!fs.existsSync(resolved)) failures.push(`${path.relative(root, file)}: missing link target ${target}`);
|
|
}
|
|
}
|
|
if (failures.length) {
|
|
console.error(failures.join('\n'));
|
|
process.exit(1);
|
|
}
|
|
console.log(`Documentation links passed: ${markdown.length} Markdown files checked.`);
|