@vdwpsmt/node-red-contrib-flow-splitter-extended 1.0.1 → 1.0.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.
Files changed (3) hide show
  1. package/README.md +3 -1
  2. package/index.js +43 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -130,7 +130,8 @@ Default configuration file =
130
130
  "destinationFolder": "src",
131
131
  "tabsOrder": [],
132
132
  "extractFunctionsTemplates": true,
133
- "restoreFunctionsTemplates": false
133
+ "restoreFunctionsTemplates": false,
134
+ "enableArtifact": false
134
135
  }
135
136
  ```
136
137
 
@@ -140,6 +141,7 @@ You can freely edit the config file, the changes are taken into account at the n
140
141
  - `destinationFolder`: path where to create the `tabs`, `subflows` and `config-nodes` sub-directories
141
142
  - `tabsOrder`: position of each tab (ordered array of the Ids of each tab node)
142
143
  - `extractFunctionsTemplates`: additional extraction of function and ui-template nodes
144
+ - `enableArtifact`: when `true`, writes a deployable monolith artifact to `artifact/flows.json` on reload/start events
143
145
  ## Installation
144
146
 
145
147
  ```bash
package/index.js CHANGED
@@ -25,13 +25,16 @@ const functionsTemplatesHandler = require('./functions-templates-handler')
25
25
  let RED
26
26
 
27
27
  const splitCfgFilename = '.config.flow-splitter.json'
28
+ const artifactsDirname = 'artifact'
29
+ const artifactsFilename = 'flows.json'
28
30
  const DEFAULT_CFG = {
29
31
  fileFormat: 'yaml',
30
32
  destinationFolder: 'src',
31
33
  tabsOrder: [],
32
34
  monolithFilename: "flows.json",
33
35
  extractFunctionsTemplates: true,
34
- restoreFunctionsTemplates: false
36
+ restoreFunctionsTemplates: false,
37
+ enableArtifact: false
35
38
  }
36
39
 
37
40
  /**
@@ -358,6 +361,42 @@ function restoreIntoFlowDirectory(dir, fileFormat, flowType) {
358
361
  })
359
362
  }
360
363
 
364
+ /**
365
+ * Write a monolith artifact file to artifact/flows.json when enabled.
366
+ * @param {object} cfg - Splitter configuration
367
+ * @param {string} projectPath - Path to the project
368
+ * @param {Array} [flowNodes] - Optional flow nodes to serialize directly
369
+ */
370
+ function writeMonolithArtifact(cfg, projectPath, flowNodes) {
371
+ if (cfg.enableArtifact !== true) {
372
+ return
373
+ }
374
+
375
+ const artifactDir = path.join(projectPath, artifactsDirname)
376
+ const artifactPath = path.join(artifactDir, artifactsFilename)
377
+
378
+ try {
379
+ fs.mkdirSync(artifactDir, { recursive: true })
380
+
381
+ if (Array.isArray(flowNodes)) {
382
+ fs.writeFileSync(artifactPath, eol.auto(JSON.stringify(flowNodes, null, 2)), 'utf8')
383
+ } else {
384
+ const monolithPath = path.join(projectPath, cfg.monolithFilename || RED.settings.flowFile || 'flows.json')
385
+
386
+ if (!fs.existsSync(monolithPath)) {
387
+ RED.log.warn(`[node-red-contrib-flow-splitter-extended] Could not write artifact: monolith file not found at '${monolithPath}'`)
388
+ return
389
+ }
390
+
391
+ fs.copyFileSync(monolithPath, artifactPath)
392
+ }
393
+
394
+ RED.log.info(`[node-red-contrib-flow-splitter-extended] Wrote monolith artifact at '${artifactPath}'`)
395
+ } catch (error) {
396
+ RED.log.warn(`[node-red-contrib-flow-splitter-extended] Could not write monolith artifact: ${error.message}`)
397
+ }
398
+ }
399
+
361
400
  /**
362
401
  * Manual reload endpoint handler
363
402
  * Restores functions/templates from files and reloads flows
@@ -382,6 +421,7 @@ async function manualReload(req, res) {
382
421
  }
383
422
 
384
423
  manager.constructMonolithFileFromFlowSet(flowSet, cfg, projectPath, false)
424
+ writeMonolithArtifact(cfg, projectPath)
385
425
 
386
426
  const PRIVATE_RED = getPrivateRED()
387
427
  await PRIVATE_RED.nodes.loadFlows(true)
@@ -428,6 +468,7 @@ async function onFlowReload(flowEventData) {
428
468
 
429
469
  const updatedCfg = manager.constructMonolithFileFromFlowSet(flowSet, cfg, projectPath, false)
430
470
  writeSplitterConfig(updatedCfg, projectPath)
471
+ writeMonolithArtifact(updatedCfg, projectPath)
431
472
 
432
473
  const PRIVATE_RED = getPrivateRED()
433
474
 
@@ -447,6 +488,7 @@ async function onFlowReload(flowEventData) {
447
488
 
448
489
  const updatedCfg = manager.constructTreeFilesFromFlowSet(flowSet, cfg, projectPath)
449
490
  writeSplitterConfig(updatedCfg, projectPath)
491
+ writeMonolithArtifact(updatedCfg, projectPath, flowEventData.config.flows)
450
492
 
451
493
  extractFunctionsTemplatesFromSplitFiles(updatedCfg, projectPath)
452
494
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vdwpsmt/node-red-contrib-flow-splitter-extended",
3
- "version": "1.0.1",
3
+ "version": "1.0.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
  "keywords": [