UNPKG

@modyo/cli

Version:

Modyo CLI Command line to expose local development tools

195 lines (191 loc) 7.32 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const core_1 = require("@oclif/core"); const axios_1 = require("axios"); const merge_env_variables_1 = tslib_1.__importDefault(require("../push/merge-env-variables")); const process_widget_1 = tslib_1.__importDefault(require("../push/process-widget")); const upload_widget_1 = tslib_1.__importDefault(require("../push/upload-widget")); const prepare_and_validate_params_1 = tslib_1.__importDefault(require("../push/prepare-and-validate-params")); const check_widget_1 = tslib_1.__importDefault(require("../push/check-widget")); class PUSH extends core_1.Command { async run() { await (0, merge_env_variables_1.default)(); const input = await this.parse(PUSH); const params = await (0, prepare_and_validate_params_1.default)(input); await (0, check_widget_1.default)(params.buildDirectory, params.buildCommand); const resources = await (0, process_widget_1.default)(params); this.debug('pushing widget'); await (0, upload_widget_1.default)(params.name, resources, { version: params.version, accountUrl: params.accountUrl, siteId: params.siteId, token: params.token, }, { publish: params.publish }); this.log('widget pushed'); } /** * Handles errors thrown during execution of this command. * * This method is invoked by oclif when {@link run} (or other command lifecycle * methods) throws an error or returns a rejected promise. It provides * specialized handling for: * * - Axios errors: formats and reports the Modyo API error response (if * available) before exiting the process. * - {@link Errors.CLIError} instances with a non-zero exit code: rethrows the * error via {@link this.error} while preserving the intended exit code. * * All other errors are delegated to {@link Command.catch} via * {@link super.catch}. * * @param error The error encountered while running the push command. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any async catch(error) { var _b, _c; if ((0, axios_1.isAxiosError)(error)) { const errorMessage = ((_b = error.response) === null || _b === void 0 ? void 0 : _b.data) ? JSON.stringify(error.response.data, null, 2) : error.message; return this.error(`Modyo API Error: ${errorMessage}`); } if (error instanceof core_1.Errors.CLIError) { const exit = (_c = error.oclif) === null || _c === void 0 ? void 0 : _c.exit; if (typeof exit === 'number' && exit !== 0) { return this.error(error.message, { exit }); } } return super.catch(error); } } exports.default = PUSH; _a = PUSH; PUSH.summary = 'Push widget to Modyo platform'; PUSH.description = `The \`push\` command is the one in charge of the integration principle, used to send the widget to the selected site in the modyo platform. It will use an argument called name to upload the widget to the platform and some required flags like token site_base id or host to can identify the ®Modyo platform which host the widget and have an additional flag to avoid the manual process flow of widget publication. Many of the options can be defined as environment variables or inside an .env file that is recommended to avoid the publication to the GitHub registry because can contain some delicate information MODYO_BUILD_DIRECTORY=buildDirectoryPath MODYO_VERSION=version MODYO_TOKEN=token MODYO_ACCOUNT_URL=account-url MODYO_SITE_ID=siteId MODYO_SITE_HOST=siteHost MODYO_BUILD_COMMAND=buildCommand MODYO_REGEX_EXCLUDE=regexToExcludeFiles MODYO_DISABLE_LIQUID_REGEX=regexToDisableLiquidOnFiles MODYO_ZIP=true MODYO_ZIP_ENTRY_JS=main.js MODYO_ZIP_ENTRY_CSS=main.css `; PUSH.examples = [ `$ modyo-cli push `, ]; PUSH.flags = { token: core_1.Flags.string({ char: 't', description: 'Modyo Api token', env: 'MODYO_TOKEN', required: true, }), publish: core_1.Flags.boolean({ char: 'p', description: 'Force widget publication', default: false, }), help: core_1.Flags.help({ char: 'h', description: 'Output usage information', }), 'build-directory': core_1.Flags.string({ char: 'd', description: 'Build directory path', env: 'MODYO_BUILD_DIRECTORY', default: 'dist', }), version: core_1.Flags.string({ char: 'v', description: 'Version of Modyo platform', options: ['8', '9', '10'], env: 'MODYO_VERSION', default: '9', parse: async (input) => ((input === '8' || input === '9' || input === '10') ? input : '9'), }), 'account-url': core_1.Flags.string({ char: 'u', description: 'URL of your ®Modyo account ex("https://account.modyo.com")', env: 'MODYO_ACCOUNT_URL', required: true, parse: async (input) => (/\/$/.test(input) ? input.replace(/\/$/, '') : input), }), 'site-id': core_1.Flags.string({ char: 'i', description: 'Id of the site where the widget will be push', env: 'MODYO_SITE_ID', exclusive: ['site-host'], }), 'site-host': core_1.Flags.string({ char: 'n', description: 'Host of the site where the widget will be push', env: 'MODYO_SITE_HOST', exclusive: ['site-id'], }), 'build-command': core_1.Flags.string({ char: 'b', description: 'Build command in package.json', env: 'MODYO_BUILD_COMMAND', default: 'build', }), 'regex-exclude': core_1.Flags.string({ char: 'r', description: 'Exclude file that match a regex', hidden: true, env: 'MODYO_REGEX_EXCLUDE', default: 'preview_script.js', }), 'remove-emojis': core_1.Flags.boolean({ char: 'e', description: 'Remove emojis from the widget that will be push ', default: true, allowNo: true, }), 'disable-liquid': core_1.Flags.boolean({ char: 'l', description: 'Disable liquid on all files', default: false, exclusive: ['disable-liquid-regex'], }), 'disable-liquid-regex': core_1.Flags.string({ char: 'f', description: 'Disable liquid on files that match a regex', exclusive: ['disable-liquid'], env: 'MODYO_DISABLE_LIQUID_REGEX', }), zip: core_1.Flags.boolean({ char: 'z', description: 'Zip bundle to publish', env: 'MODYO_ZIP', default: false, }), 'zip-entry-js': core_1.Flags.string({ char: 'j', description: 'Entry js file when use --zip flag', default: 'main.js', env: 'MODYO_ZIP_ENTRY_JS', }), 'zip-entry-css': core_1.Flags.string({ char: 'c', description: 'Entry css file when use --zip flag', default: 'main.css', env: 'MODYO_ZIP_ENTRY_CSS', }), }; PUSH.args = { name: core_1.Args.string({ description: 'The name of the widget', required: false, env: 'MODYO_WIDGET_NAME', }), };