esa-cli
Version:
A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).
85 lines (84 loc) • 3.73 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());
});
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import Table from 'cli-table3';
import logger from '../../libs/logger.js';
import { checkIsLoginSuccess } from '../utils.js';
import chalk from 'chalk';
import { ApiService } from '../../libs/apiService.js';
import t from '../../i18n/index.js';
import moment from 'moment';
const list = {
command: 'list',
describe: `📋 ${t('list_describe').d('List all your routines')}`,
builder: (yargs) => {
return yargs.usage(`${t('common_usage').d('Usage')}: \$0 list []`);
},
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
handleList(argv);
})
};
export default list;
export function handleList(argv) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const { site } = argv, args = __rest(argv, ["site"]);
const isSuccess = yield checkIsLoginSuccess();
if (!isSuccess)
return;
const server = yield ApiService.getInstance();
if (site) {
const req = {
SiteSearchType: 'fuzzy',
Status: 'active',
PageNumber: 1,
PageSize: 50
};
const res = yield server.listSites(req);
const siteList = (_a = res === null || res === void 0 ? void 0 : res.data.Sites) !== null && _a !== void 0 ? _a : [];
const siteNameList = siteList === null || siteList === void 0 ? void 0 : siteList.map((item) => item.SiteName);
logger.log(chalk.bold.bgGray(`📃 ${t('list_site_name_title').d('List all of site names')}:`));
logger.tree(siteNameList);
return;
}
const res = yield server.listUserRoutines();
const routineList = (_b = res === null || res === void 0 ? void 0 : res.body) === null || _b === void 0 ? void 0 : _b.Routines;
if (routineList) {
logger.log(chalk.bold.bgGray(`📃 ${t('list_routine_name_title').d('List all of routine')}:`));
displayRoutineList(routineList);
}
});
}
export function displayRoutineList(versionList) {
return __awaiter(this, void 0, void 0, function* () {
const table = new Table({
head: ['Name', 'Created', 'Description'],
colWidths: [20, 25, 30]
});
versionList.forEach((version) => {
table.push([
version.RoutineName,
moment(version.CreateTime).format('YYYY/MM/DD HH:mm:ss'),
version.Description
]);
});
console.table(table.toString());
});
}