UNPKG

zcatalyst-cli

Version:

Command Line Tool for CATALYST

60 lines (59 loc) 3.02 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 path_1 = require("path"); const fn_utils_1 = require("../../../fn-utils"); const runtime_store_1 = __importDefault(require("../../../runtime-store")); const constants_1 = require("../../../util_modules/constants"); const fs_1 = require("../../../util_modules/fs"); const pip_install_1 = require("../../../init/dependencies/python/pip-install"); const error_1 = __importDefault(require("../../../error")); const fs_extra_1 = require("fs-extra"); const throbber_1 = __importDefault(require("../../../throbber")); exports.default = (targets) => __awaiter(void 0, void 0, void 0, function* () { if (targets === undefined || targets.length === 0) { return; } const throbber = throbber_1.default.getInstance(); yield fn_utils_1.fnUtils.python.validate(targets, 0); const pyTargets = targets .filter((target) => { if (!target.valid) { throbber.remove('function_serve_' + target.name); } return target.valid; }) .map((target) => { fn_utils_1.fnUtils.common.generateUrlForTarget(target); return target; }); return Promise.all(pyTargets.map((target) => __awaiter(void 0, void 0, void 0, function* () { var _a; const buildPath = (0, path_1.join)(runtime_store_1.default.get('project.root'), constants_1.FOLDERNAME.build, constants_1.FOLDERNAME.functions, target.name); const reqFile = (0, path_1.join)(target.source, constants_1.FILENAME.functions.python_requirements); yield (0, fs_extra_1.ensureDir)(buildPath); yield fs_1.ASYNC.emptyDir(buildPath); try { yield (0, pip_install_1.installRequirements)(reqFile, buildPath, (_a = target.stack) === null || _a === void 0 ? void 0 : _a.replace('python_', '')); } catch (err) { const error = error_1.default.getErrorInstance(err); target.valid = false; target.failure_reason = error.message; } yield fs_1.ASYNC.copyDir(target.source, buildPath); throbber.remove('function_serve_' + target.name); return target; }))); });