UNPKG

cli-engine

Version:
89 lines (68 loc) 2.21 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); require('cli-engine-config'); var _cliEngineCommand = require('cli-engine-command'); var _cliEngineCommand2 = _interopRequireDefault(_cliEngineCommand); var _manager = require('./manager'); var _legacy = require('./legacy'); require('./cache'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } class Plugin { constructor(out, pluginPath, cachedPlugin) { this.config = out.config; this.out = out; this.pluginPath = pluginPath; this.cachedPlugin = cachedPlugin; } get tag() { return this.pluginPath.tag; } get type() { return this.pluginPath.type; } get path() { return this.pluginPath.path; } get name() { return this.cachedPlugin.name; } get version() { return this.cachedPlugin.version; } get commands() { return this.cachedPlugin.commands; } get topics() { return this.cachedPlugin.topics; } get namespace() { return this.cachedPlugin.namespace; } async findCommand(id) { if (!id) return; let c = this.commands.find(c => c.id === id || (c.aliases || []).includes(id)); if (!c) return; let { topic, command } = c; let p = await this.pluginPath.require(); let Command = (p.commands || []).find(d => topic === d.topic && command === d.command); if (!Command) return; return typeof Command === 'function' ? Command : (0, _legacy.convertFromV5)(Command); } async findTopic(id) { let t = this.topics.find(t => t.id === id); if (!t) return; let { topic } = t; let plugin = await this.pluginPath.require(); let Topic = (plugin.topics || []).find(t => [t.topic, t.name].includes(topic)); if (!Topic && plugin.topic) Topic = (plugin.topic.topic || plugin.topic.name) === topic ? plugin.topic : ''; if (!Topic) return; return typeof Topic === 'function' ? Topic : this.buildTopic(t); } buildTopic(t) { var _class, _temp; return _temp = _class = class extends _cliEngineCommand.Topic {}, _class.topic = t.topic, _class.description = t.description, _class.hidden = t.hidden, _temp; } } exports.default = Plugin;