forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify-doc-links
executable file
·47 lines (41 loc) · 1.04 KB
/
verify-doc-links
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
#!/usr/bin/env node
const fs = require("fs");
const glob = require("glob");
const chalk = require("chalk");
init();
function verifyDocumentationLinks(files) {
let missing = 0;
for (const file of files) {
const text = fs.readFileSync(file, "utf-8");
const regex = /docsUrl\((?:[\s\n]+)?"([^"]+)"/g;
let match;
while ((match = regex.exec(text))) {
const [_, page, anchor] = match;
const path = `./docs/${page}.md`;
if (fs.existsSync(path)) {
console.log(`Exists: ${path}`);
} else {
console.log(chalk.red(`Missing: ${path}`));
missing++;
}
}
}
if (missing > 0) {
process.exit(missing);
}
}
function verifyAllFiles() {
glob("./{enterprise/,}frontend/src/**/*.{js,jsx,ts,tsx}", (err, files) => {
if (err) {
console.error(err);
process.exit(1);
}
verifyDocumentationLinks(files);
});
}
function init() {
const stagedFiles = process.argv.slice(2);
return stagedFiles.length
? verifyDocumentationLinks(stagedFiles)
: verifyAllFiles();
}