From 75c31af0cab2b6a169ec4a6455b5562b4c61d89c Mon Sep 17 00:00:00 2001 From: Daniel Zeiter Date: Thu, 26 Feb 2015 20:57:04 +0100 Subject: [PATCH 1/5] Update dependency on lodash to 3.0.1 The template function changed --- gulp-ng-config.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gulp-ng-config.js b/gulp-ng-config.js index d7ca3c0..0ce34ed 100644 --- a/gulp-ng-config.js +++ b/gulp-ng-config.js @@ -48,7 +48,7 @@ function gulpNgConfig (moduleName, configuration) { }); }); - templateOutput = _.template(templateFile, { + templateOutput = _.template(templateFile)({ createModule: configuration.createModule, moduleName: moduleName, constants: constants @@ -60,7 +60,7 @@ function gulpNgConfig (moduleName, configuration) { } else { wrapTemplate = WRAP_TEAMPLTE; } - templateOutput = _.template(wrapTemplate, { + templateOutput = _.template(wrapTemplate)({ module: templateOutput }); } diff --git a/package.json b/package.json index 92a35f9..a9d3a8d 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "homepage": "https://github.com/ajwhite/gulp-ng-config", "dependencies": { "gulp-util": "^3.0.0", - "lodash": "^2.4.1", + "lodash": "^3.0.1", "through2": "^1.1.1" }, "devDependencies": { From 8b61a78113ca688ce968537ac4987ad47ed3acf3 Mon Sep 17 00:00:00 2001 From: Atticus White Date: Thu, 12 Mar 2015 01:26:35 -0400 Subject: [PATCH 2/5] Create LICENSE.md --- LICENSE.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..3a05de2 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Atticus White + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 744a312acde51dd4321c322ff07971218727380a Mon Sep 17 00:00:00 2001 From: Atticus White Date: Sun, 29 Mar 2015 15:42:21 -0400 Subject: [PATCH 3/5] allow environment key to be supplied --- gulp-ng-config.js | 8 +++++++- package.json | 2 +- test/mocks/input_3.json | 12 ++++++++++++ test/mocks/output_10.js | 3 +++ test/mocks/output_8.js | 2 ++ test/mocks/output_9.js | 2 ++ test/stream.js | 37 +++++++++++++++++++++++++++++++++++++ 7 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 test/mocks/input_3.json create mode 100644 test/mocks/output_10.js create mode 100644 test/mocks/output_8.js create mode 100644 test/mocks/output_9.js diff --git a/gulp-ng-config.js b/gulp-ng-config.js index 0ce34ed..a4fb1e0 100644 --- a/gulp-ng-config.js +++ b/gulp-ng-config.js @@ -12,7 +12,8 @@ function gulpNgConfig (moduleName, configuration) { var templateFile, stream, defaults; defaults = { createModule: true, - wrap: false + wrap: false, + environment: null }; if (!moduleName) { @@ -41,6 +42,11 @@ function gulpNgConfig (moduleName, configuration) { jsonObj = _.merge({}, jsonObj, configuration.constants || {}); + // select the environment in the configuration + if (configuration.environment && jsonObj.hasOwnProperty(configuration.environment)) { + jsonObj = jsonObj[configuration.environment]; + } + _.each(jsonObj, function (value, key) { constants.push({ name: key, diff --git a/package.json b/package.json index a9d3a8d..72a0524 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "devDependencies": { "chai": "^1.9.1", "chai-spies": "^0.5.1", - "event-stream": "^3.1.7", + "event-stream": "^3.3.0", "gulp": "^3.8.7", "gulp-jscs": "^1.3.1", "gulp-jshint": "^1.8.4", diff --git a/test/mocks/input_3.json b/test/mocks/input_3.json new file mode 100644 index 0000000..b724e83 --- /dev/null +++ b/test/mocks/input_3.json @@ -0,0 +1,12 @@ +{ + "environmentA": { + "one": { + "two": "three" + } + }, + "environmentB": { + "four": { + "five": "six" + } + } +} diff --git a/test/mocks/output_10.js b/test/mocks/output_10.js new file mode 100644 index 0000000..3e2ad6d --- /dev/null +++ b/test/mocks/output_10.js @@ -0,0 +1,3 @@ +angular.module('gulp-ng-config', []) +.constant('environmentA', {"one":{"two":"three"}}) +.constant('environmentB', {"four":{"five":"six"}}); diff --git a/test/mocks/output_8.js b/test/mocks/output_8.js new file mode 100644 index 0000000..5565881 --- /dev/null +++ b/test/mocks/output_8.js @@ -0,0 +1,2 @@ +angular.module('gulp-ng-config', []) +.constant('one', {"two":"three"}); diff --git a/test/mocks/output_9.js b/test/mocks/output_9.js new file mode 100644 index 0000000..ab23a47 --- /dev/null +++ b/test/mocks/output_9.js @@ -0,0 +1,2 @@ +angular.module('gulp-ng-config', []) +.constant('four', {"five":"six"}); diff --git a/test/stream.js b/test/stream.js index 5f6e87b..4f0c0ab 100644 --- a/test/stream.js +++ b/test/stream.js @@ -166,5 +166,42 @@ describe('gulp-ng-config', function () { done(); })); }); + it ('should select an embedded json object if an environment key is supplied and the key exists', function (done) { + var expectedOutputA = fs.readFileSync(path.normalize(__dirname + '/mocks/output_8.js')), // match envA + expectedOutputB = fs.readFileSync(path.normalize(__dirname + '/mocks/output_9.js')), // match envB + expectedOutputC = fs.readFileSync(path.normalize(__dirname + '/mocks/output_10.js')), // no match + streamA = gulp.src(path.normalize(__dirname + '/mocks/input_3.json')), + streamB = gulp.src(path.normalize(__dirname + '/mocks/input_3.json')), + streamC = gulp.src(path.normalize(__dirname + '/mocks/input_3.json')); + + // tests output with `environmentA` + streamA.pipe(plugin('gulp-ng-config', { + environment: 'environmentA' + })) + .pipe(through.obj(function (file) { + expect(file.contents.toString()).to.equal(expectedOutputA.toString()); + })); + + // tests output with `environmentB` + streamB.pipe(plugin('gulp-ng-config', { + environment: 'environmentB' + })) + .pipe(through.obj(function (file) { + expect(file.contents.toString()).to.equal(expectedOutputB.toString()); + })); + + // tests output with no matching environment key + streamC.pipe(plugin('gulp-ng-config', { + environment: 'nonExistant' + })) + .pipe(through.obj(function (file) { + expect(file.contents.toString()).to.equal(expectedOutputC.toString()); + })); + + es.merge(streamA, streamB, streamC) + .pipe(through.obj(function () { + done(); + })); + }); }); }); From 6762f1731363db5849dff93feb26c635da622170 Mon Sep 17 00:00:00 2001 From: Atticus White Date: Sun, 29 Mar 2015 15:47:29 -0400 Subject: [PATCH 4/5] readme --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 8f75af6..1b4c8ac 100644 --- a/README.md +++ b/README.md @@ -54,10 +54,44 @@ angular.module('myApp', ['myApp.config']).run(function (string) { ## Configuration Currently there are a few configurable options to control the output of your configuration file: +- [options.environment](#options.environment) - [options.constants](#options.constants) - [options.createModule](#options.createModule) - [options.wrap](#options.wrap) +### options.environment +Type: `String` Optional + +If your configuration contains multiple environments, you can supply the key you want the plugin to load from your configuration file. + +Example `config.json` file with multiple environments: +```json +{ + "local": { + "EnvironmentConfig": { + "api": "http://localhost/" + } + }, + "production": { + "EnvironmentConfig": { + "api": "https://api.production.com/" + } + } +} +``` + +Usage of the plugin: +```js +gulpNgConfig('myApp.config', { + environment: 'production' +}) +``` + +Expected output: +```js +angular.module('myApp.config', []) +.contant('EnvironmentConfig', {"api": "https://api.production.com/"}); +``` ### options.constants Type: `Object` Optional From 342895590fbca296d75ca587b9be90b7788e5fea Mon Sep 17 00:00:00 2001 From: Atticus White Date: Sun, 29 Mar 2015 16:00:11 -0400 Subject: [PATCH 5/5] v1.1.0 bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 72a0524..3ed83fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-ng-config", - "version": "1.0.0", + "version": "1.1.0", "description": "AngularJS configuration generator for a module of constants", "main": "index.js", "scripts": {