UNPKG

esa-cli

Version:

A CLI for operating Alibaba Cloud ESA Functions and Pages.

75 lines (74 loc) 3.75 kB
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()); }); }; import chalk from 'chalk'; import t from '../../i18n/index.js'; import { ApiService } from '../../libs/apiService.js'; import logger from '../../libs/logger.js'; import { validRoutine } from '../../utils/checkIsRoutineCreated.js'; import { getProjectConfig } from '../../utils/fileUtils/index.js'; import { displayVersionList } from '../deploy/helper.js'; import { checkIsLoginSuccess, getRoutineCodeVersions } from '../utils.js'; const deploymentsList = { command: 'list', describe: `🔍 ${t('deployments_list_describe').d('List all deployments')}`, handler: () => __awaiter(void 0, void 0, void 0, function* () { handleListDeployments(); }) }; export default deploymentsList; export function handleListDeployments() { return __awaiter(this, void 0, void 0, function* () { const projectConfig = getProjectConfig(); if (!projectConfig) return logger.notInProject(); const isSuccess = yield checkIsLoginSuccess(); if (!isSuccess) return; yield validRoutine(projectConfig.name); const server = yield ApiService.getInstance(); const req = { Name: projectConfig.name }; const routineDetail = yield server.getRoutine(req); if (!routineDetail) return; const { allVersions, stagingVersions, productionVersions } = yield getRoutineCodeVersions(projectConfig.name); yield displayDeployingVersions(routineDetail, stagingVersions, productionVersions); yield displayVersionList(allVersions, stagingVersions, productionVersions); }); } function displayDeployingVersions(routineDetail, stagingVersions, productionVersions) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; const server = yield ApiService.getInstance(); const res = yield server.getRoutineStagingEnvIp(); const stagingIpList = (_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.IPV4) !== null && _b !== void 0 ? _b : []; const coloredStagingIpList = stagingIpList.map((ip) => { return chalk.green(ip); }); const showEnvTable = (version) => { const data = [{ Version: version }]; logger.table([], data); }; logger.log(chalk.bold(t('deploy_env_staging').d('Staging'))); if (stagingIpList.length > 0) { logger.log(`Staging IP: ${coloredStagingIpList.join(', ')}`); } if (stagingVersions.length > 0) { showEnvTable(stagingVersions.join(',')); } logger.block(); logger.log(`${chalk.bold(`${t('deploy_env_production').d('Production')} ${chalk.green('●')}`)}`); if (productionVersions.length > 0) { showEnvTable(productionVersions.join(',')); } logger.log(`${t('show_default_url').d(`You can visit:`)} ${chalk.yellowBright(routineDetail.data.DefaultRelatedRecord)}`); logger.info(routineDetail.data.DefaultRelatedRecord); logger.block(); }); }