Recursively search for a file by basename within a directory (max 3 levels deep).
( dir: string, basename: string, root: string, depth = 0, )
| 19 | |
| 20 | /** Recursively search for a file by basename within a directory (max 3 levels deep). */ |
| 21 | function findFileRecursive( |
| 22 | dir: string, |
| 23 | basename: string, |
| 24 | root: string, |
| 25 | depth = 0, |
| 26 | ): string | null { |
| 27 | if (depth > 3) return null; |
| 28 | try { |
| 29 | for (const entry of fs.readdirSync(dir)) { |
| 30 | const full = path.join(dir, entry); |
| 31 | if (entry === basename && fs.statSync(full).isFile()) return full; |
| 32 | if ( |
| 33 | depth < 3 && |
| 34 | fs.statSync(full).isDirectory() && |
| 35 | !entry.startsWith('.') |
| 36 | ) { |
| 37 | const found = findFileRecursive(full, basename, root, depth + 1); |
| 38 | if (found) return found; |
| 39 | } |
| 40 | } |
| 41 | } catch { |
| 42 | /* permission or read error, skip */ |
| 43 | } |
| 44 | return null; |
| 45 | } // v4: compact md, no breaks, hide br |
| 46 | |
| 47 | let wss: WebSocketServer; |
| 48 |