esa-cli
Version:
A CLI for operating Alibaba Cloud ESA Functions and Pages.
104 lines (103 loc) • 3.96 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 yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import commit from './commands/commit/index.js';
import config from './commands/config.js';
import deploy from './commands/deploy/index.js';
import deployments from './commands/deployments/index.js';
import dev from './commands/dev/index.js';
import domainCommand from './commands/domain/index.js';
import init from './commands/init/index.js';
import lang from './commands/lang.js';
import login from './commands/login/index.js';
import logout from './commands/logout.js';
import routeCommand from './commands/route/index.js';
import routine from './commands/routine/index.js';
import site from './commands/site/index.js';
import t from './i18n/index.js';
import logger from './libs/logger.js';
import { handleCheckVersion, checkCLIVersion } from './utils/checkVersion.js';
import { getCliConfig } from './utils/fileUtils/index.js';
const main = () => __awaiter(void 0, void 0, void 0, function* () {
const argv = hideBin(process.argv);
const cliConfig = getCliConfig();
const esa = yargs(argv)
.strict()
.fail((msg, err) => {
console.error(msg, err);
})
.scriptName('esa-cli')
.locale((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.lang) || 'en')
.version(false)
.wrap(null)
.help()
.middleware((argv) => __awaiter(void 0, void 0, void 0, function* () {
if (argv.debug) {
logger.setLogLevel('debug');
}
try {
// Pass current command (first positional) so version check can decide prompting behavior
yield checkCLIVersion((argv._ && argv._[0] ? String(argv._[0]) : ''));
}
catch (e) {
console.log(e);
console.log('error');
}
}))
.epilogue(`${t('main_epilogue').d('For more information, visit ESA')}: ${chalk.underline.blue('https://www.aliyun.com/product/esa')}`)
.options('version', {
describe: t('main_version_describe').d('Show version'),
alias: 'v'
})
.options('help', {
describe: t('main_help_describe').d('Show help'),
alias: 'h'
})
.options('debug', {
describe: t('dev_option_debugger').d('Output debug logs'),
type: 'boolean',
default: false
});
esa.command('*', false, () => { }, (args) => {
if (args._.length > 0) {
// Unknown command
console.error(t('common_sub_command_fail').d('Use esa-cli <command> -h to see help'));
}
else {
if (args.v) {
handleCheckVersion();
}
else if (args.h || args.help) {
esa.showHelp('log');
}
else {
esa.showHelp('log');
}
}
});
esa.command(init);
esa.command(dev);
esa.command(commit);
esa.command(deploy);
esa.command(deployments);
esa.command(routine);
esa.command(site);
esa.command(domainCommand);
esa.command(routeCommand);
esa.command(login);
esa.command(logout);
esa.command(config);
esa.command(lang);
esa.group(['help', 'version'], 'Options:');
esa.parse();
});
main();