2016-10-10 15:04:00 +03:00
|
|
|
var Nconf = require('nconf'),
|
2016-09-13 18:20:44 +03:00
|
|
|
path = require('path'),
|
2017-08-15 14:29:27 +03:00
|
|
|
_debug = require('ghost-ignition').debug._base,
|
2017-02-17 18:27:02 +03:00
|
|
|
debug = _debug('ghost:config'),
|
2016-09-13 18:20:44 +03:00
|
|
|
localUtils = require('./utils'),
|
2017-02-02 15:46:30 +03:00
|
|
|
env = process.env.NODE_ENV || 'development',
|
|
|
|
_private = {};
|
|
|
|
|
|
|
|
_private.loadNconf = function loadNconf(options) {
|
2017-02-17 18:27:02 +03:00
|
|
|
debug('config start');
|
2017-02-02 15:46:30 +03:00
|
|
|
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({
|
2018-10-28 22:06:44 +03:00
|
|
|
separator: '__',
|
|
|
|
parseValues: true
|
2017-02-02 15:46:30 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
2017-02-11 21:02:12 +03:00
|
|
|
nconf.sanitizeDatabaseProperties = localUtils.sanitizeDatabaseProperties.bind(nconf);
|
2017-06-07 12:31:01 +03:00
|
|
|
nconf.doesContentPathExist = localUtils.doesContentPathExist.bind(nconf);
|
2017-02-02 15:46:30 +03:00
|
|
|
|
2017-02-11 21:02:12 +03:00
|
|
|
nconf.sanitizeDatabaseProperties();
|
2017-02-02 15:46:30 +03:00
|
|
|
nconf.makePathsAbsolute(nconf.get('paths'), 'paths');
|
|
|
|
nconf.makePathsAbsolute(nconf.get('database:connection'), 'database:connection');
|
|
|
|
|
2017-05-21 19:00:11 +03:00
|
|
|
/**
|
|
|
|
* Check if the URL in config has a protocol
|
|
|
|
*/
|
|
|
|
nconf.checkUrlProtocol = localUtils.checkUrlProtocol.bind(nconf);
|
|
|
|
nconf.checkUrlProtocol();
|
|
|
|
|
2017-06-07 12:31:01 +03:00
|
|
|
/**
|
|
|
|
* Ensure that the content path exists
|
|
|
|
*/
|
|
|
|
nconf.doesContentPathExist();
|
|
|
|
|
2017-02-02 15:46:30 +03:00
|
|
|
/**
|
|
|
|
* values we have to set manual
|
|
|
|
*/
|
|
|
|
nconf.set('env', env);
|
|
|
|
|
2017-02-17 18:27:02 +03:00
|
|
|
// Wrap this in a check, because else nconf.get() is executed unnecessarily
|
|
|
|
// To output this, use DEBUG=ghost:*,ghost-config
|
|
|
|
if (_debug.enabled('ghost-config')) {
|
|
|
|
debug(nconf.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('config end');
|
2017-02-02 15:46:30 +03:00
|
|
|
return nconf;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = _private.loadNconf();
|
|
|
|
module.exports.loadNconf = _private.loadNconf;
|