keycloak_theme/src/bin/tools/getThisCodebaseRootDirPath.ts

20 lines
516 B
TypeScript
Raw Normal View History

2021-02-28 18:40:57 +01:00
import * as fs from "fs";
import * as path from "path";
function getThisCodebaseRootDirPath_rec(dirPath: string): string {
if (fs.existsSync(path.join(dirPath, "package.json"))) {
2021-02-28 18:40:57 +01:00
return dirPath;
}
return getThisCodebaseRootDirPath_rec(path.join(dirPath, ".."));
2021-02-28 18:40:57 +01:00
}
let result: string | undefined = undefined;
export function getThisCodebaseRootDirPath(): string {
2021-02-28 18:40:57 +01:00
if (result !== undefined) {
return result;
}
return (result = getThisCodebaseRootDirPath_rec(__dirname));
}