add some plugin getters
This commit is contained in:
parent
289533b755
commit
509f44bcb1
|
@ -105,11 +105,10 @@ class PluginManager extends Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
async reloadPlugin(plugin) {
|
async reloadPlugin(plugin) {
|
||||||
let _plugin = this.getPluginByName(plugin);
|
const _plugin = this.findPlugin(plugin);
|
||||||
if (!_plugin) _plugin = this.plugins.find(plugin => plugin.pluginPath === plugin || plugin.dirName === plugin);
|
|
||||||
if (!_plugin) throw { 'message': 'Attempted to reload a plugin that is not loaded?' };
|
if (!_plugin) throw { 'message': 'Attempted to reload a plugin that is not loaded?' };
|
||||||
if (!_plugin.stop()) throw { 'message': 'Plugin failed to stop!' };
|
if (!_plugin.stop()) throw { 'message': 'Plugin failed to stop!' };
|
||||||
const index = this.plugins.findIndex(plugin => plugin === _plugin);
|
const index = this.getPluginIndex(_plugin);
|
||||||
const { pluginPath, dirName } = _plugin;
|
const { pluginPath, dirName } = _plugin;
|
||||||
delete window.require.cache[window.require.resolve(pluginPath)];
|
delete window.require.cache[window.require.resolve(pluginPath)];
|
||||||
|
|
||||||
|
@ -118,8 +117,22 @@ class PluginManager extends Module {
|
||||||
return this.loadPlugin(dirName);
|
return this.loadPlugin(dirName);
|
||||||
}
|
}
|
||||||
|
|
||||||
getPluginByName(name) { return this.plugins.find(plugin => plugin.name === name); }
|
//TODO make this nicer
|
||||||
getPluginById(id) { return this.plugins.find(plugin => plugin.id === id); }
|
findPlugin(wild) {
|
||||||
|
let plugin = this.getPluginByName(wild);
|
||||||
|
if (plugin) return plugin;
|
||||||
|
plugin = this.getPluginById(wild);
|
||||||
|
if (plugin) return plugin;
|
||||||
|
plugin = this.getPluginByPath(wild);
|
||||||
|
if (plugin) return plugin;
|
||||||
|
return this.getPluginByDirName(wild);
|
||||||
|
}
|
||||||
|
|
||||||
|
getPluginIndex(plugin) { return this.plugins.findIndex(p => p === plugin) }
|
||||||
|
getPluginByName(name) { return this.plugins.find(p => p.name === name) }
|
||||||
|
getPluginById(id) { return this.plugins.find(p => p.id === id) }
|
||||||
|
getPluginByPath(path) { return this.plugins.find(p => p.pluginPath === path) }
|
||||||
|
getPluginByDirName(dirName) { return this.plugins.find(p => p.dirName === dirName) }
|
||||||
|
|
||||||
stopPlugin(name) {
|
stopPlugin(name) {
|
||||||
const plugin = this.getPluginByName(name);
|
const plugin = this.getPluginByName(name);
|
||||||
|
|
Loading…
Reference in New Issue