MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / findEntryFileInDirectory

Function findEntryFileInDirectory

packages/parser/src/index.ts:262–288  ·  view source on GitHub ↗
(dirPath: string, maxDepth = 1)

Source from the content-addressed store, hash-verified

260 * @returns path to the entry file, or null if none found
261 */
262export 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}
289
290// ==================== 导出类型 ====================
291

Callers 2

registerChatHandlersFunction · 0.90
registerImportRoutesFunction · 0.85

Calls 1

walkFunction · 0.70

Tested by

no test coverage detected