2021-02-28 18:40:57 +01:00
|
|
|
import * as fs from "fs";
|
|
|
|
import * as path from "path";
|
|
|
|
|
|
|
|
function getProjectRootRec(dirPath: string): string {
|
2022-02-18 21:00:44 +01:00
|
|
|
if (fs.existsSync(path.join(dirPath, "tsconfig.json"))) {
|
2021-02-28 18:40:57 +01:00
|
|
|
return dirPath;
|
|
|
|
}
|
|
|
|
return getProjectRootRec(path.join(dirPath, ".."));
|
|
|
|
}
|
|
|
|
|
|
|
|
let result: string | undefined = undefined;
|
|
|
|
|
|
|
|
export function getProjectRoot(): string {
|
|
|
|
if (result !== undefined) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result = getProjectRootRec(__dirname));
|
2021-10-11 21:35:40 +02:00
|
|
|
}
|