From 1ea9f5560055a3b440fc63059f6c1b2c1fd01ece Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Sun, 31 May 2015 11:54:17 +0300 Subject: [PATCH] porting pull request from master to 0.4.0 branch: Local environment variables to address issue #553 #557 --- .gitignore | 1 + config/config.js | 5 ++++- config/env/local.example.js | 23 +++++++++++++++++++++++ gruntfile.js | 20 +++++++++++++++----- package.json | 1 + 5 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 config/env/local.example.js diff --git a/.gitignore b/.gitignore index 13bbaa740f..43107cc37b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.log node_modules/ public/lib/ +config/env/local.js public/dist/ .bower-*/ .idea/ diff --git a/config/config.js b/config/config.js index 670cd3f341..85458853b9 100644 --- a/config/config.js +++ b/config/config.js @@ -6,6 +6,7 @@ var _ = require('lodash'), chalk = require('chalk'), glob = require('glob'), + fs = require('fs'), path = require('path'); /** @@ -139,7 +140,9 @@ var initGlobalConfig = function() { var environmentConfig = require(path.join(process.cwd(), 'config/env/', process.env.NODE_ENV)) || {}; // Merge config files - var config = _.extend(defaultConfig, environmentConfig); + var envConf = _.extend(defaultConfig, environmentConfig); + + var config = _.merge(envConf, (fs.existsSync(path.join(process.cwd(), 'config/env/local.js')) && require(path.join(process.cwd(), 'config/env/local.js'))) || {}); // Initialize global globbed files initGlobalConfigFiles(config, assets); 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 ea4eb0d88e..e8abfe71ab 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -5,7 +5,8 @@ */ var _ = require('lodash'), defaultAssets = require('./config/assets/default'), - testAssets = require('./config/assets/test'); + testAssets = require('./config/assets/test'), + fs = require('fs'); module.exports = function (grunt) { // Project Configuration @@ -190,6 +191,15 @@ module.exports = function (grunt) { args: {} // Target-specific arguments } } + }, + copy: { + localConfig: { + src: 'config/env/local.example.js', + dest: 'config/env/local.js', + filter: function() { + return !fs.existsSync('config/env/local.js'); + } + } } }); @@ -220,14 +230,14 @@ module.exports = function (grunt) { grunt.registerTask('build', ['env:dev', 'lint', 'ngAnnotate', 'uglify', 'cssmin']); // Run the project tests - grunt.registerTask('test', ['env:test', 'mongoose', 'mochaTest', 'karma:unit']); + grunt.registerTask('test', ['env:test', 'copy:localConfig', 'mongoose', 'mochaTest', 'karma:unit']); // Run the project in development mode - grunt.registerTask('default', ['env:dev', 'lint', 'concurrent:default']); + grunt.registerTask('default', ['env:dev', 'lint', 'copy:localConfig', 'concurrent:default']); // Run the project in debug mode - grunt.registerTask('debug', ['env:dev', 'lint', 'concurrent:debug']); + grunt.registerTask('debug', ['env:dev', 'lint', 'copy:localConfig', 'concurrent:debug']); // Run the project in production mode - grunt.registerTask('prod', ['build', 'env:prod', 'concurrent:default']); + grunt.registerTask('prod', ['build', 'env:prod', 'copy:localConfig', 'concurrent:default']); }; diff --git a/package.json b/package.json index aabab5ab59..873e02e09e 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "grunt-contrib-uglify": "~0.6.0", "grunt-contrib-cssmin": "~0.10.0", "grunt-nodemon": "~0.3.0", + "grunt-contrib-copy": "0.8", "grunt-concurrent": "~1.0.0", "grunt-mocha-test": "~0.12.1", "grunt-karma": "~0.9.0",