UNPKG

zcatalyst-cli

Version:

Command Line Tool for CATALYST

148 lines (147 loc) 7.38 kB
"use strict"; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const ansi_colors_1 = require("ansi-colors"); const path_1 = require("path"); const prompt_1 = __importDefault(require("../../../prompt")); const runtime_store_1 = __importDefault(require("../../../runtime-store")); const constants_1 = require("../../../util_modules/constants"); const fs_1 = require("../../../util_modules/fs"); const index_1 = require("../../../util_modules/logger/index"); const option_1 = require("../../../util_modules/option"); const common_1 = require("../../util/common"); const project_1 = require("../../../util_modules/project"); const utils_1 = require("./utils"); exports.default = () => __awaiter(void 0, void 0, void 0, function* () { (0, index_1.info)(); (0, index_1.info)((0, ansi_colors_1.white)('=> ') + 'Configure AppSail'); const descArr = [ '', ` Catalyst let's you choose the runtime of your choice for your AppSail. You can either select`, ` "Catalyst-Managed Runtime" to select one of the Catalyst offered runtimes or you can select `, ` "Docker Image" to use a docker image, which can utilize OCI compliant containers to host your AppSail`, ` For more info: ${(0, ansi_colors_1.underline)('https://docs.catalyst.zoho.com/en/serverless/help/appsail/introduction/')}`, '' ]; yield prompt_1.default.register('with-desc'); const runtimeQuestion = yield prompt_1.default.ask(prompt_1.default.question('runtime', 'Please select the runtime for your AppSail to continue:', { type: 'with-desc', description: (0, ansi_colors_1.italic)(descArr.join('\n')), choices: [ prompt_1.default.choice('Catalyst-Managed Runtime', { value: 'catalyst', short: 'Catalyst-Managed Runtime' }), prompt_1.default.choice('Docker Image', { value: 'custom', short: 'Docker Image' }) ] })); if (runtimeQuestion.runtime === 'custom') { const payload = { source: yield (0, utils_1.getCustomAppSailSource)(), name: yield (0, utils_1.getAppSailName)() }; runtime_store_1.default.set('context.payload.appsail.targets', [payload]); return; } const curCommand = (0, option_1.getCurrentCommand)(); const gitPrompt = yield prompt_1.default.ask(prompt_1.default.question('gitClone', 'Do you want to get-started with a list of example AppSails?', { type: 'confirm', default: true, when: curCommand === 'init' })); const pulledSource = gitPrompt.gitClone && (yield (0, utils_1.getAppSailZip)()); const sourcePath = yield prompt_1.default.ask(prompt_1.default.question('currentDir', 'Do you want to initialize an AppSail in this directory?', { type: 'confirm', default: true, when: !pulledSource })); const _appSailConfig = sourcePath.currentDir ? { source: runtime_store_1.default.get('cwd') } : pulledSource || { source: (yield prompt_1.default.ask(prompt_1.default.question('source', "Please provide the exact path to your AppSail's source directory:", { type: 'input', validate: (pth) => __awaiter(void 0, void 0, void 0, function* () { return (0, path_1.isAbsolute)(pth) ? (yield fs_1.ASYNC.dirExists(pth)) ? true : 'Provided path does not exists' : 'Please provide an absolute path'; }) }))).source }; const payload = { source: (0, path_1.relative)((0, project_1.getProjectRoot)(), _appSailConfig.source) || '.', name: yield (0, utils_1.getAppSailName)() }; const appConfigPth = (0, path_1.join)(_appSailConfig.source, constants_1.FILENAME.app_config); const isAppConfig = yield fs_1.ASYNC.fileExists(appConfigPth); if (isAppConfig) { (0, index_1.info)(); (0, index_1.warning)(`The ${(0, ansi_colors_1.bold)(constants_1.FILENAME.app_config)} file is already present in the appsail directory`); } const overWrite = yield prompt_1.default.ask(prompt_1.default.question('appConfig', 'Do you wish to overwrite the ' + constants_1.FILENAME.app_config + '?', { type: 'confirm', default: false, when: isAppConfig })); const activeWrite = overWrite.appConfig !== false; if (!activeWrite) { runtime_store_1.default.set('context.payload.appsail.targets', [payload]); return; } const buildPath = yield prompt_1.default.ask(prompt_1.default.question('path', 'Please provide the build path of your AppSail:', { type: 'input', rootPath: _appSailConfig.source, when: !_appSailConfig.build && activeWrite })); const appSailStack = _appSailConfig.stack || (yield (0, common_1.getRuntimePromptAnswer)('Please choose a stack for your AppSail: ')); const appConfig = { command: _appSailConfig.command || 'echo Please specify the start-up command in the app-config.json file under the key command for AppSail $X_ZC_RESOURCE_NAME', build_path: _appSailConfig.build || ((0, path_1.isAbsolute)(buildPath.path) ? (0, path_1.relative)(_appSailConfig.source, buildPath.path) || '.' : buildPath.path), stack: appSailStack.runtime, env_variables: {}, memory: _appSailConfig.memory || 256, scripts: _appSailConfig.scripts || {} }; if (appSailStack.lang === 'java') { const platformQ = yield prompt_1.default.ask(prompt_1.default.question('platform', 'Please choose a platform for your AppSail: ', { type: 'list', choices: [ prompt_1.default.choice('JavaSE', { value: 'javase', short: 'JavaSE' }), prompt_1.default.choice('JavaWAR', { value: 'war', short: 'JavaWAR' }) ], when: !_appSailConfig.platform })); appConfig.platform = _appSailConfig.platform || platformQ.platform; if (appConfig.platform === 'war') { delete appConfig.command; } } runtime_store_1.default.set('context.payload.appsail.targets', [payload]); activeWrite && (yield fs_1.ASYNC.writeJSONFile(appConfigPth, appConfig)); });