If you don't need version control, I can understand that having all code in one file is easier. But node red already has the git integration in projects mode. Is there any good way of splitting flows.json into individual code files? Diffs are a pain and it would be a breeze to be able to synchronize particular flows or subflows across repos if having multiple files.
This has been requested many times:
- Formatted Function Node with separate JS files - #2 by knolleary
- Flows/*.json instead of flows.json? - #6 by knolleary
- Function Node exported json - #2 by knolleary
One promising (and simple) solution would be to support YAML format (as Nick says in the first link) but unfortunately, as of writing, no one has picked this up.
An option that would make diffs a little easier would be to enable the flowFilePretty
flag in settings.js. This will make JSON props much easier to compare (but function code will still be escaped unlike an equivalent YAML file format)
I once created a visual comparison between a flow in the flow editor and the flow on the server --> node-red-contrib-flowcompare (node) - Node-RED
This doesn't help with diffing mods to the flow itself, but for mods within function nodes I use flowFilePretty
and before committing to git I run a batch file containing:
#!/usr/bin/env sh
# generates formatted versions of node red flow files matching flow*.json
# in files flow*.json.formatted
# NOTE must have flowFilePretty: true in settings.js
for f in *flow*.json; do
echo $f
sed -r 's/\\n/\n/g' "$f" > "$f.formatted"
done
# remove any cred files converted
rm *_cred.json.formatted
This escapes function nodes in flows files, generating flows.json.formatted
files. I include the formatted file in the git repo and a diff on that file shows the changes to the function nodes in an understandable format.
Some nice workarounds and hacks, also found some interesting community packages that could help. But nothing would beat a native built-in solution.
While I'm dreaming, first-class support for typescript?
This the purpose of flowhub.org - visual versioning of flows.
Yep that's why there is a text-based, attribute by attribute diff built in to NodeRED.
If flows.json was split, I could simply distribute a new version of a subflow by copying its file. At the moment distributing subflow version has become very difficult.
that's what flowhub.org does or helps with - since flowhub.org works at the level of flow tabs not flows.json. So you create your flows.json using various flow tabs and each flow tab is hosted flowhub (i.e. in a github repo) and then you combine you individual flows into one large flows.json.