UNPKG

esa-cli

Version:

A CLI for operating Alibaba Cloud ESA Functions and Pages.

98 lines (97 loc) 4.35 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 { exit } from 'process'; import { intro, outro } from '@clack/prompts'; import t from '../../i18n/index.js'; import { getRoot } from '../../utils/fileUtils/base.js'; import { getProjectConfig } from '../../utils/fileUtils/index.js'; import { commitAndDeployVersion, displayDeploySuccess, deployWithVersionPercentages } from '../common/utils.js'; const deploy = { command: 'deploy [entry]', builder: (yargs) => { return yargs .positional('entry', { describe: t('dev_entry_describe').d('Entry file of Functions& Pages'), type: 'string', demandOption: false }) .option('version', { alias: 'v', describe: t('deploy_option_version').d('Version to deploy (skip interactive selection)'), type: 'string' }) .option('environment', { alias: 'e', describe: t('deploy_option_environment').d('Environment to deploy to: staging or production (skip interactive selection)'), type: 'string', choices: ['staging', 'production'] }) .option('name', { alias: 'n', describe: t('deploy_option_name').d('Name of Functions& Pages'), type: 'string' }) .option('assets', { alias: 'a', describe: t('deploy_option_assets').d('Deploy assets'), type: 'string' }) .option('description', { alias: 'd', describe: t('deploy_option_description').d('Description of the version'), type: 'string' }) .option('minify', { alias: 'm', describe: t('deploy_option_minify').d('Minify the code'), type: 'boolean' }) .option('bundle', { describe: 'Bundle with esbuild (use --no-bundle to skip)', type: 'boolean', default: true }) .option('versions', { describe: 'Deploy two versions with percentages, format: v1:80,v2:20 or repeat --versions v1:80 --versions v2:20', type: 'array' }); }, describe: `🚀 ${t('deploy_describe').d('Deploy your project')}`, handler: (argv) => __awaiter(void 0, void 0, void 0, function* () { yield handleDeploy(argv); exit(); }) }; export function handleDeploy(argv) { return __awaiter(this, void 0, void 0, function* () { var _a; const entry = argv.entry; const assets = (_a = argv.assets) !== null && _a !== void 0 ? _a : undefined; const versionsArg = argv.versions || []; intro(`Deploy an application with ESA`); if (versionsArg.length > 0) { const env = argv.environment || 'all'; const ok = yield deployWithVersionPercentages(argv.name || undefined, versionsArg, env, getRoot()); outro(ok ? 'Deploy finished' : 'Deploy failed'); exit(ok ? 0 : 1); } const success = yield commitAndDeployVersion(argv.name || undefined, entry, assets, argv.description || '', getRoot(), argv.environment || 'all', argv.minify, argv.version, (argv.bundle === false)); outro(success ? 'Deploy finished' : 'Deploy failed'); if (success) { const projectConfig = getProjectConfig(getRoot()); yield displayDeploySuccess(argv.name || (projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) || getRoot().split(/[\\/]/).pop() || '', true, true); } exit(success ? 0 : 1); }); } export default deploy;