standard-settings
Advanced tools
Comparing version 1.1.7 to 1.1.8
25
index.js
@@ -32,15 +32,22 @@ // first settings loaded are stronger than last one | ||
let lookUpPath = '.' | ||
if (fs.existsSync(path.resolve(process.cwd(), secondarySettingsPath))) { | ||
lookUpPath = process.cwd() | ||
} else if (fs.existsSync(path.resolve(path.dirname(require.main.filename), secondarySettingsPath))) { | ||
lookUpPath = path.dirname(require.main.filename) | ||
let settingsPath = '.' | ||
let lookUpPaths = [ | ||
process.cwd(), | ||
require.main.filename, | ||
path.resolve(path.dirname(require.main.filename), '../../../'), // inside electron | ||
path.resolve(path.dirname(require.main.filename), '../../../app.asar.unpacked/') // inside electron with asar | ||
] | ||
for (let lookUpPath in lookUpPaths) { | ||
if (fs.existsSync(path.resolve(lookUpPaths[lookUpPath], secondarySettingsPath))) { | ||
settingsPath = lookUpPaths[lookUpPath] | ||
break | ||
} | ||
} | ||
if (!fs.existsSync(path.resolve(lookUpPath, secondarySettingsPath))) { | ||
console.warn('Cannot find ' + path.resolve(lookUpPath, secondarySettingsPath)) | ||
if (!fs.existsSync(path.resolve(settingsPath, secondarySettingsPath))) { | ||
console.warn('Settings not found ' + secondarySettingsPath) | ||
} | ||
nconf.file({file: path.resolve(lookUpPath, primarySettingsPath)}) | ||
.file('default', path.resolve(lookUpPath, secondarySettingsPath)) | ||
nconf.file({file: path.resolve(settingsPath, primarySettingsPath)}) | ||
.file('default', path.resolve(settingsPath, secondarySettingsPath)) | ||
@@ -47,0 +54,0 @@ var getMeta = media => { |
{ | ||
"name": "standard-settings", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"description": "Standardised settings loader", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,3 +11,11 @@ # standard-settings | ||
## Why | ||
No more `cp config.sample.json config.json` | ||
Your app presents a `settings/settings.default.json` which is always included. | ||
User or other developer needing custom settings loads his custom settings which overrides the default settings. | ||
If a key is missing in user settings, it won't trigger errors, as a default value is in `settings.default.json` | ||
`standard-settings` offers multiple ways to change settings: `settings.json` file, command line arguments, environment variables. Check below examples for usage and priority order. | ||
## Usage | ||
@@ -14,0 +22,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
107765
154
114
1