diff --git a/index.js b/index.js index 5c4aa1a87ae0a4425b627fd889fe21f48bee9812..8f06d40ca3feede6b025ae0a66d7da1d778c0d6c 100755 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ var fs = require('fs') var path = require('path') var merge = require('lodash.merge') -module.exports = function(basePath = undefined, envPrefix = undefined) { +function createConfig(basePath = undefined, envPrefix = undefined) { let configDefaults let configLocal let envPrefixUpper = envPrefix ? envPrefix.toUpperCase() + "_" : '' @@ -104,4 +104,5 @@ module.exports = function(basePath = undefined, envPrefix = undefined) { } config._reload() return config -} \ No newline at end of file +} +module.exports = { createConfig }; \ No newline at end of file diff --git a/index.test.js b/index.test.js index 39bea6399c31238007c72dd8129fd6eb938d443d..37fbe817e41ef6e8f77af8229840e92c4162d2be 100755 --- a/index.test.js +++ b/index.test.js @@ -1,6 +1,6 @@ const fs = require('fs').promises -const Config = require('./index') +const createConfig = require('./index').createConfig let jsonDefaults = { setting:"defaultvalue", @@ -25,7 +25,7 @@ describe('config', function() { it('should only have values from config.defaults.json', async function() { await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults)) - let config = new Config() + let config = createConfig() await fs.unlink('config.defaults.json') expect(config.setting).toBe('defaultvalue') @@ -34,7 +34,7 @@ describe('config', function() { it('should only have values from config.json', async function() { await fs.writeFile('config.json', JSON.stringify(jsonLocals)) - let config = new Config() + let config = createConfig() await fs.unlink('config.json') expect(config.setting).toBe('localvalue') @@ -44,7 +44,7 @@ describe('config', function() { it('should have both values with preference to config.json', async function() { await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults)) await fs.writeFile('config.json', JSON.stringify(jsonLocals)) - let config = new Config() + let config = createConfig() await fs.unlink('config.json') await fs.unlink('config.defaults.json') @@ -57,7 +57,7 @@ describe('config', function() { await fs.mkdir('tmp') await fs.writeFile('tmp/config.defaults.json', JSON.stringify(jsonDefaults)) await fs.writeFile('tmp/config.json', JSON.stringify(jsonLocals)) - let config = new Config('tmp') + let config = createConfig('tmp') await fs.unlink('tmp/config.json') await fs.unlink('tmp/config.defaults.json') await fs.rmdir('tmp') @@ -75,7 +75,7 @@ describe('config', function() { process.env['ANOTHER_MORE'] = 'false' process.env['EVEN_DEEPER_KEY'] = 'true' - let config = new Config() + let config =createConfig() await fs.unlink('config.json') await fs.unlink('config.defaults.json') @@ -98,7 +98,7 @@ describe('config', function() { process.env['P_ANOTHER_MORE'] = 'false' process.env['P_EVEN_DEEPER_KEY'] = 'true' - let config = new Config(undefined, 'p') + let config = createConfig(undefined, 'p') await fs.unlink('config.json') await fs.unlink('config.defaults.json') @@ -119,7 +119,7 @@ describe('config', function() { await fs.writeFile('config.json', JSON.stringify(jsonLocals)) await fs.writeFile('file.txt', 'value-from-file') - let config = new Config() + let config = createConfig() await fs.unlink('config.json') await fs.unlink('config.defaults.json') @@ -133,7 +133,7 @@ describe('config', function() { await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults)) await fs.writeFile('config.json', JSON.stringify(jsonLocals)) - let config = new Config() + let config = createConfig() await fs.unlink('config.json') await fs.unlink('config.defaults.json') @@ -146,7 +146,7 @@ describe('config', function() { await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults)) await fs.writeFile('config.json', JSON.stringify(jsonLocals)) - let config = new Config() + let config = createConfig() expect(config.setting).toBe('localvalue') @@ -165,7 +165,7 @@ describe('config', function() { await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults)) await fs.writeFile('config.json', JSON.stringify(jsonLocals)) - let config = new Config() + let config = createConfig() await fs.unlink('config.json') await fs.unlink('config.defaults.json') diff --git a/package.json b/package.json index cd836eb79d6acb9a4536a259331951b9efcf2601..1bb5e980ef4c32b9f30f8c00060bfc5be2c027de 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libs/config", - "version": "1.13.5", + "version": "1.13.6", "description": "Simple Config with ENV Support", "main": "index.js", "scripts": {