Subflow 2 Module helper flow

Hey y'all

In the last month, I have seen a slight increase in the need to package subflows as modules,
and the guide to do that is here : Packaging a Subflow as a module : Node-RED.

This is currently a manual affair.
And one of the time consuming parts, is to manually make changes to the export of the subflow.

This small, no-fuss flow, should help address that!

Simply, paste your subflow export (please see guide, and I suggested using the formatted option) into the Paste JSON In Here template node, and click Generate.

The debug will then print the output that needs to be used in the subflow.json file (as explained in the guide linked above)

Anyway, it's just a thing I quickly put together, but should do the trick.
Please note: This was created (and tested) in Node RED 3.1.0, so just a reminder, it might not be compatible with earlier versions :man_shrugging:

Enjoy & Happy Friday

[{"id":"d8a0138c500400c0","type":"tab","label":"Subflow To Module Helper","disabled":false,"info":"","env":[]},{"id":"010971a0b889d9e2","type":"inject","z":"d8a0138c500400c0","name":"Generate","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":400,"wires":[["b26cd5bbf33bb995"]]},{"id":"58c70ff09c672927","type":"function","z":"d8a0138c500400c0","name":"Fix me up baby!","func":"let parsedObject = JSON.parse(msg.payload)\n\nparsedObject = parsedObject.filter((n) => !n.type.startsWith(\"subflow:\"))\n\nconst nodes = parsedObject.filter((n) => n.type !== 'subflow')\nconst subflow = parsedObject.filter((n) => n.type === 'subflow')[0]\n\nmsg.payload  = {\n    ...subflow,\n    flow:[...nodes]\n}\n\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":175,"y":530,"wires":[["f35a8ce51124e60b"]]},{"id":"b26cd5bbf33bb995","type":"template","z":"d8a0138c500400c0","name":"Paste JSON In Here","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"","output":"str","x":185,"y":465,"wires":[["58c70ff09c672927"]]},{"id":"f35a8ce51124e60b","type":"debug","z":"d8a0138c500400c0","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":405,"y":530,"wires":[]}]

2 Likes