chore: workiing on base

This commit is contained in:
Martin Guillon
2020-11-14 15:13:09 +01:00
parent 9250bf2222
commit 9dd5471d6d
4 changed files with 88 additions and 9 deletions

View File

@@ -0,0 +1,27 @@
import { existsSync } from "fs";
import { resolve } from "path";
export function getPackageJson(projectDir: string) {
const packageJsonPath = getPackageJsonPath(projectDir);
const result = readJsonFile(packageJsonPath);
return result;
}
export function readJsonFile(filePath:string) {
return require(filePath) as {
main:string
// to be extended?
};
}
export function getPackageJsonPath (projectDir: string) {
const packagePath = resolve(projectDir, "package.json");
if (existsSync(packagePath)) {
return packagePath;
} else {
return getPackageJsonPath(resolve(projectDir, '..'));
}
}