From 1bd7aa9b97a47f81baa2dbc0c05446e1ef9e713f Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 17 Jan 2022 18:08:26 +0100 Subject: [PATCH] MOBILE-3833 core: Add helpers to patch config --- src/core/constants.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/constants.ts b/src/core/constants.ts index 6df64e291..a4f6a7c32 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -131,9 +131,26 @@ export class CoreConstants { static readonly MOD_ARCHETYPE_SYSTEM = 3; // System (not user-addable) module archetype. // Config & environment constants. - static readonly CONFIG = envJson.config as unknown as EnvironmentConfig; // Data parsed from config.json files. + static readonly CONFIG = { ...envJson.config } as unknown as EnvironmentConfig; // Data parsed from config.json files. static readonly BUILD = envJson.build as unknown as EnvironmentBuild; // Build info. + /** + * Update config with the given values. + * + * @param config Config updates. + */ + static patchConfig(config: Partial): void { + Object.assign(this.CONFIG, config); + } + + /** + * Reset config values to its original state. + */ + static resetConfig(): void { + Object.keys(this.CONFIG).forEach(key => delete this.CONFIG[key]); + Object.assign(this.CONFIG, envJson.config); + } + } interface EnvironmentBuild {