()
| 86 | } |
| 87 | |
| 88 | async function verifyMarkdownLinks() { |
| 89 | // Find all markdown files in docs directory |
| 90 | const markdownFiles = await glob('docs/**/*.md', { |
| 91 | ignore: ['**/node_modules/**'], |
| 92 | }) |
| 93 | |
| 94 | console.log(`Found ${markdownFiles.length} markdown files\n`) |
| 95 | |
| 96 | // Process each file |
| 97 | for (const file of markdownFiles) { |
| 98 | const content = readFileSync(file, 'utf-8') |
| 99 | const links: Array<string> = markdownLinkExtractor(content) |
| 100 | |
| 101 | const relativeLinks = links.filter((link: string) => { |
| 102 | return isRelativeLink(link) |
| 103 | }) |
| 104 | |
| 105 | if (relativeLinks.length > 0) { |
| 106 | relativeLinks.forEach((link) => { |
| 107 | relativeLinkExists(link, file) |
| 108 | }) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if (errors.length > 0) { |
| 113 | console.log(`\n❌ Found ${errors.length} broken links:`) |
| 114 | errors.forEach((err) => { |
| 115 | console.log( |
| 116 | `${err.file}\n link: ${err.link}\n resolved: ${err.resolvedPath}\n why: ${err.reason}\n`, |
| 117 | ) |
| 118 | }) |
| 119 | process.exit(1) |
| 120 | } else { |
| 121 | console.log('\n✅ No broken links found!') |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | verifyMarkdownLinks().catch(console.error) |
no test coverage detected