UNPKG

zcatalyst-cli

Version:

Command Line Tool for CATALYST

76 lines (75 loc) 3.84 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 ansi_colors_1 = require("ansi-colors"); const fn_utils_1 = require("../../fn-utils"); const common_1 = require("../../fn-utils/lib/common"); const pip_install_1 = require("../../init/dependencies/python/pip-install"); const runtime_store_1 = __importDefault(require("../../runtime-store")); const throbber_1 = __importDefault(require("../../throbber")); const constants_1 = require("../../util_modules/constants"); const runtime_1 = __importDefault(require("../../util_modules/constants/lib/runtime")); const languages_1 = require("./languages"); const char_1 = require("../../util_modules/char"); exports.default = (fnTypes) => __awaiter(void 0, void 0, void 0, function* () { fn_utils_1.fnUtils.common.executeHook({ prefix: 'pre', command: 'serve' }); const throbber = throbber_1.default.getInstance(); const targets = yield fn_utils_1.fnUtils.common.validate(); let refinedTargets = yield fn_utils_1.fnUtils.common.refineTargets(targets); refinedTargets = refinedTargets.map((target) => { if (target.type && !fnTypes.includes(target.type)) { target.valid = false; target.failure_reason = 'invalid function type. Only ' + fnTypes.map((t) => constants_1.REMOTE_REF.functions.type[t]).join(',') + ' are supported.'; } else if (target.valid) { throbber.add('function_serve_' + target.name, { text: `preparing function [${target.name}]` }); } return target; }); runtime_store_1.default.set('context.functions.targets', refinedTargets); yield (0, languages_1.prepareFunctions)(refinedTargets); refinedTargets.forEach((target) => { if (target.compilationError) { target.compilationError.forEach((error) => { console.log(`${(0, ansi_colors_1.red)(char_1.CHAR.error)} Error while compiling function[${target.name}]`); console.log(error); }); } if (target.compilationWarning) { target.compilationWarning.forEach((warn) => { console.warn(`${(0, ansi_colors_1.yellow)(char_1.CHAR.warning)} Warning while compiling function[${target.name}]`); console.warn(warn); }); } }); const pyStacks = []; refinedTargets.filter((target) => { var _a; if (((_a = target.stack) === null || _a === void 0 ? void 0 : _a.startsWith(runtime_1.default.language.python.value)) && !pyStacks.includes(target.stack) && target.valid) { pyStacks.push(target.stack); } }); yield Promise.all(pyStacks.map((stack) => __awaiter(void 0, void 0, void 0, function* () { yield (0, pip_install_1.ensurePyRuntime)(constants_1.ENVPATH.runtimes.data, stack); }))); yield (0, common_1.resolveAllFnPorts)(refinedTargets); return refinedTargets; });