UNPKG

jovo-cli

Version:
164 lines 6.59 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); const jovo_cli_core_1 = require("jovo-cli-core"); const Listr = require("listr"); const _ = __importStar(require("lodash")); const utils_1 = require("../utils"); const Prompts_1 = require("../utils/Prompts"); const Tasks_1 = require("../utils/Tasks"); const chalk_1 = __importDefault(require("chalk")); class Get extends command_1.Command { async run() { try { utils_1.platforms.addCliOptions('get', Get.flags); utils_1.addBaseCliOptions(Get.flags); const { args, flags } = this.parse(Get); if (!utils_1.platforms.validateCliOptions('get', flags)) { return; } this.log(`\n jovo get: ${Get.description}`); this.log(chalk_1.default.grey(' >> Learn more: https://jovo.tech/docs/cli/get\n')); const project = jovo_cli_core_1.getProject(); await project.init(); const types = []; if (args.platform) { types.push(args.platform); } else { types.push(...utils_1.platforms.getAll(args.platform, flags.stage)); } const tasks = new Listr([], { renderer: new utils_1.JovoCliRenderer(), collapse: false, }); try { project.getConfig(flags.stage); } catch (err) { if (err instanceof jovo_cli_core_1.JovoCliError) { throw err; } throw new jovo_cli_core_1.JovoCliError(err.message, 'jovo-cli'); } const config = { types, debug: flags.debug, }; for (const type of config.types) { const platform = utils_1.platforms.get(type, config.stage); let platformConfigIds = platform.getPlatformConfigIds(project, {}); if (!flags.overwrite && Object.keys(platformConfigIds).length > 0) { const { overwrite } = await Prompts_1.promptOverwriteProjectFiles(); if (overwrite === Prompts_1.ANSWER_CANCEL) { return; } } platformConfigIds = platform.getPlatformConfigIds(project, flags); _.merge(config, platformConfigIds); _.merge(config, platform.getPlatformConfigValues(project, flags)); _.merge(config, { locales: project.getLocales(flags.locale), targets: project.getTargets('get', flags.target, flags.stage), stage: project.getStage(flags.stage), }); if (Object.keys(platformConfigIds).length === 0) { const choices = await platform.getExistingProjects(config); const answers = await Prompts_1.promptListForProjectId(choices); config[platform.constructor.ID_KEY] = answers.id; } if (flags.reverse) { try { config.locales = platform.getLocales(flags.locale); } catch (err) { config.locales = undefined; } if (flags.overwrite) { config.reverse = true; } else if (project.hasModelFiles(config.locales)) { const answers = await Prompts_1.promptOverwriteReverseBuild(); if (answers.promptOverwriteReverseBuild === Prompts_1.ANSWER_CANCEL) { return; } else { config.reverse = answers.promptOverwriteReverseBuild; } } } for (const task of Tasks_1.getTask(config)) { tasks.add(task); } } if (flags.build && flags.reverse) { tasks.add({ title: 'Building language model platform model...', task(ctx) { return Tasks_1.buildReverseTask(ctx); }, }); } await tasks.run(config); this.log(); this.log(' Build completed.'); this.log(); } catch (err) { this.error(`There was a problem:\n${err}`); } } } exports.Get = Get; Get.description = 'Downloads an existing platform project into the platforms folder.'; Get.examples = [ 'jovo get alexaSkill --skill-id amzn1.ask.skill.xxxxxxxx', 'jovo get googleAction --project-id testproject-xxxxxx', ]; Get.flags = { locale: command_1.flags.string({ char: 'l', description: 'Locale of the language model.\n<en-US|de-DE|etc>', }), target: command_1.flags.string({ char: 't', description: 'Target of build.', options: [ jovo_cli_core_1.TARGET_ALL, jovo_cli_core_1.TARGET_INFO, jovo_cli_core_1.TARGET_MODEL, jovo_cli_core_1.TARGET_ZIP, ...utils_1.deployTargets.getAllPluginTargets(), ], }), stage: command_1.flags.string({ description: 'Takes configuration from specified stage.', }), build: command_1.flags.boolean({ description: 'Runs build after get. Works only with --reverse.', char: 'b', }), reverse: command_1.flags.boolean({ char: 'r', description: 'Builds Jovo language model from platfrom specific language model.', }), overwrite: command_1.flags.boolean({ description: 'Forces overwrite of existing project.', }), debug: command_1.flags.boolean({ hidden: true, default: false, }), }; Get.args = [{ name: 'platform', options: utils_1.platforms.getAllAvailable(), required: true }]; //# sourceMappingURL=get.js.map