zcatalyst-cli
Version:
Command Line Tool for CATALYST
85 lines (84 loc) • 3.42 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateAppSail = exports.filterTargets = void 0;
const ansi_colors_1 = require("ansi-colors");
const error_1 = __importDefault(require("./error"));
const constants_1 = require("./util_modules/constants");
const logger_1 = require("./util_modules/logger");
const option_1 = require("./util_modules/option");
function getAppSailFilters(targetStr) {
return targetStr.split(',').reduce((filterArr, target) => {
const opts = target.split(':');
if (opts[0] === 'appsail' && opts[1]) {
filterArr.push(opts[1]);
return filterArr;
}
return filterArr;
}, []);
}
function filterTargets(allTargets) {
const only = (0, option_1.getOptionValue)('only');
if (only !== undefined) {
const onlyTargs = getAppSailFilters(only);
if (onlyTargs.length === 0) {
return allTargets;
}
const refined = onlyTargs.reduce((filtered, filter) => {
const targDetailsIdx = allTargets.findIndex((targ) => targ.name === filter);
if (targDetailsIdx === -1) {
filtered.unmatched.push(filter);
}
else {
const targDetails = allTargets.splice(targDetailsIdx, 1);
filtered.matched.push(targDetails[0]);
}
return filtered;
}, {
matched: [],
unmatched: []
});
if (refined.unmatched.length > 0) {
throw new error_1.default(`The filters ${(0, ansi_colors_1.bold)(refined.unmatched.join(', '))} provided with --only option does not match with any AppSail service in ${constants_1.FILENAME.config}.`);
}
return refined.matched;
}
const except = (0, option_1.getOptionValue)('except');
if (except !== undefined) {
const exceptTargs = getAppSailFilters(except);
const refined = exceptTargs.reduce((filtered, filter) => {
const targDetailsIdx = allTargets.findIndex((targ) => targ.name === filter);
if (targDetailsIdx === -1) {
filtered.unmatched.push(filter);
}
else {
filtered.matched.splice(targDetailsIdx, 1);
}
return filtered;
}, {
matched: allTargets,
unmatched: []
});
if (refined.unmatched.length > 0) {
(0, logger_1.message)(`The filters ${(0, ansi_colors_1.bold)(refined.unmatched.join(', '))} provided with --except option does not match with any AppSail service in ${constants_1.FILENAME.config}, hence ignored.`);
}
return refined.matched;
}
return allTargets;
}
exports.filterTargets = filterTargets;
function validateAppSail(targDetails) {
targDetails.forEach((targ) => {
var _a, _b;
if (targ.validity.valid && ((_a = targ.config) === null || _a === void 0 ? void 0 : _a.platform) !== 'war' && !((_b = targ.config) === null || _b === void 0 ? void 0 : _b.command)) {
targ.validity = {
valid: false,
reason: 'Start-up command missing'
};
}
});
return targDetails;
}
exports.validateAppSail = validateAppSail;