Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #557 from lirantal/feature-553-local-config
Browse files Browse the repository at this point in the history
Local environment variables to address issue #553
  • Loading branch information
lirantal committed May 14, 2015
2 parents 9f9f450 + dce17e9 commit 88a89f2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ehthumbs.db
Icon?
Thumbs.db
config/env/local.js

# Node and related ecosystem
# ==========================
Expand Down
24 changes: 19 additions & 5 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions config/env/local.example.js
Original file line number Diff line number Diff line change
@@ -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'
}
};
*/
19 changes: 15 additions & 4 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var fs = require('fs');

module.exports = function(grunt) {
// Unified Watch Object
var watchFiles = {
Expand Down Expand Up @@ -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');
}
}
}
});

Expand All @@ -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']);
Expand All @@ -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']);
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 88a89f2

Please sign in to comment.