@adpt/cli
Version:
AdaptJS command line interface
85 lines • 3 kB
JavaScript
;
/*
* Copyright 2018-2019 Unbounded Systems, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const semver_1 = require("semver");
function checkDependencies(deps, proj) {
const ok = [];
const required = [];
for (const pkg of Object.keys(deps)) {
const hasVer = proj.getLockedVersion(pkg);
if (hasVer == null) {
required.push({
name: pkg,
message: `Package '${pkg}' is not installed`,
});
continue;
}
const dep = deps[pkg];
if (semver_1.satisfies(hasVer, dep.allowed, { includePrerelease: true })) {
ok.push({
name: pkg,
message: `Package '${pkg}': installed version ${hasVer} ok`
});
continue;
}
required.push({
name: pkg,
message: `Package '${pkg}' version '${hasVer}' does not meet ` +
`required version range '${dep.allowed}'`,
});
}
return { ok, required, matches: required.length === 0 };
}
exports.checkDependencies = checkDependencies;
function validateGenList(list) {
if (list.length === 0)
throw new Error(`Gen list cannot be empty`);
for (const g of list) {
for (const pkgName of Object.keys(g.dependencies)) {
const dep = g.dependencies[pkgName];
if (!semver_1.validRange(dep.allowed)) {
throw new Error(`Invalid semver allowed range string ` +
`'${dep.allowed}' for package '${pkgName}' ` +
`in '${g.name}'`);
}
if (!semver_1.validRange(dep.preferred)) {
throw new Error(`Invalid semver preferred range string ` +
`'${dep.preferred}' for package '${pkgName}' ` +
`in '${g.name}'`);
}
}
}
}
exports.validateGenList = validateGenList;
function matchDeps(proj) {
return checkDependencies(this.dependencies, proj);
}
exports.matchDeps = matchDeps;
function _getGen(proj, list) {
let gen;
let matchInfo;
for (gen of list) {
matchInfo = gen.match(proj);
if (matchInfo.matches)
return { gen, matchInfo };
}
if (!gen || !matchInfo)
throw new Error(`Internal error: empty Gen list`);
return { gen, matchInfo };
}
exports._getGen = _getGen;
//# sourceMappingURL=gen.js.map