Skip to content
Snippets Groups Projects
Unverified Commit 9de0aa89 authored by Sigmund, Dominik's avatar Sigmund, Dominik
Browse files

Added optional BasePath

parent fce7d26a
Branches
Tags
1 merge request!1Master
......@@ -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
......
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
......@@ -2,9 +2,16 @@ 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 = {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment