mirror of
https://github.com/garronej/ts-ci.git
synced 2025-11-30 21:43:05 +00:00
24 lines
455 B
TypeScript
24 lines
455 B
TypeScript
|
|
|
||
|
|
|
||
|
|
import * as fs from "fs";
|
||
|
|
import * as path from "path";
|
||
|
|
|
||
|
|
function getProjectRootRec(dirPath: string){
|
||
|
|
if( fs.existSync(path.join(dirPath, "package.json")) ){
|
||
|
|
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);
|
||
|
|
|
||
|
|
}
|