From ca8d26c7225799dfe2a92576eee20cdf5dcef3c7 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Fri, 20 Nov 2020 18:27:38 +1300 Subject: [PATCH] Add config overrides file --- .gitignore | 5 ++++- config/config.sample.js | 15 +++++++++++++++ package-lock.json | 5 +++++ package.json | 1 + utils/constants.js | 11 ++++++++++- 5 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 config/config.sample.js diff --git a/.gitignore b/.gitignore index 564cdcf..f511669 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ # Auto-generated files node_modules -/db \ No newline at end of file + +# User configuration +/db +/config/config.js diff --git a/config/config.sample.js b/config/config.sample.js new file mode 100644 index 0000000..71c607a --- /dev/null +++ b/config/config.sample.js @@ -0,0 +1,15 @@ +module.exports = { + /* + Copy this file to `config.js`, and add options here. + They'll override the options from `utils/constants.js`. + For example, uncommenting the next block would change the default instance. + */ + + /* + user_settings: { + instance: { + default: "https://example.com" + } + } + */ +} diff --git a/package-lock.json b/package-lock.json index 53fcb93..74f9c75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -442,6 +442,11 @@ "minipass": "^2.9.0" } }, + "mixin-deep": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-2.0.1.tgz", + "integrity": "sha512-imbHQNRglyaplMmjBLL3V5R6Bfq5oM+ivds3SKgc6oRtzErEnBUUc5No11Z2pilkUvl42gJvi285xTNswcKCMA==" + }, "mkdirp": { "version": "0.5.5", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", diff --git a/package.json b/package.json index e096af5..a29e840 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "better-sqlite3": "^7.1.0", "cookie": "^0.4.1", "denque": "^1.4.1", + "mixin-deep": "^2.0.1", "node-fetch": "^2.6.0", "pinski": "git+https://git.sr.ht/~cadence/nodejs-pinski#04cd72482574f689b78670b7f2b80209f5449a21" } diff --git a/utils/constants.js b/utils/constants.js index fae1253..e8d367e 100644 --- a/utils/constants.js +++ b/utils/constants.js @@ -1,4 +1,6 @@ -const constants = { +const mixin = require("mixin-deep") + +let constants = { user_settings: { instance: { type: "string", @@ -34,4 +36,11 @@ const constants = { } } +try { + const overrides = require("../config/config.js") + constants = mixin(constants, overrides) +} catch (e) { + console.log("Note: overrides file `config/config.js` ignored, file not found.") +} + module.exports = constants