mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add plugin support to palette manager
This commit is contained in:
@@ -39,6 +39,8 @@ function registerPlugin(nodeSetId,id,definition) {
|
||||
pluginSettings[id] = definition.settings;
|
||||
}
|
||||
|
||||
// reset the cache when a new plugin is incoming!
|
||||
pluginConfigCache = {};
|
||||
|
||||
if (definition.onadd && typeof definition.onadd === 'function') {
|
||||
definition.onadd();
|
||||
@@ -55,29 +57,47 @@ function getPluginsByType(type) {
|
||||
}
|
||||
|
||||
function getPluginConfigs(lang) {
|
||||
// we're not re-using getPluginConfig() here,
|
||||
// to avoid calling registry.getModuleList() multiple times!
|
||||
|
||||
if (!pluginConfigCache[lang]) {
|
||||
var result = "";
|
||||
var script = "";
|
||||
var moduleConfigs = registry.getModuleList();
|
||||
for (var module in moduleConfigs) {
|
||||
/* istanbul ignore else */
|
||||
if (moduleConfigs.hasOwnProperty(module)) {
|
||||
var plugins = moduleConfigs[module].plugins;
|
||||
for (var plugin in plugins) {
|
||||
if (plugins.hasOwnProperty(plugin)) {
|
||||
var config = plugins[plugin];
|
||||
if (config.enabled && !config.err && config.config) {
|
||||
result += "\n<!-- --- [red-plugin:"+config.id+"] --- -->\n";
|
||||
result += config.config;
|
||||
}
|
||||
}
|
||||
}
|
||||
result += get_config_of_plugins(moduleConfigs[module].plugins);
|
||||
}
|
||||
}
|
||||
pluginConfigCache[lang] = result;
|
||||
}
|
||||
return pluginConfigCache[lang];
|
||||
}
|
||||
|
||||
function getPluginConfig(id, lang) {
|
||||
let result = '';
|
||||
let moduleConfigs = registry.getModuleList();
|
||||
if (moduleConfigs.hasOwnProperty(id)) {
|
||||
result = get_config_of_plugins(moduleConfigs[id].plugins);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// helper function to avoid code duplication
|
||||
function get_config_of_plugins(plugins) {
|
||||
let result = '';
|
||||
for (let plugin in plugins) {
|
||||
if (plugins.hasOwnProperty(plugin)) {
|
||||
let config = plugins[plugin];
|
||||
if (config.enabled && !config.err && config.config) {
|
||||
result += "\n<!-- --- [red-plugin:"+config.id+"] --- -->\n";
|
||||
result += config.config;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function getPluginList() {
|
||||
var list = [];
|
||||
var moduleConfigs = registry.getModuleList();
|
||||
@@ -142,12 +162,51 @@ function exportPluginSettings(safeSettings) {
|
||||
return safeSettings;
|
||||
}
|
||||
|
||||
function removeModule(moduleId) {
|
||||
|
||||
// clean the (plugin) registry when a module is removed / uninstalled
|
||||
|
||||
let pluginList = [];
|
||||
let module = registry.getModule(moduleId);
|
||||
let keys = Object.keys(module.plugins ?? {});
|
||||
keys.forEach( key => {
|
||||
let _plugins = module.plugins[key].plugins ?? [];
|
||||
_plugins.forEach( plugin => {
|
||||
let id = plugin.id;
|
||||
|
||||
if (plugin.onremove && typeof plugin.onremove === 'function') {
|
||||
plugin.onremove();
|
||||
}
|
||||
|
||||
delete pluginToId[id];
|
||||
delete plugins[id];
|
||||
delete pluginSettings[id];
|
||||
pluginConfigCache = {};
|
||||
|
||||
let psbtype = pluginsByType[plugin.type] ?? [];
|
||||
for (let i=psbtype.length; i>0; i--) {
|
||||
let pbt = psbtype[i-1];
|
||||
if (pbt.id == id) {
|
||||
psbtype.splice(i-1, 1);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
pluginList.push(registry.filterNodeInfo(module.plugins[key]));
|
||||
|
||||
})
|
||||
|
||||
return pluginList;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init,
|
||||
registerPlugin,
|
||||
getPlugin,
|
||||
getPluginsByType,
|
||||
getPluginConfigs,
|
||||
getPluginConfig,
|
||||
getPluginList,
|
||||
exportPluginSettings
|
||||
exportPluginSettings,
|
||||
removeModule
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user