From 92534fa4094ed21923d3bde90e096c0dd3a49206 Mon Sep 17 00:00:00 2001 From: Marat Dreizin Date: Thu, 19 Nov 2015 10:37:30 +0300 Subject: [PATCH 1/3] refactor(configEnvironment): renames some methods BREAKING CHANGE: Some methods have been renamed. Please use `#set()` instead `#add()` and `#set()` instead `#value()`. --- docs/API.md | 12 ++++++------ lib/configEnvironment.js | 8 ++++---- lib/configNameResolver.js | 2 +- test/configEnvironment.spec.js | 18 +++++++++--------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/API.md b/docs/API.md index 948a706..dcf100f 100644 --- a/docs/API.md +++ b/docs/API.md @@ -230,9 +230,9 @@ Returns plain object * [ConfigEnvironment](#ConfigEnvironment) * [new ConfigEnvironment(...arguments)](#new_ConfigEnvironment_new) - * [.add(...arguments)](#ConfigEnvironment+add) + * [.set(...arguments)](#ConfigEnvironment+set) * [.keys()](#ConfigEnvironment+keys) ⇒ Array.<String> - * [.value(key)](#ConfigEnvironment+value) ⇒ \* + * [.get(key)](#ConfigEnvironment+get) ⇒ \* * [.reset()](#ConfigEnvironment+reset) @@ -244,8 +244,8 @@ Adds `process.env` to `variables` by default | --- | --- | | ...arguments | Object | - -### configEnvironment.add(...arguments) + +### configEnvironment.set(...arguments) Adds custom `variables` **Kind**: instance method of [ConfigEnvironment](#ConfigEnvironment) @@ -259,8 +259,8 @@ Adds custom `variables` Gets keys **Kind**: instance method of [ConfigEnvironment](#ConfigEnvironment) - -### configEnvironment.value(key) ⇒ \* + +### configEnvironment.get(key) ⇒ \* Gets value from `variables` or `process.env` as fallback **Kind**: instance method of [ConfigEnvironment](#ConfigEnvironment) diff --git a/lib/configEnvironment.js b/lib/configEnvironment.js index e3994d3..6a6426a 100644 --- a/lib/configEnvironment.js +++ b/lib/configEnvironment.js @@ -29,14 +29,14 @@ function ConfigEnvironment() { var args = _.flatten(_.toArray(arguments), true); this.reset(); - this.add(args); + this.set(args); } /** * Adds custom `variables` * @param {...Object} arguments */ -ConfigEnvironment.prototype.add = function() { +ConfigEnvironment.prototype.set = function() { var args = _.flatten(_.toArray(arguments), true); args.forEach(function(variables) { @@ -57,7 +57,7 @@ ConfigEnvironment.prototype.keys = function() { * @param {String} key * @returns {*} */ -ConfigEnvironment.prototype.value = function(key) { +ConfigEnvironment.prototype.get = function(key) { var value = _.result(this.variables, key); if (_.isUndefined(value)) { @@ -73,7 +73,7 @@ ConfigEnvironment.prototype.value = function(key) { ConfigEnvironment.prototype.reset = function() { this.variables = {}; - this.add(process.env, DEFAULT_VARIABLES); + this.set(process.env, DEFAULT_VARIABLES); }; /** diff --git a/lib/configNameResolver.js b/lib/configNameResolver.js index e34866f..2f0c709 100644 --- a/lib/configNameResolver.js +++ b/lib/configNameResolver.js @@ -28,7 +28,7 @@ ConfigNameResolver.prototype.resolve = function(filename) { this.patterns[key] = pattern; } - var value = this.environment.value(key); + var value = this.environment.get(key); filename = filename.replace(pattern, value); }, this); diff --git a/test/configEnvironment.spec.js b/test/configEnvironment.spec.js index 7e35d74..4d26328 100644 --- a/test/configEnvironment.spec.js +++ b/test/configEnvironment.spec.js @@ -20,36 +20,36 @@ describe('ConfigEnvironment', function () { }); it('should return "process.env.WEBPACK_ENV"', function() { - expect(configEnvironment.value('WEBPACK_ENV')).to.eql('foo'); + expect(configEnvironment.get('WEBPACK_ENV')).to.eql('foo'); }); it('should return "process.env.NODE_ENV"', function() { - expect(configEnvironment.value('NODE_ENV')).to.eql('bar'); + expect(configEnvironment.get('NODE_ENV')).to.eql('bar'); }); it('should return "env"', function() { - expect(configEnvironment.value('env')).to.eql('foo'); + expect(configEnvironment.get('env')).to.eql('foo'); }); }); context('#add()', function() { it('should add custom values', function() { - configEnvironment.add({ + configEnvironment.set({ rev: 1 }); - expect(configEnvironment.value('rev')).to.eql(1); + expect(configEnvironment.get('rev')).to.eql(1); }); it('should override existing values', function() { - configEnvironment.add({ + configEnvironment.set({ WEBPACK_ENV: 1, // eslint-disable-line NODE_ENV: 2 // eslint-disable-line }); - expect(configEnvironment.value('WEBPACK_ENV')).to.eql(1); - expect(configEnvironment.value('NODE_ENV')).to.eql(2); - expect(configEnvironment.value('env')).to.eql(1); + expect(configEnvironment.get('WEBPACK_ENV')).to.eql(1); + expect(configEnvironment.get('NODE_ENV')).to.eql(2); + expect(configEnvironment.get('env')).to.eql(1); }); }); }); From c1bf0e0fbb7a5fb2e452cd095a94953ca195dbf7 Mon Sep 17 00:00:00 2001 From: Marat Dreizin Date: Thu, 19 Nov 2015 10:40:35 +0300 Subject: [PATCH 2/3] docs(configEnvironment): adds simple example how to use environment variables --- README.md | 1 + docs/samples/webpack.config.js | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index e271bbe..5a7e5b0 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,7 @@ module.exports = new WebpackConfig().extend({ var WebpackConfig = require('webpack-config'); +// Please use `process.env.WEBPACK_ENV || process.env.NODE_ENV` to set `[env]` or override it via `WebpackConfig.environment.set({ env: 'dev' })`. module.exports = new WebpackConfig().extend('./conf/webpack.[env].config.js'); ``` diff --git a/docs/samples/webpack.config.js b/docs/samples/webpack.config.js index b2c31b6..ed6d314 100644 --- a/docs/samples/webpack.config.js +++ b/docs/samples/webpack.config.js @@ -2,4 +2,5 @@ var WebpackConfig = require('webpack-config'); +// Please use `process.env.WEBPACK_ENV || process.env.NODE_ENV` to set `[env]` variable or override it via `WebpackConfig.environment.set({ env: 'dev' })`. module.exports = new WebpackConfig().extend('./conf/webpack.[env].config.js'); From 29d45ac5b3f0347754b28538505e16b916894b5c Mon Sep 17 00:00:00 2001 From: Marat Dreizin Date: Thu, 19 Nov 2015 07:43:50 +0000 Subject: [PATCH 3/3] v2.0.0 --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e0875c7..fed95bf 100644 --- a/package.json +++ b/package.json @@ -52,5 +52,6 @@ }, "dependencies": { "lodash": "^3.10.1" - } -} + }, + "version": "2.0.0" +} \ No newline at end of file