| 3 | import { join } from 'node:path'; |
| 4 | |
| 5 | export async function scanFiles( |
| 6 | dir: string, |
| 7 | callback: (file: string) => Promise<void> |
| 8 | ): Promise<void> { |
| 9 | const promises: Promise<void>[] = []; |
| 10 | readdir(dir, (err, files) => { |
| 11 | if (err) return; |
| 12 | files.forEach((file) => { |
| 13 | const path = join(dir, file); |
| 14 | if (file === 'node_modules') return; |
| 15 | if (file.startsWith('.')) return; |
| 16 | stat(path, (err, status) => { |
| 17 | if (err) return; |
| 18 | if (status.isDirectory()) { |
| 19 | promises.push(scanFiles(path, callback)); |
| 20 | } else if (status.isFile()) { |
| 21 | promises.push(callback(path)); |
| 22 | } |
| 23 | }); |
| 24 | }); |
| 25 | }); |
| 26 | await Promise.all(promises); |
| 27 | } |
| 28 | |
| 29 | const hackMdCache = new Map<string, Promise<string[]>>(); |
| 30 | |