How to integrate a self cooked node and subflows into single package

Hello there,

I am struggling to decide between having a single .js where the main node is defined and add into the .js the subflows read/import and register or if, otherwise, it is better to have each subflow aside with its own .js to do the import/register.

If I were to integrate everything into a single .js file, how would the nodes section of the package section should look like? Specifically.. should I list in the same section all the nodes pointing to the same file or should I just mention the main (js) node and have NR to discover the rest? I suppose if subflows are spread in different .js files, package.json should include a node pointing to each .js file.

What about the html files? Again... one file for the non-subflow node and subflow nodes?

Truth is I tried both but I have issues with both options. Is there a good practice for packaging a 'regular js' node and subflow nodes ?

Thanks!

You can define multiple nodes within a single file if you wish. Personally I dislike that and don't do it even for simple nodes. I would much rather keep things separate. Node.JS is, in any case, so good at doing file imports that there seems to be no real benefit from having everything in a single file. The general recommendation for developing in Node.JS is to have lots of simple modules that work together.

Indeed, if you look at the vNext branch of uibuilder, you will see that I split the code into a set of libraries. Though not so long back, most things were in the mail .js file plus a couple of utility modules. Now things are much better organised with each file having a logical module and much of the code node code moved out. That has made it massively easier to follow and change the logic. I found (and keep finding!) lots of subtle logic errors this way.

Similarly with the html files. A single node is already quite complex having 3 very different sections to it. In fact, I now keep each section in a separate file and use Gulp with a watch to automatically build the html file from the components. But if your code is very simple, you can certainly have multiple nodes in a single html file.

Not sure how sub-flow nodes are different though as I've not done that.

Bottom line is that simple code tends to greater complexity over time and complex code is best kept in smaller modules.

But, as always, it is entirely up to how you work best.