-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #7488 - rename file keys for config files, see https://github.com/TryGhost/Ghost/pull/7493/files - add tests to avoid running into config hierarchy problems again - overrides.json is the strongest! - argv/env can override any default - custom config can override defaults - reorganise util functions for config again
- Loading branch information
Showing
9 changed files
with
204 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,57 @@ | ||
var Nconf = require('nconf'), | ||
nconf = new Nconf.Provider(), | ||
path = require('path'), | ||
debug = require('debug')('ghost:config'), | ||
localUtils = require('./utils'), | ||
env = process.env.NODE_ENV || 'development'; | ||
|
||
/** | ||
* command line arguments | ||
*/ | ||
nconf.argv(); | ||
|
||
/** | ||
* env arguments | ||
*/ | ||
nconf.env({ | ||
separator: '__' | ||
}); | ||
|
||
/** | ||
* load config files | ||
* @TODO: | ||
* - why does this work? i have no idea! | ||
* - find out why argv override works, when defining these weird keys | ||
* - i could not find any nconf usages so that all config requirements work | ||
*/ | ||
nconf.file('ghost1', __dirname + '/overrides.json'); | ||
nconf.file('ghost2', path.join(process.cwd(), 'config.' + env + '.json')); | ||
nconf.file('ghost3', __dirname + '/env/config.' + env + '.json'); | ||
nconf.file('ghost4', __dirname + '/defaults.json'); | ||
|
||
/** | ||
* transform all relative paths to absolute paths | ||
* transform sqlite filename path for Ghost-CLI | ||
*/ | ||
localUtils.makePathsAbsolute.bind(nconf)(nconf.get('paths'), 'paths'); | ||
localUtils.makePathsAbsolute.bind(nconf)(nconf.get('database:connection'), 'database:connection'); | ||
|
||
/** | ||
* values we have to set manual | ||
*/ | ||
nconf.set('env', env); | ||
|
||
module.exports = nconf; | ||
module.exports.isPrivacyDisabled = localUtils.isPrivacyDisabled.bind(nconf); | ||
module.exports.getContentPath = localUtils.getContentPath.bind(nconf); | ||
env = process.env.NODE_ENV || 'development', | ||
_private = {}; | ||
|
||
_private.loadNconf = function loadNconf(options) { | ||
options = options || {}; | ||
|
||
var baseConfigPath = options.baseConfigPath || __dirname, | ||
customConfigPath = options.customConfigPath || process.cwd(), | ||
nconf = new Nconf.Provider(); | ||
|
||
/** | ||
* no channel can override the overrides | ||
*/ | ||
nconf.file('overrides', path.join(baseConfigPath, 'overrides.json')); | ||
|
||
/** | ||
* command line arguments | ||
*/ | ||
nconf.argv(); | ||
|
||
/** | ||
* env arguments | ||
*/ | ||
nconf.env({ | ||
separator: '__' | ||
}); | ||
|
||
nconf.file('custom-env', path.join(customConfigPath, 'config.' + env + '.json')); | ||
nconf.file('default-env', path.join(baseConfigPath, 'env', 'config.' + env + '.json')); | ||
nconf.file('defaults', path.join(baseConfigPath, 'defaults.json')); | ||
|
||
/** | ||
* transform all relative paths to absolute paths | ||
* transform sqlite filename path for Ghost-CLI | ||
*/ | ||
nconf.makePathsAbsolute = localUtils.makePathsAbsolute.bind(nconf); | ||
nconf.isPrivacyDisabled = localUtils.isPrivacyDisabled.bind(nconf); | ||
nconf.getContentPath = localUtils.getContentPath.bind(nconf); | ||
|
||
nconf.makePathsAbsolute(nconf.get('paths'), 'paths'); | ||
nconf.makePathsAbsolute(nconf.get('database:connection'), 'database:connection'); | ||
|
||
/** | ||
* values we have to set manual | ||
*/ | ||
nconf.set('env', env); | ||
|
||
debug(nconf.get()); | ||
return nconf; | ||
}; | ||
|
||
module.exports = _private.loadNconf(); | ||
module.exports.loadNconf = _private.loadNconf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"paths": { | ||
"corePath": "try-to-override" | ||
}, | ||
"database": { | ||
"connection": { | ||
"filename": "/hehe.db" | ||
}, | ||
"debug": true | ||
}, | ||
"logging": { | ||
"level": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"paths": { | ||
"corePath": "try-to-override" | ||
}, | ||
"database": { | ||
"connection": { | ||
"filename": "/hehe.db" | ||
}, | ||
"debug": true | ||
}, | ||
"logging": { | ||
"level": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"database": { | ||
"client": "sqlite3", | ||
"connection": { | ||
"filename": "/test.db" | ||
}, | ||
"debug": false | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
core/test/utils/fixtures/config/env/config.testing-mysql.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"url": "http://localhost:2368", | ||
"logging": { | ||
"level": "info", | ||
"transports": ["stdout"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"url": "http://localhost:2368", | ||
"logging": { | ||
"level": "info", | ||
"transports": ["stdout"] | ||
} | ||
} |
Oops, something went wrong.