UNPKG

cli-engine

Version:
60 lines (48 loc) 1.78 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _cliEngineCommand = require('cli-engine-command'); var _cliEngineCommand2 = _interopRequireDefault(_cliEngineCommand); var _plugins = require('../../plugins'); var _plugins2 = _interopRequireDefault(_plugins); var _hooks = require('../../hooks'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } let examplePlugin = 'heroku-production-status'; let cli = 'heroku'; if (global.config) { cli = global.config.bin; let pjson = global.config.pjson['cli-engine']; if (pjson['help'] && pjson['help']['plugins']) { examplePlugin = Object.keys(pjson['help']['plugins'])[0]; } } class PluginsInstall extends _cliEngineCommand2.default { async run() { this.plugins = new _plugins2.default(this.config); const [plugin, tag = 'latest'] = this.parsePlugin(this.argv[0]); if (!this.config.debug) this.out.action.start(`Installing plugin ${plugin}${tag === 'latest' ? '' : '@' + tag}`); await this.plugins.install(plugin, tag); const hooks = new _hooks.Hooks({ config: this.config }); await hooks.run('update'); } parsePlugin(input) { if (input.includes('/')) { input = input.slice(1); let [name, tag = 'latest'] = input.split('@'); return ['@' + name, tag]; } else { let [name, tag = 'latest'] = input.split('@'); return [name, tag]; } } } exports.default = PluginsInstall; PluginsInstall.topic = 'plugins'; PluginsInstall.command = 'install'; PluginsInstall.description = 'installs a plugin into the CLI'; PluginsInstall.help = ` Example: $ ${cli} plugins:install ${examplePlugin} `; PluginsInstall.args = [{ name: 'plugin', description: 'plugin to install' }];