esa-cli
Version:
A CLI for operating Alibaba Cloud ESA Functions and Pages.
81 lines (80 loc) • 3.45 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 t from '../../i18n/index.js';
import api from '../../libs/api.js';
import logger from '../../libs/logger.js';
import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
import { getProjectConfig } from '../../utils/fileUtils/index.js';
import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
const deleteRoute = {
command: 'delete <routeName>',
describe: `🗑 ${t('route_delete_describe').d('Delete a related route')}`,
builder: (yargs) => {
return yargs
.positional('routeName', {
describe: t('route_delete_positional_describe').d('The name of the routes to delete'),
type: 'string',
demandOption: true
})
.fail((msg, err, yargsIns) => {
console.log(msg, err);
if (err)
throw err;
if (msg) {
yargsIns.showHelp('log');
}
process.exit(1);
});
},
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
handleDeleteRoute(argv);
})
};
export default deleteRoute;
export function handleDeleteRoute(argv) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
if (!checkDirectory()) {
return;
}
const projectConfig = getProjectConfig();
if (!projectConfig)
return logger.notInProject();
const isSuccess = yield checkIsLoginSuccess();
if (!isSuccess)
return;
yield validRoutine(projectConfig.name);
const req = {
routineName: projectConfig.name
};
const res = yield api.listRoutineRoutes(req);
const configs = ((_a = res.body) === null || _a === void 0 ? void 0 : _a.configs) || [];
const deleteRouteName = argv.routeName;
const matchedRoute = configs.find((config) => config.routeName === deleteRouteName);
if (!matchedRoute) {
logger.error(t('no_route_found').d('No route found! Please check the route name.'));
return;
}
const siteId = matchedRoute === null || matchedRoute === void 0 ? void 0 : matchedRoute.siteId;
const configId = matchedRoute === null || matchedRoute === void 0 ? void 0 : matchedRoute.configId;
const deleteRouteReq = {
siteId: siteId,
configId: configId
};
const deleteRouteRes = yield api.deleteRoutineRoute(deleteRouteReq);
const isDeleteSuccess = deleteRouteRes.statusCode === 200;
if (isDeleteSuccess) {
logger.success(t('route_delete_success').d('Delete route success!'));
}
else {
logger.error(t('route_delete_fail').d('Delete route fail!'));
}
});
}