From a08018ac8e8491de82b35cbe03ec0984249a9a07 Mon Sep 17 00:00:00 2001 From: Florent Date: Sun, 26 Dec 2021 14:19:45 +0100 Subject: [PATCH] Add file for user specific settings --- conf/settings.js | 17 ++++++++++++++-- conf/settings.user.js | 46 +++++++++++++++++++++++++++++++++++++++++++ doc/DESCRIPTION.md | 19 ++++++++++++++++++ doc/DESCRIPTION_fr.md | 22 +++++++++++++++++++++ manifest.json | 2 +- scripts/install | 3 +++ scripts/upgrade | 5 +++++ 7 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 conf/settings.user.js diff --git a/conf/settings.js b/conf/settings.js index d8da1c9..0185849 100644 --- a/conf/settings.js +++ b/conf/settings.js @@ -1,3 +1,11 @@ +// CAUTION: DO NOT EDIT THIS FILE. Rather go to and edit `__FINALPATH__/settings.user.js` + + +const getUserSettings = require('./settings.user'); + + + + /** * This is the default settings file provided by Node-RED. * @@ -20,7 +28,7 @@ * **/ -module.exports = { +const defaultSettings = Object.freeze({ /******************************************************************************* * Flow File and User Directory Settings @@ -483,4 +491,9 @@ module.exports = { // * - reason: if result is false, the HTTP reason string to return // */ //}, -} +}); + +module.exports = { + ...defaultSettings, + ...getUserSettings(defaultSettings), +}; diff --git a/conf/settings.user.js b/conf/settings.user.js new file mode 100644 index 0000000..393809b --- /dev/null +++ b/conf/settings.user.js @@ -0,0 +1,46 @@ +/** + * + * This is where you you can as a user define and even override the default settings. + * This file will remain untouched by the yunohost package accross upgrades. + * + * It can contain any valid JavaScript code that will get run when Node-RED + * is started. + * + * Lines that start with // are commented out. + * Each entry should be separated from the entries above and below by a comma ',' + * + * For more information about individual settings, refer to the documentation: + * https://nodered.org/docs/user-guide/runtime/configuration + * + * The settings are split into the following sections: + * - Flow File and User Directory Settings + * - Security + * - Server Settings + * - Runtime Settings + * - Editor Settings + * - Node Settings + * + **/ + +module.exports = (defaultSettings) => ({ + /** + * Put here your own config, it will override the ones in settings.js + * + * Example: + * ```js + * module.exports = (defaultSettings) => ({ + * lang: "de", // define the language as "de" + * exportGlobalContextKeys: true, // override the `exportGlobalContextKeys` value + * + * + * logging: { // replace the default logging option + * ...defaultSettings.logging, // this will reinject the default settings in logging + * console: { + * ...defaultSettings.logging.level, // this will reinject the default settings in logging.console + * level: "debug", // but here, we override the "info" level by "debug" + * }, + * }, + * }); + * ``` + */ +}); diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md index 2005b21..b1a897a 100644 --- a/doc/DESCRIPTION.md +++ b/doc/DESCRIPTION.md @@ -8,3 +8,22 @@ It provides a browser-based editor that makes it easy to wire together flows usi - On-click deployment of the flows - Over 225,000 modules available - Custom JavaScript functions can be written + +### Override the default settings + +From the installation directory, go edit the `data/settings.user.js`. For example: + +```js +module.exports = (defaultSettings) => ({ + lang: "de", // define the language as "de" + exportGlobalContextKeys: true, // override the `exportGlobalContextKeys` value +logging: { // replace the default logging option ...defaultSettings.logging, // this will reinject the default settings in logging + console: { + ...defaultSettings.logging.level, // this will reinject the default settings in logging.console + level: "debug", // but here, we override the "info" level by "debug" + }, + }, +}); +``` + +You can check the default settings Yunohost generates at `data/settings.js` and find the documentation for configuring Node-RED here: https://nodered.org/docs/user-guide/runtime/configuration diff --git a/doc/DESCRIPTION_fr.md b/doc/DESCRIPTION_fr.md index 4248bd3..1a00e72 100644 --- a/doc/DESCRIPTION_fr.md +++ b/doc/DESCRIPTION_fr.md @@ -8,3 +8,25 @@ Il propose un éditeur accessible dans le navigateur, qui facilite l'ébauche de - Déploiement des flux en un clic - Plus de 225 000 modules disponibles - Fonctions personnalisées en JavaScript + + +### Surcharger la configuration par défaut + +Depuis le répertoire d'installation, éditer le fichier `data/settings.user.js`. Par exemple + +```js +module.exports = (defaultSettings) => ({ + lang: "de", // définit la langue de l'IHM comme allemande + exportGlobalContextKeys: true, // surcharger la valeur de `exportGlobalContextKeys` + + logging: { // remplacer l'option par défaut pour la journalisation (logging) + ...defaultSettings.logging, // cela réinjectera les paramètres par défaut dans `logging` + console: { + ...defaultSettings.logging.level, // cela réinjectera les paramètres par défaut dans `logging.console` + level: "debug", // mais isi, nous surchargeons le niveau "info" par "debug" + }, + }, +}); +``` + +Vous pouvez consulter les paramètres par défaut générez par Yunohost dans `data/settings.js` et trouver la documentation pour configurer Node-RED ici: https://nodered.org/docs/user-guide/runtime/configuration diff --git a/manifest.json b/manifest.json index f865077..636c9a8 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Flow-based programming for the Internet of Things", "fr": "Programmation par flux de données pour l'Internet des objets" }, - "version": "2.1.4~ynh1", + "version": "2.1.4~ynh2", "url": "https://nodered.org", "upstream": { "license": "Apache-2.0", diff --git a/scripts/install b/scripts/install index 8596869..e6cb691 100755 --- a/scripts/install +++ b/scripts/install @@ -107,6 +107,7 @@ ynh_add_nginx_config # Set up the settings file mkdir -p $final_path/data ynh_add_config --template="../conf/settings.js" --destination="$final_path/data/settings.js" +ynh_add_config --template="../conf/settings.user.js" --destination="$final_path/data/settings.user.js" # Small hack to have the "/" path answer with a 200 code to satisfy the CI if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] ; then @@ -120,6 +121,8 @@ fi chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app: "$final_path" +# make settings.js readonly +chmod a-w "$final_path/data/settings.js" #================================================= # SETUP SYSTEMD diff --git a/scripts/upgrade b/scripts/upgrade index 5ccbcdb..bccbec5 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -175,6 +175,9 @@ ynh_add_nginx_config # Set up the settings file ynh_add_config --template="../conf/settings.js" --destination="$final_path/data/settings.js" +if [[ ! -f "$final_path/data/settings.user.js" ]] ; then + ynh_add_config --template="../conf/settings.user.js" --destination="$final_path/data/settings.user.js" +fi # Small hack to have the "/" path answer with a 200 code to satisfy the CI if [[ "${PACKAGE_CHECK_EXEC:-}" = "1" ]] ; then @@ -207,6 +210,8 @@ ynh_add_systemd_config chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app: "$final_path" +# make settings.js readonly +chmod a-w "$final_path/data/settings.js" #================================================= # ADVERTISE SERVICE IN ADMIN PANEL