mirror of
https://github.com/cloudflare/cloudflare-docs.git
synced 2026-01-11 20:06:58 +00:00
* fix: many many typescript issues chore: bump dependencies * fix: assign-pr script when no codeowners found * fix: ExternalResources TS * fix: check all functions * chore: minor dep bumps * chore: fixups * chore: merge fixups
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { readFile } from "fs/promises";
|
|
|
|
async function main() {
|
|
const redirects = await readFile("public/_redirects", { encoding: "utf-8" });
|
|
|
|
let numInfiniteRedirects = 0;
|
|
let numUrlsWithFragment = 0;
|
|
let numDuplicateRedirects = 0;
|
|
let redirectSourceUrls: string[] = [];
|
|
|
|
for (const line of redirects.split("\n")) {
|
|
if (line.startsWith("#") || line.trim() === "") continue;
|
|
|
|
const [from, to] = line.split(" ");
|
|
|
|
if (from === to) {
|
|
console.log(`✘ Found infinite redirect:\n ${from} -> ${to}`);
|
|
numInfiniteRedirects++;
|
|
}
|
|
|
|
if (from.includes("#")) {
|
|
console.log(`✘ Found source URL with fragment:\n ${from}`);
|
|
numUrlsWithFragment++;
|
|
}
|
|
|
|
if (redirectSourceUrls.includes(from)) {
|
|
console.log(`✘ Found repeated source URL:\n ${from}`);
|
|
numDuplicateRedirects++;
|
|
} else {
|
|
redirectSourceUrls.push(from);
|
|
}
|
|
}
|
|
|
|
if (numInfiniteRedirects || numUrlsWithFragment || numDuplicateRedirects) {
|
|
console.log("\nDetected errors:");
|
|
|
|
if (numInfiniteRedirects > 0) {
|
|
console.log(`- ${numInfiniteRedirects} infinite redirect(s)`);
|
|
}
|
|
|
|
if (numUrlsWithFragment > 0) {
|
|
console.log(`- ${numUrlsWithFragment} source URL(s) with a fragment`);
|
|
}
|
|
|
|
if (numDuplicateRedirects > 0) {
|
|
console.log(`- ${numDuplicateRedirects} repeated source URL(s)`);
|
|
}
|
|
|
|
console.log("\nPlease fix the errors above before merging :)");
|
|
process.exit(1);
|
|
} else {
|
|
console.log("\nDone!");
|
|
}
|
|
}
|
|
|
|
main();
|