UNPKG

flysh

Version:

DOM Document Object Artifact Collector

77 lines 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigReader = void 0; /** * 'ConfigReader' class helper * * Read the settings found from configuration file * * Note: 'ENV' variables might be overridden by 'properties.cnf' by 'launch.json', 'tasks.json' and command line (OS). */ class ConfigReader { /** * Constructor */ constructor() { this.ENVIRONMENT_KEY_VAUE = 'NODE_ENV'; this.CONFIG_FILE_PATH_VALUE = './properties.cnf'; this.CONFIG_FILE_SECTION_DATABASE_NAME = 'database'; this.CONFIG_FILE_SECTION_INSTANCE_NAME = 'instance'; this.CONFIG_FILE_SECTION_MAIN_NAME = 'main'; this.CONFIG_FILE_PROPERTIES_CURRENT_ENVIRONMENT_NAME = 'current.environment'; this.propertiesReader = require('properties-reader'); this.init(); } /** * Loads the environment and configuration file to the class properties */ init() { this.properties = this.propertiesReader(this.CONFIG_FILE_PATH_VALUE); this.environment = this.getENVMode(); } /** * Sets the environment from configuration file then eventually overload it by the preseted 'NODE_ENV' value(s). * This means that 'properties.cnf', 'launch.json' and 'tasks.json' will be overridden as well * * @returns Returns the current mode environment */ getENVMode() { let retVal = this.properties.get(this.CONFIG_FILE_SECTION_MAIN_NAME + '.' + this.CONFIG_FILE_PROPERTIES_CURRENT_ENVIRONMENT_NAME); if (process.env[this.ENVIRONMENT_KEY_VAUE]) retVal = process.env[this.ENVIRONMENT_KEY_VAUE]; return retVal; } /** * Returns the "section" from 'properties' class attribute (ENV) * * @param section 'String' that contains the section to read * @returns Returns a 'map' value that contains the right section * @deprecated */ getPropSettings(section) { let retMap = new Map(); this.properties.each((key, value) => { if (key.match(section + "." + this.environment)) retMap.set(key.substring(key.lastIndexOf(".") + 1, key.length), value); }); return retMap; } /** * Returns the "section" from 'properties' class attribute * * @param section 'String' that contains the "section" to read * @returns Returns a 'map' value that contains the right "section" */ getProperties(section) { let retMap = new Map(); this.properties.each((key, value) => { if (key.match(section)) retMap.set(key.substring(key.lastIndexOf(".") + 1, key.length), value); }); return retMap; } } exports.ConfigReader = ConfigReader; ; //# sourceMappingURL=ConfigReader.js.map