Node-RED CLI tool for easier source code management

Nice! That's giving me some good insight. I started a prototype of the flow-to-source file generating command as a subflow in lieu of a CLI routine. But then this led me to the inability to discover the project path. Looks like the ability has been requested but it's still not possible from a subflow (discussion from 2019 at Project directory path - #3 by ianmacs).

So I had to implement it as a written node "from scratch" (thankfully, I have another set of subflows that automates that; but I have digressed...).

I've written the flows2src node (light green in the pic) that generates a "src" folder and then subfolders as the same name as the flows tab, and/or subflows (as subfolders). Within the subfolders are the template and function nodes as appropriately named files with extensions. I've implemented the filename iteration scheme to address two nodes of the same name.

Lastly, a manifest.json file exists in the root of the src folder that maps the files, object ids, and property that is being written (templates, functions for on message, on start, on stop). If the function property is empty it won't bother writing the file (git doesn't like empty files anyways).

I did have the node perform this after every. deploy but in the end decided to give it an input so that one can simply attach an injector node to do the same thing; or write out the src folder on demand.

I'll publish the node to npm and the flows directory shortly. Writing the reverse, given the manifest file, should be trivial.

1 Like