UNPKG

esa-cli

Version:

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

57 lines (56 loc) 2.68 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 path from 'path'; import { createEdgeRoutine } from '../commands/commit/index.js'; import { ApiService } from '../libs/apiService.js'; import { readEdgeRoutineFile } from './fileUtils/index.js'; import logger from '../libs/logger.js'; import t from '../i18n/index.js'; import prodBuild from '../commands/commit/prodBuild.js'; import { exit } from 'process'; import chalk from 'chalk'; export function isRoutineExist(name) { return __awaiter(this, void 0, void 0, function* () { const server = yield ApiService.getInstance(); const req = { Name: name }; const response = yield server.getRoutine(req, false); return !!response; }); } export function validRoutine(name) { return __awaiter(this, void 0, void 0, function* () { const isCreatedRoutine = yield isRoutineExist(name); if (!isCreatedRoutine) { logger.warn(`${t('routine_not_exist').d('Routine does not exist, please create a new one. Run command:')} ${chalk.greenBright('esa deploy')}`); exit(0); } }); } export function checkRoutineExist(name, entry) { return __awaiter(this, void 0, void 0, function* () { const isCreatedRoutine = yield isRoutineExist(name); if (!isCreatedRoutine) { logger.log(t('first_deploy').d('This is the first time to deploy, we will create a new routine for you.')); const entryFile = path.resolve(entry !== null && entry !== void 0 ? entry : '', 'src/index.js'); yield prodBuild(false, entryFile, entry); const code = readEdgeRoutineFile(entry) || ''; const res = yield createEdgeRoutine({ name: name, code: code }); if (res) { logger.success(t('routine_create_success').d('Routine created successfully.')); } else { logger.error(t('routine_create_fail').d('Routine created failed.')); } } }); }