Possible minor restructure of settings.js?

In a previous release of Node-RED, Nick was kind enough to restructure the comments in settings.js to make it easier for people to read when using something like VSCode (being able to collapse long comments).

My proposal this time is to slightly restructure the file so that it is easier for people to add dynamic changes to settings based on another setting.

For example, lets say that you want to change some aspect of the editor theme based on another setting. At the moment, this is quite hard to get your head around and may involve some restructuring.

However, with this minor change, it becomes easy.

The change is to assign the settings to a variable and then export the variable rather than exporting a JavaScript object directly.

// ...
const nrsettings = {
    // ...
}

// we can make changes to settings here and even use other settings
// properties to make changes to other properties.
if ( nrsettings.uiport = 9999 )  nrsettings.editor.theme.header.title = "DEVELOPMENT SERVER"
else nrsettings.editor.theme.header.title = "PRODUCTION SERVER"
// Obviously, the above is just a poor example but hopefully illustrates the point.

module.exports = nrsettings

I've been using this in my own node-red instances for a while now.

This also has the advantage that few manual changes may be needed in the actual settings which can make comparison (diff) to new versions of the settings file easier to manage.


As a bonus request, it would be great to wrap the various sections of the settings file in

//#region ---- region description ----
....
//#endregion ---- region description ----

tags which are recognised by various code editors and will trigger smart folding of the sections. Given how long the settings are now, this is very helpful when trying to navigate and edit the file. Again, I've been using this for quite a while now.


I'd be happy to submit a PR for either/both of these if they were deemed useful.

5 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.