UNPKG

esa-cli

Version:

A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).

73 lines (72 loc) 2.9 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 { bindRoutineWithDomain, checkDirectory, checkIsLoginSuccess, validDomain, validName } from '../utils.js'; import { getProjectConfig } from '../../utils/fileUtils/index.js'; import t from '../../i18n/index.js'; import logger from '../../libs/logger.js'; import { validRoutine } from '../../utils/checkIsRoutineCreated.js'; const addDomain = { command: 'add <domain>', describe: `🔗 ${t('domain_add_describe').d('Bind a domain to a routine')}`, builder: (yargs) => { return yargs .positional('domain', { describe: t('domain_add_positional_describe').d('The name of domain to add'), type: 'string', demandOption: true }) .usage(`${t('common_usage').d('Usage')}: esa domain add <domain>`) .option('help', { alias: 'h', describe: t('common_help').d('Help'), type: 'boolean', default: false }) .help() .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* () { handleAddDomain(argv); }) }; export default addDomain; export function handleAddDomain(argv) { return __awaiter(this, void 0, void 0, function* () { if (!checkDirectory()) { return; } const isSuccess = yield checkIsLoginSuccess(); if (!isSuccess) return; const projectConfig = getProjectConfig(); if (!projectConfig) return logger.notInProject(); yield validRoutine(projectConfig.name); const name = projectConfig.name; const domain = argv.domain; if (!validName(name)) { logger.error(t('domain_add_invalid_name').d('Invalid name')); return; } if (!domain || !validDomain(domain)) { logger.error(t('domain_add_invalid_name').d('Invalid name')); return; } yield bindRoutineWithDomain(name, domain); }); }