Raw
1 import fs from "fs/promises"
2 import path from "path"
3 import { SEARCH_ENTITY_FILES } from "./constants"
4
5 /**
6 * Returns the path of the source's search entity file, or `null` when the
7 * source has none.
8 */
9 export async function findSearchEntityFile(
10 source: string
11 ): Promise<string | null> {
12 for (const fileName of SEARCH_ENTITY_FILES) {
13 const filePath = path.join(source, fileName)
14
15 try {
16 await fs.access(filePath)
17 return filePath
18 } catch {
19 // File doesn't exist, try next extension
20 }
21 }
22
23 return null
24 }