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

Commit

Permalink
porting pull request from master to 0.4.0 branch: Local environment v…
Browse files Browse the repository at this point in the history
…ariables to address issue #553 #557
  • Loading branch information
lirantal committed May 31, 2015
1 parent 3ea400f commit 1ea9f55
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.log
node_modules/
public/lib/
config/env/local.js
public/dist/
.bower-*/
.idea/
Expand Down
5 changes: 4 additions & 1 deletion config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
var _ = require('lodash'),
chalk = require('chalk'),
glob = require('glob'),
fs = require('fs'),
path = require('path');

/**
Expand Down Expand Up @@ -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'))) || {});

This comment has been minimized.

Copy link
@sielay

sielay Jun 18, 2015

IMHO that line should depend on environment. For instance I see no sense of using local for test env.


// Initialize global globbed files
initGlobalConfigFiles(config, assets);
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'
}
};
*/
20 changes: 15 additions & 5 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
}
}
});

Expand Down Expand Up @@ -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']);
};
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-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",
Expand Down

0 comments on commit 1ea9f55

Please sign in to comment.