UNPKG

esa-cli

Version:

A CLI for operating Alibaba Cloud ESA Functions and Pages.

93 lines (92 loc) 4.06 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 moment from 'moment'; import SelectItems from '../../components/selectInput.js'; import t from '../../i18n/index.js'; import { PublishType } from '../../libs/interface.js'; import logger from '../../libs/logger.js'; import promptParameter from '../../utils/prompt.js'; export function yesNoPromptAndExecute(message, execute) { return __awaiter(this, void 0, void 0, function* () { const confirmed = (yield promptParameter({ type: 'confirm', question: message, label: 'Confirm', defaultValue: true })); if (!confirmed) return false; return yield execute(); }); } export function promptSelectVersion(versionList) { const items = versionList .filter((version) => version.codeVersion !== 'unstable') .map((version, index) => { var _a; return ({ label: (_a = version.codeVersion) !== null && _a !== void 0 ? _a : '', value: String(index) }); }); return new Promise((resolve) => { const handleSelection = (item) => __awaiter(this, void 0, void 0, function* () { resolve(item.label); }); SelectItems({ items, handleSelect: handleSelection }); }); } export function displaySelectDeployEnv() { logger.log(`📃 ${t('deploy_env_select_description').d('Please select which environment you want to deploy')}`); const selectItems = [ { label: t('deploy_env_staging').d('Staging'), value: PublishType.Staging }, { label: t('deploy_env_production').d('Production'), value: PublishType.Production } ]; return new Promise((resolve) => { const handleSelection = (item) => __awaiter(this, void 0, void 0, function* () { resolve(item.value); }); SelectItems({ items: selectItems, handleSelect: handleSelection }); }); } export function displayVersionList(allVersions, stagingVersions, productionVersions) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; logger.log(`${chalk.bgYellow('Active')} ${t('deploy_env_staging').d('Staging')}`); logger.log(`${chalk.bgGreen('Active')} ${t('deploy_env_production').d('Production')}`); const data = []; for (let i = 0; i < allVersions.length; i++) { const version = allVersions[i]; const createTime = moment(version.createTime).format('YYYY/MM/DD HH:mm:ss'); const tags = [ stagingVersions.includes((_a = version.codeVersion) !== null && _a !== void 0 ? _a : '') ? chalk.bgYellow('Active') : '', productionVersions.includes((_b = version.codeVersion) !== null && _b !== void 0 ? _b : '') ? chalk.bgGreen('Active') : '' ]; data.push([ `${version.codeVersion} ${tags.join(' ')}`, createTime, (_c = version.codeDescription) !== null && _c !== void 0 ? _c : '' ]); } logger.table([ t('deploy_table_header_version').d('Version'), t('deploy_table_header_created').d('Created'), t('deploy_table_header_description').d('Description') ], data); }); }