From dce17e9fae88f51588a12d25ce8a0e5b86f2f601 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Thu, 14 May 2015 00:16:08 +0300 Subject: [PATCH] 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 --- config/config.js | 22 +++++++++++++++++----- config/env/local.example.js | 23 +++++++++++++++++++++++ gruntfile.js | 2 +- 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 config/env/local.example.js diff --git a/config/config.js b/config/config.js index efe758dc92..3a22a2cdb3 100644 --- a/config/config.js +++ b/config/config.js @@ -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 diff --git a/config/env/local.example.js b/config/env/local.example.js new file mode 100644 index 0000000000..824a29930f --- /dev/null +++ b/config/env/local.example.js @@ -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' + } +}; +*/ \ No newline at end of file diff --git a/gruntfile.js b/gruntfile.js index 7f995da03c..c028ff7751 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -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');