2020-09-17 10:39:25 +03:00
|
|
|
"use strict";
|
|
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
|
};
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2021-03-31 02:55:25 +03:00
|
|
|
exports.isEthers = exports.getPackageJsonPath = exports.getDirname = exports.getPackagePath = exports.packages = exports.dirnames = exports.dirs = exports.resolve = exports.root = void 0;
|
2020-09-17 10:39:25 +03:00
|
|
|
const fs_1 = __importDefault(require("fs"));
|
|
|
|
const path_1 = require("path");
|
2021-10-16 09:29:27 +03:00
|
|
|
exports.root = (0, path_1.resolve)(__dirname, "../../../");
|
2020-09-21 08:14:06 +03:00
|
|
|
function resolve(...args) {
|
|
|
|
args.unshift(exports.root);
|
|
|
|
return path_1.resolve.apply(null, args);
|
|
|
|
}
|
|
|
|
exports.resolve = resolve;
|
|
|
|
const pathRootPackageJsonPath = resolve("package.json");
|
|
|
|
const pathPackages = resolve("packages");
|
2020-09-17 10:39:25 +03:00
|
|
|
exports.dirs = Object.freeze({
|
|
|
|
rootPackageJsonPath: pathRootPackageJsonPath,
|
|
|
|
packages: pathPackages,
|
|
|
|
root: exports.root,
|
|
|
|
});
|
2020-09-23 05:54:48 +03:00
|
|
|
exports.dirnames = Object.freeze(fs_1.default.readdirSync(exports.dirs.packages).filter((dirname) => {
|
|
|
|
return (dirname[0] !== ".");
|
|
|
|
}));
|
2020-09-17 10:39:25 +03:00
|
|
|
const packageLookup = exports.dirnames.reduce((accum, dirname) => {
|
2021-10-16 09:29:27 +03:00
|
|
|
const packagePath = (0, path_1.resolve)(exports.dirs.packages, dirname);
|
|
|
|
const packageJsonPath = (0, path_1.resolve)(packagePath, "package.json");
|
2020-09-17 10:39:25 +03:00
|
|
|
const info = JSON.parse(fs_1.default.readFileSync(packageJsonPath).toString());
|
|
|
|
const packageName = info.name;
|
|
|
|
const version = info.version;
|
|
|
|
accum[packageName] = accum[dirname] = {
|
|
|
|
dirname, packageName, packagePath, packageJsonPath, version
|
|
|
|
};
|
|
|
|
return accum;
|
|
|
|
}, {});
|
|
|
|
exports.packages = Object.freeze(exports.dirnames.map((dirname) => packageLookup[dirname].packageName));
|
|
|
|
function getPackageInfo(name) {
|
|
|
|
const value = packageLookup[name];
|
|
|
|
if (!value) {
|
|
|
|
throw new Error(`unknown package: ${name}`);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
function getPackagePath(name) {
|
|
|
|
return getPackageInfo(name).packagePath;
|
|
|
|
}
|
|
|
|
exports.getPackagePath = getPackagePath;
|
|
|
|
function getDirname(name) {
|
|
|
|
return getPackageInfo(name).dirname;
|
|
|
|
}
|
|
|
|
exports.getDirname = getDirname;
|
|
|
|
function getPackageJsonPath(name) {
|
|
|
|
return getPackageInfo(name).packageJsonPath;
|
|
|
|
}
|
|
|
|
exports.getPackageJsonPath = getPackageJsonPath;
|
|
|
|
function isEthers(name) {
|
|
|
|
return !!packageLookup[name];
|
|
|
|
}
|
|
|
|
exports.isEthers = isEthers;
|