UNPKG

esa-cli

Version:

A CLI for operating Alibaba Cloud ESA Functions and Pages.

112 lines (111 loc) 4.55 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 { promptParameter } from '../../utils/prompt.js'; import { displayDeploySuccess } from '../common/utils.js'; import { applyFileEdits, buildProject, checkAndUpdatePackage, configCategory, configLanguage, configProjectName, configTemplate, createProject, deployProject, getInitParamsFromArgv, initGit, installDependencies, installESACli, updateConfigFile } from './helper.js'; const init = { command: 'init [name]', describe: `📥 ${t('init_describe').d('Initialize a project with a template')}`, builder: (yargs) => { return yargs .positional('name', { describe: t('init_project_name').d('Project name'), type: 'string' }) .option('framework', { alias: 'f', describe: 'Choose a frontend framework (react/vue/nextjs...)', type: 'string' }) .option('language', { alias: 'l', describe: 'Choose programming language (typescript/javascript)', type: 'string', choices: ['typescript', 'javascript'] }) .option('template', { alias: 't', describe: t('init_template_name').d('Template name to use'), type: 'string' }) .option('yes', { alias: 'y', describe: t('init_yes').d('Answer "Yes" to all prompts.'), type: 'boolean', default: false }) .option('git', { alias: 'g', describe: 'Initialize git repository', type: 'boolean' }) .option('deploy', { alias: 'd', describe: 'Deploy after initialization', type: 'boolean' }); }, handler: (argv) => __awaiter(void 0, void 0, void 0, function* () { yield handleInit(argv); exit(0); }) }; export default init; const handleInit = (argv) => __awaiter(void 0, void 0, void 0, function* () { yield checkAndUpdatePackage('esa-template'); const initParams = getInitParamsFromArgv(argv); yield create(initParams); yield config(initParams); yield deploy(initParams); }); const create = (initParams) => __awaiter(void 0, void 0, void 0, function* () { intro(`Create an application with ESA ${chalk.gray('Step 1 of 3')}`); yield configProjectName(initParams); yield configCategory(initParams); yield configTemplate(initParams); if (initParams.category === 'framework') { yield configLanguage(initParams); } yield createProject(initParams); yield installDependencies(initParams); outro(`Application created`); }); const config = (initParams) => __awaiter(void 0, void 0, void 0, function* () { intro(`Configure an application with ESA ${chalk.gray('Step 2 of 3')}`); yield applyFileEdits(initParams); yield installESACli(initParams); yield updateConfigFile(initParams); yield initGit(initParams); outro(`Project configured`); }); const deploy = (initParams) => __awaiter(void 0, void 0, void 0, function* () { intro(`Deploy an application with ESA ${chalk.gray('Step 3 of 3')}`); if (!initParams.deploy) { const deploy = (yield promptParameter({ type: 'confirm', question: t('auto_deploy').d('Do you want to deploy your project?'), label: 'Auto deploy', defaultValue: false })); initParams.deploy = deploy; } if (!initParams.deploy) { outro(`Deploy project skipped`); return; } yield buildProject(initParams); yield deployProject(initParams); outro(`Deploy project finished`); yield displayDeploySuccess(initParams.name, true, true); });