UNPKG

zcatalyst-cli

Version:

Command Line Tool for CATALYST

92 lines (91 loc) 5.13 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const appsail_utils_1 = require("../../appsail-utils"); const error_1 = __importDefault(require("../../error")); const port_resolver_1 = __importDefault(require("../../port-resolver")); const runtime_store_1 = __importDefault(require("../../runtime-store")); const config_1 = require("../../util_modules/config"); const constants_1 = require("../../util_modules/constants"); const index_1 = require("../../util_modules/logger/index"); exports.default = () => __awaiter(void 0, void 0, void 0, function* () { const allTargets = yield config_1.appSailConfig.getAllTargetDetails(); const optionTargets = (0, appsail_utils_1.filterTargets)(allTargets || []); if (optionTargets.length === 0) { (0, index_1.debug)('AppSail targets are empty'); return []; } const validated = yield (0, appsail_utils_1.validateAppSail)(optionTargets); const filledTargets = yield Promise.all(validated.map((targ) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; if (!targ.validity.valid) { return targ; } const proxyPort = yield port_resolver_1.default.getPort('appsail', 'http', { name: targ.name + '_proxy', searchSpan: 10, server: 'master' }).catch((err) => { throw new error_1.default('No free ports between 3000 and 3010. AppSail needs the ports within this range to function properly', { original: err }); }); const AppSailServerDetails = Object.assign(Object.assign({}, targ), { port: { appsail: { host: -1 }, proxy: proxyPort, debug: { host: runtime_store_1.default.get(`context.port.debug.appsail.${targ.name}`, -1), container: (_b = (_a = targ.config) === null || _a === void 0 ? void 0 : _a.port) === null || _b === void 0 ? void 0 : _b.debug } } }); if (targ.runtime === 'catalyst') { try { const appsailPort = ((_d = (_c = targ.config) === null || _c === void 0 ? void 0 : _c.port) === null || _d === void 0 ? void 0 : _d.http) ? yield port_resolver_1.default.getFreePort(targ.config.port.http) : yield port_resolver_1.default.getPort('appsail', 'http', { name: targ.name + '_proxy', server: 'service', searchSpan: constants_1.DEFAULT.serve_port.search_span.http_port }); AppSailServerDetails.port.appsail.host = appsailPort; } catch (er) { throw new error_1.default(((_f = (_e = targ.config) === null || _e === void 0 ? void 0 : _e.port) === null || _f === void 0 ? void 0 : _f.http) ? `The port ${(_h = (_g = targ.config) === null || _g === void 0 ? void 0 : _g.port) === null || _h === void 0 ? void 0 : _h.http} configured for the AppSail ${targ.name} is not available` : 'Unable to find a free port to serve the AppSail: ' + targ.name, { exit: 1, original: er }); } } else { try { const hostBindPort = yield port_resolver_1.default.getPort('appsail', 'http', { name: targ.name + '_proxy', server: 'service', searchSpan: constants_1.DEFAULT.serve_port.search_span.http_port }); AppSailServerDetails.port.appsail.host = hostBindPort; AppSailServerDetails.port.appsail.container = (_k = (_j = targ.config) === null || _j === void 0 ? void 0 : _j.port) === null || _k === void 0 ? void 0 : _k.http; } catch (er) { throw new error_1.default('Unable to find a host port to bind with the AppSail container for serving the AppSail: ' + targ.name, { exit: 1, original: er }); } } return AppSailServerDetails; }))); runtime_store_1.default.set('context.appsail.targets', filledTargets); return filledTargets; });