diff --git a/.gitignore b/.gitignore index bca129da..c519f474 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ ehthumbs.db Icon? Thumbs.db +config/env/local.js # Node and related ecosystem # ========================== diff --git a/config/config.js b/config/config.js index ef4a4c2c..3a22a2cd 100644 --- a/config/config.js +++ b/config/config.js @@ -4,15 +4,29 @@ * Module dependencies. */ var _ = require('lodash'), - glob = require('glob'); + 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) || {} -); +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 00000000..824a2993 --- /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 b45a9cd7..c028ff77 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -1,5 +1,7 @@ 'use strict'; +var fs = require('fs'); + module.exports = function(grunt) { // Unified Watch Object var watchFiles = { @@ -143,6 +145,15 @@ module.exports = function(grunt) { unit: { configFile: 'karma.conf.js' } + }, + copy: { + localConfig: { + src: 'config/env/local.example.js', + dest: 'config/env/local.js', + filter: function() { + return !fs.existsSync('config/env/local.js'); + } + } } }); @@ -162,13 +173,13 @@ module.exports = function(grunt) { }); // Default task(s). - grunt.registerTask('default', ['lint', 'concurrent:default']); + grunt.registerTask('default', ['lint', 'copy:localConfig', 'concurrent:default']); // Debug task. - grunt.registerTask('debug', ['lint', 'concurrent:debug']); + grunt.registerTask('debug', ['lint', 'copy:localConfig', 'concurrent:debug']); // Secure task(s). - grunt.registerTask('secure', ['env:secure', 'lint', 'concurrent:default']); + grunt.registerTask('secure', ['env:secure', 'lint', 'copy:localConfig', 'concurrent:default']); // Lint task(s). grunt.registerTask('lint', ['jshint', 'csslint']); @@ -177,7 +188,7 @@ module.exports = function(grunt) { grunt.registerTask('build', ['lint', 'loadConfig', 'ngAnnotate', 'uglify', 'cssmin']); // Test task. - grunt.registerTask('test', ['test:server', 'test:client']); + grunt.registerTask('test', ['copy:localConfig', 'test:server', 'test:client']); grunt.registerTask('test:server', ['env:test', 'mochaTest']); grunt.registerTask('test:client', ['env:test', 'karma:unit']); }; diff --git a/package.json b/package.json index 8d2a05b9..091f2e12 100755 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "grunt-mocha-test": "~0.12.1", "grunt-karma": "~0.9.0", "load-grunt-tasks": "~1.0.0", + "grunt-contrib-copy": "0.8", "karma": "~0.12.0", "karma-jasmine": "~0.2.1", "karma-coverage": "~0.2.0",