UNPKG

esa-cli

Version:

A CLI for operating Alibaba Cloud ESA Functions and Pages.

91 lines (90 loc) 4.03 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 chalk from 'chalk'; import t from '../../i18n/index.js'; import logger from '../../libs/logger.js'; import promptParameter from '../../utils/prompt.js'; import { validateAndInitializeProject, generateCodeVersion } from '../common/utils.js'; const commit = { command: 'commit [entry]', describe: `📦 ${t('commit_describe').d('Commit your code, save as a new version')}`, builder: (yargs) => { return yargs .option('minify', { alias: 'm', describe: t('commit_option_minify').d('Minify code before committing'), type: 'boolean', default: false }) .option('assets', { alias: 'a', describe: t('commit_option_assets').d('Assets directory'), type: 'string' }) .option('description', { alias: 'd', describe: t('commit_option_description').d('Description for Functions& Pages/version (skip interactive input)'), type: 'string' }) .option('name', { alias: 'n', describe: t('commit_option_name').d('Functions& Pages name'), type: 'string' }) .option('bundle', { describe: 'Bundle with esbuild (use --no-bundle to skip)', type: 'boolean', default: true }); }, handler: (argv) => __awaiter(void 0, void 0, void 0, function* () { yield handleCommit(argv); exit(); }) }; export default commit; export function handleCommit(argv) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; intro(`Commit an application with ESA`); const projectInfo = yield validateAndInitializeProject(argv === null || argv === void 0 ? void 0 : argv.name); if (!projectInfo) return; const { projectName } = projectInfo; let description; if (argv.description) { description = argv.description; } else { description = (yield promptParameter({ type: 'text', question: t('commit_version_description').d('Enter a description for the version'), label: 'Description', defaultValue: '' })); } logger.startSubStep('Generating code version'); const res = yield generateCodeVersion(projectName, description, argv === null || argv === void 0 ? void 0 : argv.entry, argv === null || argv === void 0 ? void 0 : argv.assets, argv === null || argv === void 0 ? void 0 : argv.minify, undefined, argv.bundle === false); const { isSuccess } = res || {}; if (!isSuccess) { logger.endSubStep('Generate version failed'); exit(1); } const codeVersion = (_b = (_a = res === null || res === void 0 ? void 0 : res.res) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.CodeVersion; if (!codeVersion) { logger.endSubStep('Missing CodeVersion in response'); return false; } logger.endSubStep(`Version generated: ${codeVersion}`); outro(`Code version ${chalk.bold(codeVersion)} generated successfully`); }); }