Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mdreizin committed Nov 19, 2015
2 parents b51311c + 29d45ac commit 4ca05a6
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');

```
12 changes: 6 additions & 6 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) ⇒ <code>Array.&lt;String&gt;</code>
* [.value(key)](#ConfigEnvironment+value) ⇒ <code>\*</code>
* [.get(key)](#ConfigEnvironment+get) ⇒ <code>\*</code>
* [.reset()](#ConfigEnvironment+reset)

<a name="new_ConfigEnvironment_new"></a>
Expand All @@ -244,8 +244,8 @@ Adds `process.env` to `variables` by default
| --- | --- |
| ...arguments | <code>Object</code> |

<a name="ConfigEnvironment+add"></a>
### configEnvironment.add(...arguments)
<a name="ConfigEnvironment+set"></a>
### configEnvironment.set(...arguments)
Adds custom `variables`

**Kind**: instance method of <code>[ConfigEnvironment](#ConfigEnvironment)</code>
Expand All @@ -259,8 +259,8 @@ Adds custom `variables`
Gets keys

**Kind**: instance method of <code>[ConfigEnvironment](#ConfigEnvironment)</code>
<a name="ConfigEnvironment+value"></a>
### configEnvironment.value(key) ⇒ <code>\*</code>
<a name="ConfigEnvironment+get"></a>
### configEnvironment.get(key) ⇒ <code>\*</code>
Gets value from `variables` or `process.env` as fallback

**Kind**: instance method of <code>[ConfigEnvironment](#ConfigEnvironment)</code>
Expand Down
1 change: 1 addition & 0 deletions docs/samples/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
8 changes: 4 additions & 4 deletions lib/configEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)) {
Expand All @@ -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);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/configNameResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@
"dependencies": {
"lodash": "^3.10.1"
},
"version": "1.2.0"
"version": "2.0.0"
}
18 changes: 9 additions & 9 deletions test/configEnvironment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 4ca05a6

Please sign in to comment.