-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathcheckNav.mjs
More file actions
54 lines (41 loc) · 1.5 KB
/
checkNav.mjs
File metadata and controls
54 lines (41 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const navPath = '../docs/nav.mjs';
const mdListPath = process.argv[2];
if (!mdListPath) {
console.error('Usage: node checkNav.mjs <md-list-file>');
process.exit(1);
}
const navFile = path.resolve(__dirname, navPath);
const nav = await import(pathToFileURL(navFile).href).then(mod => mod.default);
const extractPathsFromNav = (items) =>
items.filter(item => item.type === 'page').map(page => page.path);
const navPaths = extractPathsFromNav(nav.items);
const navPathSet = new Set(navPaths);
const expectedMdPaths = fs.readFileSync(path.resolve(__dirname, mdListPath), 'utf8')
.split('\n')
.map(line => line.trim())
.filter(Boolean);
const expectedPathSet = new Set(expectedMdPaths);
const missingInNav = expectedMdPaths.filter(p => !navPathSet.has(p));
const extraInNav = navPaths.filter(p => !expectedPathSet.has(p));
let failed = false;
if (missingInNav.length > 0) {
console.error('❌ These docs are missing from nav:');
missingInNav.forEach(p => console.error(`- ${p}`));
failed = true;
}
if (extraInNav.length > 0) {
console.error('❌ These docs are listed in nav but not found under docs/:');
extraInNav.forEach(p => console.error(`- ${p}`));
failed = true;
}
if (!failed) {
console.log('✅ nav list matches filesystem.');
} else {
process.exit(1);
}