UNPKG

jovo-cli

Version:
202 lines 8.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); const chalk_1 = __importDefault(require("chalk")); const jovo_cli_core_1 = require("jovo-cli-core"); const Listr = require("listr"); const _ = __importStar(require("lodash")); const utils_1 = require("../utils"); const Tasks_1 = require("../utils/Tasks"); const { buildReverseTask } = utils_1.tasks; const { isValidLocale, isValidPlatform } = utils_1.validators; const { promptForPlatforms, promptOverwriteReverseBuild, ANSWER_CANCEL } = utils_1.prompts; class Build extends command_1.Command { async run() { try { utils_1.platforms.addCliOptions('build', Build.flags); utils_1.addBaseCliOptions(Build.flags); const { flags } = this.parse(Build); if (!utils_1.platforms.validateCliOptions('build', flags)) { return; } if (!isValidLocale(flags.locale) || !isValidPlatform(flags.platform)) { return; } if (flags.overwrite) { this.warn('Flag --overwrite is deprecated. Consider using --clean instead.'); } this.log(`\n jovo build: ${Build.description}`); this.log(chalk_1.default.grey(' >> Learn more: https://jovo.tech/docs/cli/build\n')); const project = jovo_cli_core_1.getProject(); await project.init(); const tasks = new Listr([], { renderer: new utils_1.JovoCliRenderer(), collapse: false, seperateTopTasks: true, }); try { project.getConfig(flags.stage); } catch (err) { if (flags.debug) { this.log(err); } throw new jovo_cli_core_1.JovoCliError(`Could not load ${project.getConfigFileName()}.`, 'jovo-cli'); } const types = flags.platform ? [flags.platform] : utils_1.platforms.getAll(flags.platform, flags.stage); const config = { types, locales: project.getLocales(flags.locale), projectId: flags['project-id'] || project.jovoConfigReader.getConfigParameter('googleAction.dialogflow.projectId', flags.stage), endpoint: flags.endpoint || jovo_cli_core_1.DEFAULT_ENDPOINT, targets: project.getTargets('deploy', flags.target, flags.stage), src: flags.src || project.jovoConfigReader.getConfigParameter('src', flags.stage) || project.getProjectPath(), stage: project.getStage(flags.stage), debug: flags.debug, frameworkVersion: project.frameworkVersion, ignoreTasks: [flags.ignore], }; if (!project.hasConfigFile()) { throw new jovo_cli_core_1.JovoCliError(`The "${project.getConfigPath()}" file is missing or invalid!`, 'jovo-cli'); } if (config.types.length !== 1 && flags.reverse) { const { platform } = await promptForPlatforms('Please select the platform you want to reverse build from:'); config.types = [platform]; } for (const type of config.types) { const platform = utils_1.platforms.get(type, config.stage); _.merge(config, platform.getPlatformConfigValues(project, flags)); if (flags.reverse) { config.locales = platform.getLocales(flags.locale); if (flags.force) { config.reverse = true; } else if (project.hasModelFiles(config.locales)) { const answer = await promptOverwriteReverseBuild(); if (answer.promptOverwriteReverseBuild === ANSWER_CANCEL) { return; } config.reverse = answer.promptOverwriteReverseBuild; } } } if (flags.clean) { for (const type of types) { if (type === 'bixbyCapsule') { continue; } const platformsPath = `${project.getPlatformsPath()}/${type}`; utils_1.deleteFolderRecursive(platformsPath); } } if (flags.reverse) { tasks.add({ title: 'Building language model platform model', task(ctx) { return buildReverseTask(ctx); }, }); } else { for (const task of Tasks_1.buildTask(config)) { tasks.add(task); } if (flags.deploy) { tasks.add({ title: 'Deploying project...', task(ctx) { return new Listr(Tasks_1.deployTask(ctx)); }, }); } } await tasks.run(config); this.log(); this.log(' Build completed.'); this.log(); } catch (err) { this.error(`There was a problem:\n${err}`); } } } exports.Build = Build; Build.description = 'Build platform-specific language models based on jovo models folder.'; Build.examples = ['jovo build --platform alexaSkill', 'jovo build --target zip']; Build.flags = { locale: command_1.flags.string({ char: 'l', description: 'Locale of the language model.\n<en-US|de-DE|etc>', }), platform: command_1.flags.string({ char: 'p', description: 'Specifies a build platform.', options: utils_1.platforms.getAllAvailable(), }), deploy: command_1.flags.boolean({ char: 'd', description: 'Runs deploy after build.', }), reverse: command_1.flags.boolean({ char: 'r', description: 'Builds Jovo language model from platform specific language model.', }), 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(), ], }), src: command_1.flags.string({ char: 's', description: 'Path to source files.\n Default: <project directory>', }), stage: command_1.flags.string({ description: 'Takes configuration from specified stage.', }), endpoint: command_1.flags.string({ description: 'Type of endpoint.', options: ['jovo-webhook', 'ngrok', 'none'], default: 'jovo-webhook', }), force: command_1.flags.boolean({ description: 'Forces overwrite of existing project for reverse build.', }), overwrite: command_1.flags.boolean({ description: 'Forces overwrite of existing project for reverse build.', hidden: true, }), ignore: command_1.flags.string({ description: 'Task which should be ignored.', options: ['model-validation', 'none'], default: 'none', }), clean: command_1.flags.boolean({ description: 'Deletes all platform folders and executes a clean build. If --platform is specified, it deletes only the respective platforms folder.', }), debug: command_1.flags.boolean({ hidden: true, default: false, }), }; //# sourceMappingURL=build.js.map