(current: string, depth: number)
| 261 | */ |
| 262 | export function findEntryFileInDirectory(dirPath: string, maxDepth = 1): string | null { |
| 263 | function walk(current: string, depth: number): string | null { |
| 264 | if (depth > maxDepth) return null |
| 265 | let entries: fs.Dirent[] |
| 266 | try { |
| 267 | entries = fs.readdirSync(current, { withFileTypes: true }) |
| 268 | } catch { |
| 269 | return null |
| 270 | } |
| 271 | for (const entry of entries) { |
| 272 | const full = path.join(current, entry.name) |
| 273 | if (entry.isFile() && entry.name.endsWith('.json')) { |
| 274 | const format = detectFormat(full) |
| 275 | if (format) return full |
| 276 | } |
| 277 | } |
| 278 | for (const entry of entries) { |
| 279 | if (entry.isDirectory()) { |
| 280 | const found = walk(path.join(current, entry.name), depth + 1) |
| 281 | if (found) return found |
| 282 | } |
| 283 | } |
| 284 | return null |
| 285 | } |
| 286 | |
| 287 | return walk(dirPath, 0) |
| 288 | } |
no test coverage detected