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

Commit 6d74474

Browse files
committed
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.
1 parent e140880 commit 6d74474

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public/dist/
2222
uploads
2323
modules/users/client/img/profile/uploads
2424
config/env/local.js
25+
config/env/local-*.js
2526
*.pem
2627

2728
# Ignoring MEAN.JS's gh-pages branch for documenation

config/config.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,8 @@ var initGlobalConfig = function () {
187187
var pkg = require(path.resolve('./package.json'));
188188
config.meanjs = pkg;
189189

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

197193
// Initialize global globbed files
198194
initGlobalConfigFiles(config, assets);

config/env/local.example.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
'use strict';
22

3-
// Rename this file to local.js for having a local configuration variables that
3+
// Rename this file to local-NODE_ENV.js (i.e. local-development.js, or local-test.js) for having a local configuration variables that
44
// will not get commited and pushed to remote repositories.
55
// Use it for your API keys, passwords, etc.
66

7-
/* For example:
7+
// WARNING: When using this example for multiple NODE_ENV's concurrently, make sure you update the 'db' settings appropriately.
8+
// You do not want to accidentally overwrite/lose any data. For instance, if you create a file for 'test' and don't change the
9+
// database name in the setting below, running the tests will drop all the data from the specified database.
10+
//
11+
// You may end up with a list of files, that will be used with their corresponding NODE_ENV:
12+
//
13+
// local-development.js
14+
// local-test.js
15+
// local-production.js
16+
//
17+
18+
/* For example (Development):
819
920
module.exports = {
1021
db: {

gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ module.exports = function (grunt) {
218218
copy: {
219219
localConfig: {
220220
src: 'config/env/local.example.js',
221-
dest: 'config/env/local.js',
221+
dest: 'config/env/local-development.js',
222222
filter: function () {
223-
return !fs.existsSync('config/env/local.js');
223+
return !fs.existsSync('config/env/local-development.js');
224224
}
225225
}
226226
}

0 commit comments

Comments
 (0)