( dirPath: string, excludedDirs: string[] = IGNORED_DIRS, extensions: RegExp = /\.mdx?$/i, )
| 484 | * @param extensions - Regex to match file extensions (default: markdown only) |
| 485 | */ |
| 486 | export function hasMarkdownFiles( |
| 487 | dirPath: string, |
| 488 | excludedDirs: string[] = IGNORED_DIRS, |
| 489 | extensions: RegExp = /\.mdx?$/i, |
| 490 | ): boolean { |
| 491 | function walk(dir: string): boolean { |
| 492 | let entries; |
| 493 | try { |
| 494 | entries = readdirSync(dir, { withFileTypes: true }); |
| 495 | } catch { |
| 496 | return false; |
| 497 | } |
| 498 | for (const entry of entries) { |
| 499 | if (entry.isDirectory()) { |
| 500 | if (excludedDirs.some((d) => d === entry.name + "/")) continue; |
| 501 | if (walk(join(dir, entry.name))) return true; |
| 502 | } else if (entry.isFile() && extensions.test(entry.name)) { |
| 503 | return true; |
| 504 | } |
| 505 | } |
| 506 | return false; |
| 507 | } |
| 508 | return walk(dirPath); |
| 509 | } |
no test coverage detected