creating a local.example.js as a sample file to extend configuration to local repository without committing these changes and also replacing .extend() with .merge() for local repository changes

This commit is contained in:
Liran Tal
2015-05-14 00:16:08 +03:00
parent aca6a793e9
commit dce17e9fae
3 changed files with 41 additions and 6 deletions

View File

@@ -7,14 +7,26 @@ var _ = require('lodash'),
glob = require('glob'),
fs = require('fs');
/**
* Resolve environment configuration by extending each env configuration file,
* and lastly merge/override that with any local repository configuration that exists
* in local.js
*/
var resolvingConfig = function() {
var conf = {};
conf = _.extend(
require('./env/all'),
require('./env/' + process.env.NODE_ENV) || {}
);
return _.merge(conf, (fs.existsSync('./config/env/local.js') && require('./env/local.js')) || {});
};
/**
* Load app configurations
*/
module.exports = _.extend(
require('./env/all'),
require('./env/' + process.env.NODE_ENV),
(fs.existsSync('./config/env/local.js') && require('./env/local.js')) || {}
);
module.exports = resolvingConfig();
/**
* Get files by glob patterns

23
config/env/local.example.js vendored Normal file
View File

@@ -0,0 +1,23 @@
'use strict';
// Rename this file to local.js for having a local configuration variables that
// will not get commited and pushed to remote repositories.
// Use it for your API keys, passwords, etc.
/* For example:
module.exports = {
db: {
uri: 'mongodb://localhost/local-dev',
options: {
user: '',
pass: ''
}
},
facebook: {
clientID: process.env.FACEBOOK_ID || 'APP_ID',
clientSecret: process.env.FACEBOOK_SECRET || 'APP_SECRET',
callbackURL: '/auth/facebook/callback'
}
};
*/

View File

@@ -148,7 +148,7 @@ module.exports = function(grunt) {
},
copy: {
localConfig: {
src: 'config/env/development.js',
src: 'config/env/local.example.js',
dest: 'config/env/local.js',
filter: function() {
return !fs.existsSync('config/env/local.js');