@modyo/cli
Version:
Modyo CLI Command line to expose local development tools
99 lines (97 loc) • 3.36 kB
JavaScript
"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const merge_env_variables_1 = tslib_1.__importDefault(require("../push/merge-env-variables"));
const prepare_and_validate_preview_1 = tslib_1.__importDefault(require("../preview/prepare-and-validate-preview"));
const open_preview_1 = tslib_1.__importDefault(require("../preview/open-preview"));
class Preview extends core_1.Command {
async run() {
try {
await (0, merge_env_variables_1.default)();
const input = await this.parse(Preview);
const { accountUrl, domId, entryJs, port, siteHost, } = await (0, prepare_and_validate_preview_1.default)(input);
await (0, open_preview_1.default)(accountUrl, siteHost, port, domId, entryJs);
}
catch (error) {
if (error instanceof Error) {
this.error(error.message || error);
}
}
}
}
exports.default = Preview;
_a = Preview;
Preview.summary = 'Preview local widget over Modyo platform';
Preview.description = `The \`preview\` command is responsible for informing the platform about local entry points so that the widget can be rendered on the platform locally.
MODYO_VERSION=version
MODYO_TOKEN=token
MODYO_ACCOUNT_URL=account-url
MODYO_SITE_ID=siteId
MODYO_SITE_HOST=siteHost
MODYO_LOCAL_PORT=port
MODYO_LOCAL_DOM_ID=domId
MODYO_LOCAL_ENTRY_JS=entryJs
`;
Preview.examples = [
`$ modyo-cli preview
`,
];
Preview.flags = {
help: core_1.Flags.help({
char: 'h',
description: 'Output usage information',
}),
token: core_1.Flags.string({
char: 't',
description: 'Modyo Api token',
env: 'MODYO_TOKEN',
required: true,
}),
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 previewed',
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 previewed',
env: 'MODYO_SITE_HOST',
exclusive: ['site-id'],
}),
port: core_1.Flags.string({
char: 'p',
description: 'Deploy port local widget running',
env: 'MODYO_LOCAL_PORT',
default: '8080',
}),
'dom-id': core_1.Flags.string({
char: 's',
description: 'Container id of the widget',
env: 'MODYO_LOCAL_DOM_ID',
default: 'widgetName',
}),
'entry-js': core_1.Flags.string({
char: 'j',
description: 'Entry JS file of the widget',
env: 'MODYO_LOCAL_ENTRY_JS',
default: 'main.js',
}),
};