esa-cli
Version:
A CLI for operating Alibaba Cloud ESA Functions and Pages.
92 lines (91 loc) • 3.74 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 chalk from 'chalk';
import Table from 'cli-table3';
import moment from 'moment';
import t from '../../i18n/index.js';
import { ApiService } from '../../libs/apiService.js';
import logger from '../../libs/logger.js';
import { checkIsLoginSuccess } from '../utils.js';
const list = {
command: 'list',
describe: `📋 ${t('list_describe').d('List all your projects')}`,
builder: (yargs) => {
return yargs
.option('keyword', {
alias: 'k',
describe: t('deploy_option_keyword').d('Keyword to search for projects'),
type: 'string'
})
.usage(`${t('common_usage').d('Usage')}: \$0 list [--keyword <keyword>]`);
},
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
handleList(argv);
})
};
export default list;
export function getAllRoutines(options) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
const server = yield ApiService.getInstance();
const allRoutines = [];
let pageNumber = 1;
const pageSize = (options === null || options === void 0 ? void 0 : options.PageSize) || 50;
while (true) {
const res = yield server.listUserRoutines({
RegionId: options === null || options === void 0 ? void 0 : options.RegionId,
PageNumber: pageNumber,
PageSize: pageSize,
SearchKeyWord: options === null || options === void 0 ? void 0 : options.SearchKeyWord
});
if (!((_a = res === null || res === void 0 ? void 0 : res.body) === null || _a === void 0 ? void 0 : _a.Routines)) {
break;
}
allRoutines.push(...res.body.Routines);
const totalCount = res.body.TotalCount;
const currentCount = allRoutines.length;
if (currentCount >= totalCount) {
break;
}
pageNumber++;
}
return allRoutines;
});
}
export function handleList(argv) {
return __awaiter(this, void 0, void 0, function* () {
const isSuccess = yield checkIsLoginSuccess();
if (!isSuccess)
return;
const routineList = yield getAllRoutines({
SearchKeyWord: argv.keyword
});
if (routineList) {
logger.log(chalk.bold.bgGray(`📃 ${t('list_routine_name_title').d('List all of Functions and Pages')}:`));
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());
});
}