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:
@@ -319,6 +319,7 @@ module.exports = {
|
||||
getPluginsByType: plugins.getPluginsByType,
|
||||
getPluginList: plugins.getPluginList,
|
||||
getPluginConfigs: plugins.getPluginConfigs,
|
||||
getPluginConfig: plugins.getPluginConfig,
|
||||
exportPluginSettings: plugins.exportPluginSettings,
|
||||
|
||||
|
||||
|
@@ -28,6 +28,8 @@ const child_process = require('child_process');
|
||||
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
||||
let installerEnabled = false;
|
||||
|
||||
const plugins = require("./plugins");
|
||||
|
||||
let settings;
|
||||
const moduleRe = /^(@[^/@]+?[/])?[^/@]+?$/;
|
||||
const slashRe = process.platform === "win32" ? /\\|[/]/ : /[/]/;
|
||||
@@ -330,10 +332,18 @@ function reportRemovedModules(removedNodes) {
|
||||
//comms.publish("node/removed",removedNodes,false);
|
||||
log.info(log._("server.removed-types"));
|
||||
for (var j=0;j<removedNodes.length;j++) {
|
||||
for (var i=0;i<removedNodes[j].types.length;i++) {
|
||||
for (var i=0;i<removedNodes[j].types?.length;i++) {
|
||||
log.info(" - "+(removedNodes[j].module?removedNodes[j].module+":":"")+removedNodes[j].types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
log.info(log._("server.removed-plugins"));
|
||||
for (let j=0;j<removedNodes.length;j++) {
|
||||
for (var i=0;i<removedNodes[j].plugins?.length;i++) {
|
||||
log.info(" - "+(removedNodes[j].module?removedNodes[j].module+":":"")+removedNodes[j].plugins[i].id);
|
||||
}
|
||||
}
|
||||
|
||||
return removedNodes;
|
||||
}
|
||||
|
||||
@@ -495,8 +505,12 @@ function uninstallModule(module) {
|
||||
} catch(err) {
|
||||
return reject(new Error(log._("server.install.uninstall-failed",{name:module})));
|
||||
}
|
||||
|
||||
// need to remove the plugins first,
|
||||
// as registry data necessary to perform this operation
|
||||
var list = plugins.removeModule(module);
|
||||
list = list.concat(registry.removeModule(module));
|
||||
|
||||
var list = registry.removeModule(module);
|
||||
log.info(log._("server.install.uninstalling",{name:module}));
|
||||
|
||||
let triggerPayload = {
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -386,7 +386,8 @@ function getModuleInfo(module) {
|
||||
local: moduleConfigs[module].local,
|
||||
user: moduleConfigs[module].user,
|
||||
path: moduleConfigs[module].path,
|
||||
nodes: []
|
||||
nodes: [],
|
||||
plugins: []
|
||||
};
|
||||
if (moduleConfigs[module].dependencies) {
|
||||
m.dependencies = moduleConfigs[module].dependencies;
|
||||
@@ -399,6 +400,14 @@ function getModuleInfo(module) {
|
||||
nodeInfo.version = m.version;
|
||||
m.nodes.push(nodeInfo);
|
||||
}
|
||||
|
||||
let plugins = Object.values(moduleConfigs[module].plugins);
|
||||
plugins.forEach((plugin) => {
|
||||
let nodeInfo = filterNodeInfo(plugin);
|
||||
nodeInfo.version = m.version;
|
||||
m.plugins.push(nodeInfo);
|
||||
});
|
||||
|
||||
return m;
|
||||
} else {
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user