Include module list in global-config node when exporting flows

This commit is contained in:
Nick O'Leary 2024-03-08 15:52:47 +00:00
parent 80e60538e2
commit 6d5948b56e
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
5 changed files with 47 additions and 12 deletions

View File

@ -1428,7 +1428,12 @@ RED.nodes = (function() {
/** /**
* Converts the current node selection to an exportable JSON Object * Converts the current node selection to an exportable JSON Object
**/ **/
function createExportableNodeSet(set, exportedIds, exportedSubflows, exportedConfigNodes) { function createExportableNodeSet(set, {
exportedIds,
exportedSubflows,
exportedConfigNodes,
includeModuleConfig = false
} = {}) {
var nns = []; var nns = [];
exportedIds = exportedIds || {}; exportedIds = exportedIds || {};
@ -1462,7 +1467,7 @@ RED.nodes = (function() {
subflowSet = subflowSet.concat(RED.nodes.junctions(subflowId)) subflowSet = subflowSet.concat(RED.nodes.junctions(subflowId))
subflowSet = subflowSet.concat(RED.nodes.groups(subflowId)) subflowSet = subflowSet.concat(RED.nodes.groups(subflowId))
var exportableSubflow = createExportableNodeSet(subflowSet, exportedIds, exportedSubflows, exportedConfigNodes); var exportableSubflow = createExportableNodeSet(subflowSet, { exportedIds, exportedSubflows, exportedConfigNodes });
nns = exportableSubflow.concat(nns); nns = exportableSubflow.concat(nns);
} }
} }
@ -1497,13 +1502,16 @@ RED.nodes = (function() {
} }
nns.push(convertedNode); nns.push(convertedNode);
if (node.type === "group") { if (node.type === "group") {
nns = nns.concat(createExportableNodeSet(node.nodes, exportedIds, exportedSubflows, exportedConfigNodes)); nns = nns.concat(createExportableNodeSet(node.nodes, { exportedIds, exportedSubflows, exportedConfigNodes }));
} }
} else { } else {
var convertedSubflow = convertSubflow(node, { credentials: false }); var convertedSubflow = convertSubflow(node, { credentials: false });
nns.push(convertedSubflow); nns.push(convertedSubflow);
} }
} }
if (includeModuleConfig) {
updateGlobalConfigModuleList(nns)
}
return nns; return nns;
} }
@ -1541,6 +1549,7 @@ RED.nodes = (function() {
RED.nodes.eachNode(function(n) { RED.nodes.eachNode(function(n) {
nns.push(convertNode(n, opts)); nns.push(convertNode(n, opts));
}) })
updateGlobalConfigModuleList(nns)
return nns; return nns;
} }
@ -2886,7 +2895,33 @@ RED.nodes = (function() {
} }
} }
} }
function getModuleListForNodes(nodes) {
const modules = {}
nodes.forEach(n => {
const nodeSet = RED.nodes.registry.getNodeSetForType(n.type)
if (nodeSet) {
modules[nodeSet.module] = nodeSet.version
}
})
return modules
}
function updateGlobalConfigModuleList(nodes) {
const modules = getModuleListForNodes(nodes)
delete modules['node-red']
const hasModules = (Object.keys(modules).length > 0)
let globalConfigNode = nodes.find(n => n.type === 'global-config')
if (!globalConfigNode && hasModules) {
globalConfigNode = {
id: RED.nodes.id(),
type: 'global-config',
env: [],
modules
}
nodes.push(globalConfigNode)
} else if (globalConfigNode) {
globalConfigNode.modules = modules
}
}
return { return {
init: function() { init: function() {
RED.events.on("registry:node-type-added",function(type) { RED.events.on("registry:node-type-added",function(type) {

View File

@ -714,7 +714,7 @@ RED.clipboard = (function() {
nodes = RED.view.selection().nodes||[]; nodes = RED.view.selection().nodes||[];
} }
// Don't include the subflow meta-port nodes in the exported selection // Don't include the subflow meta-port nodes in the exported selection
nodes = RED.nodes.createExportableNodeSet(nodes.filter(function(n) { return n.type !== 'subflow'})); nodes = RED.nodes.createExportableNodeSet(nodes.filter(function(n) { return n.type !== 'subflow'}), { includeModuleConfig: true });
} else if (type === 'flow') { } else if (type === 'flow') {
var activeWorkspace = RED.workspaces.active(); var activeWorkspace = RED.workspaces.active();
nodes = RED.nodes.groups(activeWorkspace); nodes = RED.nodes.groups(activeWorkspace);
@ -729,7 +729,7 @@ RED.clipboard = (function() {
}); });
var parentNode = RED.nodes.workspace(activeWorkspace)||RED.nodes.subflow(activeWorkspace); var parentNode = RED.nodes.workspace(activeWorkspace)||RED.nodes.subflow(activeWorkspace);
nodes.unshift(parentNode); nodes.unshift(parentNode);
nodes = RED.nodes.createExportableNodeSet(nodes); nodes = RED.nodes.createExportableNodeSet(nodes, { includeModuleConfig: true });
} else if (type === 'full') { } else if (type === 'full') {
nodes = RED.nodes.createCompleteNodeSet({ credentials: false }); nodes = RED.nodes.createCompleteNodeSet({ credentials: false });
} }
@ -832,7 +832,7 @@ RED.clipboard = (function() {
children: [] children: []
}; };
treeSubflows.push(subflows[node.id]) treeSubflows.push(subflows[node.id])
} else { } else if (node.type !== 'global-config') {
nodes.push(node); nodes.push(node);
} }
}); });

View File

@ -33,8 +33,7 @@ RED.envVar = (function() {
id: RED.nodes.id(), id: RED.nodes.id(),
type: "global-config", type: "global-config",
env: [], env: [],
name: "global-config", modules: {},
label: "",
hasUsers: false, hasUsers: false,
users: [], users: [],
credentials: cred, credentials: cred,

View File

@ -5801,8 +5801,8 @@ RED.view = (function() {
if (globalConfig) { if (globalConfig) {
// merge global env to existing global-config // merge global env to existing global-config
var env0 = gconf.env; var env0 = gconf.env || [];
var env1 = globalConfig.env; var env1 = globalConfig.env || []
var newEnv = Array.from(env0); var newEnv = Array.from(env0);
var changed = false; var changed = false;

View File

@ -11,12 +11,13 @@
RED.nodes.registerType('global-config',{ RED.nodes.registerType('global-config',{
category: 'config', category: 'config',
defaults: { defaults: {
name: { value: "" },
env: { value: [] }, env: { value: [] },
modules: { value: {} }
}, },
credentials: { credentials: {
map: { type: "map" } map: { type: "map" }
}, },
label: 'global-config',
oneditprepare: function() { oneditprepare: function() {
$('#node-input-edit-env-var').on('click', function(evt) { $('#node-input-edit-env-var').on('click', function(evt) {
RED.actions.invoke('core:show-user-settings', 'envvar') RED.actions.invoke('core:show-user-settings', 'envvar')