From: Jérôme Benoit Date: Thu, 19 Nov 2020 22:58:56 +0000 (+0100) Subject: Warn about deprecated configuration key at startup. X-Git-Tag: v1.0.1-0~193 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=eb3937cbf02c9f5000d7466afef0036639a3ddc4;p=e-mobility-charging-stations-simulator.git Warn about deprecated configuration key at startup. Signed-off-by: Jérôme Benoit --- diff --git a/package-lock.json b/package-lock.json index e15fda00..2cb919f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -508,9 +508,9 @@ "dev": true }, "@types/node": { - "version": "14.14.8", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.8.tgz", - "integrity": "sha512-z/5Yd59dCKI5kbxauAJgw6dLPzW+TNOItNE00PkpzNwUIEwdj/Lsqwq94H5DdYBX7C13aRA0CY32BK76+neEUA==", + "version": "14.14.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.9.tgz", + "integrity": "sha512-JsoLXFppG62tWTklIoO4knA+oDTYsmqWxHRvd4lpmfQRNhX6osheUOWETP2jMoV/2bEHuMra8Pp3Dmo/stBFcw==", "dev": true }, "@types/offscreencanvas": { diff --git a/package.json b/package.json index 56455997..c4ade427 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "utf-8-validate": "^5.0.3" }, "devDependencies": { - "@types/node": "^14.14.8", + "@types/node": "^14.14.9", "@types/uuid": "^8.3.0", "@types/worker-threads-pool": "^2.0.0", "@types/ws": "^7.4.0", diff --git a/src/start.ts b/src/start.ts index 61a6b5f9..1c91dea3 100644 --- a/src/start.ts +++ b/src/start.ts @@ -1,13 +1,10 @@ import Configuration from './utils/Configuration'; import { StationTemplateURL } from './types/ConfigurationData'; -import Utils from './utils/Utils'; import Wrk from './charging-station/Worker'; -import logger from './utils/Logger'; class Bootstrap { static start() { try { - logger.debug('%s Configuration: %j', Utils.logPrefix(), Configuration.getConfig()); let numStationsTotal = 0; // Start each ChargingStation object in a worker thread if (Configuration.getStationTemplateURLs()) { diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 57aa1ad9..17c04da0 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -4,17 +4,10 @@ import Utils from './Utils'; import fs from 'fs'; export default class Configuration { - static configuration: ConfigurationData; - - // Read the config file - static getConfig(): ConfigurationData { - if (!Configuration.configuration) { - Configuration.configuration = JSON.parse(fs.readFileSync('./src/assets/config.json', 'utf8')) as ConfigurationData; - } - return Configuration.configuration; - } + private static configuration: ConfigurationData; static getStatisticsDisplayInterval(): number { + Configuration.deprecateConfigurationKey(''); // Read conf return Utils.objectHasOwnProperty(Configuration.getConfig(), 'statisticsDisplayInterval') ? Configuration.getConfig().statisticsDisplayInterval : 60; } @@ -30,6 +23,11 @@ export default class Configuration { } static getStationTemplateURLs(): StationTemplateURL[] { + Configuration.getConfig().stationTemplateURLs.forEach((stationURL: StationTemplateURL) => { + if (!Utils.isUndefined(stationURL['numberOfStation'])) { + console.error(`Deprecated configuration key 'numberOfStation' usage for template file '${stationURL.file}' in 'stationTemplateURLs'. Use 'numberOfStations' instead`); + } + }); // Read conf return Configuration.getConfig().stationTemplateURLs; } @@ -43,6 +41,7 @@ export default class Configuration { } static getLogConsole(): boolean { + Configuration.deprecateConfigurationKey('consoleLog', 'Use \'logConsole\' instead'); return Utils.objectHasOwnProperty(Configuration.getConfig(), 'logConsole') ? Configuration.getConfig().logConsole : false; } @@ -67,6 +66,7 @@ export default class Configuration { } static getLogErrorFile(): string { + Configuration.deprecateConfigurationKey('errorFile', 'Use \'logErrorFile\' instead'); return Utils.objectHasOwnProperty(Configuration.getConfig(), 'logErrorFile') ? Configuration.getConfig().logErrorFile : 'error.log'; } @@ -76,6 +76,21 @@ export default class Configuration { } static getDistributeStationsToTenantsEqually(): boolean { + Configuration.deprecateConfigurationKey('distributeStationToTenantEqually', 'Use \'distributeStationsToTenantsEqually\' instead'); return Utils.objectHasOwnProperty(Configuration.getConfig(), 'distributeStationsToTenantsEqually') ? Configuration.getConfig().distributeStationsToTenantsEqually : true; } + + private static deprecateConfigurationKey(key: string, logMsgToAppend = '') { + if (!Utils.isUndefined(Configuration.getConfig()[key])) { + console.error(`Deprecated configuration key '${key}' usage${logMsgToAppend && '. ' + logMsgToAppend}`); + } + } + + // Read the config file + private static getConfig(): ConfigurationData { + if (!Configuration.configuration) { + Configuration.configuration = JSON.parse(fs.readFileSync('./src/assets/config.json', 'utf8')) as ConfigurationData; + } + return Configuration.configuration; + } }