kibana-with-account
Version:
kibana-with-account is develop based kibana project
54 lines (38 loc) • 1.21 kB
JavaScript
let { get, indexBy } = require('lodash');
let inspect = require('util').inspect;
let PluginApi = require('./PluginApi');
let Collection = require('requirefrom')('src')('utils/Collection');
let byIdCache = Symbol('byIdCache');
let pluginApis = Symbol('pluginApis');
module.exports = class Plugins extends Collection {
constructor(kbnServer) {
super();
this.kbnServer = kbnServer;
this[pluginApis] = new Set();
}
async new(path) {
let api = new PluginApi(this.kbnServer, path);
this[pluginApis].add(api);
let output = [].concat(require(path)(api) || []);
let config = this.kbnServer.config;
if (!output.length) return;
// clear the byIdCache
this[byIdCache] = null;
for (let product of output) {
if (product instanceof api.Plugin) {
let plugin = product;
this.add(plugin);
let enabled = await plugin.readConfig();
if (!enabled) this.delete(plugin);
continue;
}
throw new TypeError('unexpected plugin export ' + inspect(product));
}
}
get byId() {
return this[byIdCache] || (this[byIdCache] = indexBy([...this], 'id'));
}
getPluginApis() {
return this[pluginApis];
}
};