esa-cli
Version:
A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).
84 lines (83 loc) β’ 4.32 kB
JavaScript
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 { displayVersionList } from '../deploy/index.js';
import { checkDirectory, checkIsLoginSuccess, getRoutineVersionList } from '../utils.js';
import { getProjectConfig } from '../../utils/fileUtils/index.js';
import chalk from 'chalk';
import { ApiService } from '../../libs/apiService.js';
import t from '../../i18n/index.js';
import logger from '../../libs/logger.js';
import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
const deploymentsList = {
command: 'list',
describe: `π ${t('deployments_list_describe').d('List all deployments')}`,
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
handleListDeployments(argv);
})
};
export default deploymentsList;
export function handleListDeployments(argv) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d;
if (!checkDirectory()) {
return;
}
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 versionList = yield getRoutineVersionList(projectConfig.name);
const req = { Name: projectConfig.name };
const routineDetail = yield server.getRoutine(req);
if (!routineDetail)
return;
//ζ΅θ―η―ε’ηζ¬
const stagingVersion = (_b = (_a = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _a === void 0 ? void 0 : _a.Envs[1]) === null || _b === void 0 ? void 0 : _b.CodeVersion;
//ηδΊ§η―ε’ηζ¬
const productionVersion = (_d = (_c = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _c === void 0 ? void 0 : _c.Envs[0]) === null || _d === void 0 ? void 0 : _d.CodeVersion;
yield displayListPrompt(routineDetail);
yield displayVersionList(versionList, stagingVersion, productionVersion);
});
}
function displayListPrompt(routineDetail) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const stagingEnv = routineDetail.data.Envs[1];
const prodEnv = routineDetail.data.Envs[0];
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, region) => {
const data = [{ Version: version }];
if (region) {
data.push({ Region: region });
}
logger.table([], data);
};
logger.log(chalk.bold(t('deploy_env_staging').d('Staging')));
if (stagingIpList.length > 0) {
logger.log(`Staging IP: ${coloredStagingIpList.join(', ')}`);
}
showEnvTable(stagingEnv.CodeVersion);
logger.block();
logger.log(`${chalk.bold(`${t('deploy_env_production').d('Production')} ${chalk.green('β')}`)}`);
showEnvTable(prodEnv.CodeVersion);
logger.log(`${t('show_default_url').d(`You can visit:`)} ${chalk.yellowBright(routineDetail.data.DefaultRelatedRecord)}`);
logger.info(routineDetail.data.DefaultRelatedRecord);
logger.block();
});
}