@malysus/node-red-contrib-flow-splitter-extended 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +37 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -617,6 +617,37 @@ async function manualReload(req, res) {
|
|
|
617
617
|
}
|
|
618
618
|
}
|
|
619
619
|
|
|
620
|
+
/**
|
|
621
|
+
* Node-RED keeps ONE global-config node (global env vars, palette modules),
|
|
622
|
+
* but nothing stops an editor plugin from adding a second one: the folders
|
|
623
|
+
* plugin creates its own when it saves before the flows are loaded. Every
|
|
624
|
+
* copy then lands in config-nodes/, comes back on the next rebuild and the
|
|
625
|
+
* pile grows with each editor session. Keep the first one and fold the
|
|
626
|
+
* others into it: for an env name present twice the first value wins, which
|
|
627
|
+
* is also the copy the folders plugin reads.
|
|
628
|
+
* @param {Array} flowNodes - Array of all flow nodes from Node-RED
|
|
629
|
+
* @returns {Array} flowNodes with at most one global-config node
|
|
630
|
+
*/
|
|
631
|
+
function mergeGlobalConfigs(flowNodes) {
|
|
632
|
+
const configs = flowNodes.filter(node => node.type === 'global-config')
|
|
633
|
+
if (configs.length < 2) return flowNodes
|
|
634
|
+
const [first, ...others] = configs
|
|
635
|
+
const env = [...(first.env || [])]
|
|
636
|
+
const modules = { ...(first.modules || {}) }
|
|
637
|
+
for (const other of others) {
|
|
638
|
+
for (const item of other.env || []) {
|
|
639
|
+
if (!env.some(e => e.name === item.name)) env.push(item)
|
|
640
|
+
}
|
|
641
|
+
for (const [name, version] of Object.entries(other.modules || {})) {
|
|
642
|
+
if (!(name in modules)) modules[name] = version
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
RED.log.warn(`[node-red-contrib-flow-splitter-extended] ${configs.length} global-config nodes found, kept ${first.id} in the split files. Remove the extra ones from the editor (${others.map(n => n.id).join(', ')}).`)
|
|
646
|
+
const merged = { ...first, env, modules }
|
|
647
|
+
const dropped = new Set(others.map(n => n.id))
|
|
648
|
+
return flowNodes.filter(node => !dropped.has(node.id)).map(node => node === first ? merged : node)
|
|
649
|
+
}
|
|
650
|
+
|
|
620
651
|
/**
|
|
621
652
|
* Main function executed on each flow restart
|
|
622
653
|
* @param {FlowStartedEventType} flowEventData
|
|
@@ -686,21 +717,22 @@ async function onFlowReload(flowEventData) {
|
|
|
686
717
|
}
|
|
687
718
|
|
|
688
719
|
// Flows exist - split into source files
|
|
720
|
+
const flows = mergeGlobalConfigs(flowEventData.config.flows)
|
|
689
721
|
|
|
690
722
|
let updatedCfg
|
|
691
723
|
if (cfg.fileFormat === 'json' && cfg.fastJsonSplit !== false) {
|
|
692
|
-
updatedCfg = fastJsonTree(
|
|
724
|
+
updatedCfg = fastJsonTree(flows, cfg, projectPath)
|
|
693
725
|
} else {
|
|
694
726
|
let flowSet
|
|
695
727
|
// Guarantee a label/name to avoid a crash inside flows-file-manager's
|
|
696
728
|
// disambiguate() (see ensureFlowIdentifiers doc above)
|
|
697
729
|
try {
|
|
698
|
-
flowSet = manager.constructFlowSetFromMonolithObject(ensureFlowIdentifiers(
|
|
730
|
+
flowSet = manager.constructFlowSetFromMonolithObject(ensureFlowIdentifiers(flows))
|
|
699
731
|
} catch (error) {
|
|
700
732
|
RED.log.error(`[node-red-contrib-flow-splitter-extended] Failed to build FlowSet from monolith object (flows-file-manager error): ${error.message}`)
|
|
701
733
|
return
|
|
702
734
|
}
|
|
703
|
-
cleanFlowSet(flowSet,
|
|
735
|
+
cleanFlowSet(flowSet, flows)
|
|
704
736
|
updatedCfg = constructTreeFilesIncrementally(flowSet, cfg, projectPath)
|
|
705
737
|
}
|
|
706
738
|
writeSplitterConfig(updatedCfg, projectPath)
|
|
@@ -712,10 +744,10 @@ async function onFlowReload(flowEventData) {
|
|
|
712
744
|
// cheaper than JSON.stringify-ing the complete flow again.
|
|
713
745
|
writeMonolithArtifact(updatedCfg, projectPath)
|
|
714
746
|
|
|
715
|
-
const extractionFingerprint = getExtractionFingerprint(
|
|
747
|
+
const extractionFingerprint = getExtractionFingerprint(flows)
|
|
716
748
|
if (extractionFingerprint !== lastExtractionFingerprint) {
|
|
717
749
|
if (cfg.fileFormat === 'json' && cfg.fastJsonSplit !== false) {
|
|
718
|
-
extractFunctionsTemplatesFromRawFlow(updatedCfg, projectPath,
|
|
750
|
+
extractFunctionsTemplatesFromRawFlow(updatedCfg, projectPath, flows)
|
|
719
751
|
} else {
|
|
720
752
|
extractFunctionsTemplatesFromSplitFiles(updatedCfg, projectPath)
|
|
721
753
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malysus/node-red-contrib-flow-splitter-extended",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Split your flows.json file in individual YAML or JSON files (per tab, subflow and config-node) with optional function and ui-template node code extraction.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|