Skip to content
Permalink
Browse files

feat(config): Local env configurations

Adds the ability to configure multiple env configurations, for the
various NODE_ENV's. These configs can be used to override the current
configuration, using the appropriate local-NODE_ENV.js file that the
user has defined.

Updated the local.example.js comments to be clear on the usage.

Added config/env/local-*.js to gitignore.

Updated the copy:localConfig Grunt task to copy local.example as
local-development.js, since we're no longer going to use local.js.
  • Loading branch information...
mleanos committed Oct 20, 2015
1 parent e140880 commit 6d7447479fbfdbdb11a999c495e3851f3af3f369
Showing with 18 additions and 10 deletions.
  1. +1 −0 .gitignore
  2. +2 −6 config/config.js
  3. +13 −2 config/env/local.example.js
  4. +2 −2 gruntfile.js
@@ -22,6 +22,7 @@ public/dist/
uploads
modules/users/client/img/profile/uploads
config/env/local.js
config/env/local-*.js
*.pem

# Ignoring MEAN.JS's gh-pages branch for documenation
@@ -187,12 +187,8 @@ var initGlobalConfig = function () {
var pkg = require(path.resolve('./package.json'));
config.meanjs = pkg;

// We only extend the config object with the local.js custom/local environment if we are on
// production or development environment. If test environment is used we don't merge it with local.js
// to avoid running test suites on a prod/dev environment (which delete records and make modifications)
if (process.env.NODE_ENV !== 'test') {
config = _.merge(config, (fs.existsSync(path.join(process.cwd(), 'config/env/local.js')) && require(path.join(process.cwd(), 'config/env/local.js'))) || {});
}
// Extend the config object with the local-NODE_ENV.js custom/local environment. This will override any settings present in the local configuration.
config = _.merge(config, (fs.existsSync(path.join(process.cwd(), 'config/env/local-' + process.env.NODE_ENV + '.js')) && require(path.join(process.cwd(), 'config/env/local-' + process.env.NODE_ENV + '.js'))) || {});

// Initialize global globbed files
initGlobalConfigFiles(config, assets);
@@ -1,10 +1,21 @@
'use strict';

// Rename this file to local.js for having a local configuration variables that
// Rename this file to local-NODE_ENV.js (i.e. local-development.js, or local-test.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:
// WARNING: When using this example for multiple NODE_ENV's concurrently, make sure you update the 'db' settings appropriately.
// You do not want to accidentally overwrite/lose any data. For instance, if you create a file for 'test' and don't change the
// database name in the setting below, running the tests will drop all the data from the specified database.
//
// You may end up with a list of files, that will be used with their corresponding NODE_ENV:
//
// local-development.js
// local-test.js
// local-production.js
//

/* For example (Development):
module.exports = {
db: {
@@ -218,9 +218,9 @@ module.exports = function (grunt) {
copy: {
localConfig: {
src: 'config/env/local.example.js',
dest: 'config/env/local.js',
dest: 'config/env/local-development.js',
filter: function () {
return !fs.existsSync('config/env/local.js');
return !fs.existsSync('config/env/local-development.js');
}
}
}

0 comments on commit 6d74474

Please sign in to comment.
You can’t perform that action at this time.