-
Nemanja Glumac authored
* Expand the glob to include TS(X) files * Use console error * Re-order imports * Print the missing files in red * Fix glob pattern * Add script to pre-commit hooks * Remove the check from CI
Nemanja Glumac authored* Expand the glob to include TS(X) files * Use console error * Re-order imports * Print the missing files in red * Fix glob pattern * Add script to pre-commit hooks * Remove the check from CI
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
verify-doc-links 1.04 KiB
#!/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();
}