diff --git a/README.md b/README.md index c3664d6cca5c15745a61dfbdc06a5d6f438208a4..305e6baac43c2e39dfb0c6385c0ad4286e4520c5 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Simple Config with ENV Support. ## Usage `const Config = require('@plastdev/config')` -`let config = new Config()` +`let config = new Config([basePath])` Then config is your config object. (Use it like config.setting) @@ -28,6 +28,9 @@ You may use the function _reload()_ to reload the config from all sources. This makes *reload* a reserved keyword +If you give a basePath, the config-Files are used from there. +Else the main dir of the application will be used. + ## Examples ### Only config.defaults.json diff --git a/index.d.ts b/index.d.ts index 52fd8ac46c4dd02875b7c70d06bd44cd2efaec49..ee4d70d3c96ebc083b340f8d2fc967fe1c06f822 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1 +1,8 @@ -declare module 'config'; \ No newline at end of file +export as namespace Config; + +export = Config; + +declare class Config { + constructor(); + reload(): void; +} \ No newline at end of file diff --git a/index.js b/index.js index 049096bdeb52afca14211056c8ff6b53eda1cc97..28a68138464ddf4e44c1581c7fea516a31d7a596 100644 --- a/index.js +++ b/index.js @@ -2,10 +2,17 @@ var fs = require('fs') var path = require('path') var merge = require('lodash.merge') -module.exports = function() { - let configDefaults = path.join(path.dirname(require.main.filename), 'config.defaults.json') - let configLocal = path.join(path.dirname(require.main.filename), 'config.json') - +module.exports = function(basePath = undefined) { + let configDefaults + let configLocal + if (basePath) { + configDefaults = path.join(basePath, 'config.defaults.json') + configLocal = path.join(basePath, 'config.json') + } else { + configDefaults = path.join(path.dirname(require.main.filename), 'config.defaults.json') + configLocal = path.join(path.dirname(require.main.filename), 'config.json') + } + let config = {} const objectDeepKeys = function (obj) {