config: refactor

This commit is contained in:
Dax Raad
2026-04-16 12:40:16 -04:00
parent bfffc3c2c6
commit 33bb847a1d
14 changed files with 449 additions and 435 deletions

View File

@@ -0,0 +1,16 @@
import path from "path"
function sliceAfterMatch(filePath: string, searchRoots: string[]) {
const normalizedPath = filePath.replaceAll("\\", "/")
for (const searchRoot of searchRoots) {
const index = normalizedPath.indexOf(searchRoot)
if (index === -1) continue
return normalizedPath.slice(index + searchRoot.length)
}
}
export function configEntryNameFromPath(filePath: string, searchRoots: string[]) {
const candidate = sliceAfterMatch(filePath, searchRoots) ?? path.basename(filePath)
const ext = path.extname(candidate)
return ext.length ? candidate.slice(0, -ext.length) : candidate
}