From 2156ccaae3dc0edf1a1fd3cfd6547808ebabbc5d Mon Sep 17 00:00:00 2001 From: Dwayne Charrington Date: Fri, 4 Sep 2015 09:48:30 +1000 Subject: [PATCH] Release 1.0.3 --- dist/amd/configure.js | 56 +++++++++++++++++++++++++++- dist/commonjs/configure.js | 56 +++++++++++++++++++++++++++- dist/es6/configure.js | 75 +++++++++++++++++++++++++++++++++++++- dist/system/configure.js | 58 +++++++++++++++++++++++++++-- doc/CHANGELOG.md | 6 +++ package.json | 2 +- 6 files changed, 243 insertions(+), 10 deletions(-) diff --git a/dist/amd/configure.js b/dist/amd/configure.js index 6309169..ae05c9c 100644 --- a/dist/amd/configure.js +++ b/dist/amd/configure.js @@ -8,6 +8,7 @@ define(['exports', 'core-js', 'aurelia-dependency-injection', 'aurelia-http-clie function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var ENVIRONMENT = new WeakMap(); + var ENVIRONMENTS = new WeakMap(); var DIRECTORY = new WeakMap(); var CONFIG_FILE = new WeakMap(); var CONFIG_OBJECT = new WeakMap(); @@ -22,7 +23,8 @@ define(['exports', 'core-js', 'aurelia-dependency-injection', 'aurelia-http-clie CONFIG_OBJECT.set(this, {}); - ENVIRONMENT.set(this, 'DEFAULT'); + ENVIRONMENT.set(this, 'default'); + ENVIRONMENTS.set(this, false); DIRECTORY.set(this, 'config'); CONFIG_FILE.set(this, 'application.json'); CASCADE_MODE.set(this, true); @@ -40,14 +42,59 @@ define(['exports', 'core-js', 'aurelia-dependency-injection', 'aurelia-http-clie ENVIRONMENT.set(this, environment); }; + Configure.prototype.setEnvironments = function setEnvironments() { + var environments = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + + if (environments) { + ENVIRONMENTS.set(this, environments); + + this.check(); + } + }; + Configure.prototype.setCascadeMode = function setCascadeMode() { var bool = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0]; CASCADE_MODE.set(this, bool); }; + Configure.prototype.is = function is(environment) { + return environment === this.environment; + }; + + Configure.prototype.check = function check() { + var hostname = window.location.hostname; + + if (this.environments) { + for (var env in this.environments) { + var hostnames = this.environments[env]; + + if (hostnames) { + for (var _iterator = hostnames, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var host = _ref; + + if (hostname.search(host) !== -1) { + this.setEnvironment(env); + } + } + } + } + } + }; + Configure.prototype.environmentEnabled = function environmentEnabled() { - return this.environment === 'DEFAULT' || this.environment === '' || !this.environment ? false : true; + return this.environment === 'default' || this.environment === '' || !this.environment ? false : true; }; Configure.prototype.environmentExists = function environmentExists() { @@ -138,6 +185,11 @@ define(['exports', 'core-js', 'aurelia-dependency-injection', 'aurelia-http-clie get: function get() { return ENVIRONMENT.get(this); } + }, { + key: 'environments', + get: function get() { + return ENVIRONMENTS.get(this); + } }, { key: 'cascadeMode', get: function get() { diff --git a/dist/commonjs/configure.js b/dist/commonjs/configure.js index 8936d03..c46b18a 100644 --- a/dist/commonjs/configure.js +++ b/dist/commonjs/configure.js @@ -15,6 +15,7 @@ var _aureliaHttpClient = require('aurelia-http-client'); var _aureliaEventAggregator = require('aurelia-event-aggregator'); var ENVIRONMENT = new WeakMap(); +var ENVIRONMENTS = new WeakMap(); var DIRECTORY = new WeakMap(); var CONFIG_FILE = new WeakMap(); var CONFIG_OBJECT = new WeakMap(); @@ -29,7 +30,8 @@ var Configure = (function () { CONFIG_OBJECT.set(this, {}); - ENVIRONMENT.set(this, 'DEFAULT'); + ENVIRONMENT.set(this, 'default'); + ENVIRONMENTS.set(this, false); DIRECTORY.set(this, 'config'); CONFIG_FILE.set(this, 'application.json'); CASCADE_MODE.set(this, true); @@ -47,14 +49,59 @@ var Configure = (function () { ENVIRONMENT.set(this, environment); }; + Configure.prototype.setEnvironments = function setEnvironments() { + var environments = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + + if (environments) { + ENVIRONMENTS.set(this, environments); + + this.check(); + } + }; + Configure.prototype.setCascadeMode = function setCascadeMode() { var bool = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0]; CASCADE_MODE.set(this, bool); }; + Configure.prototype.is = function is(environment) { + return environment === this.environment; + }; + + Configure.prototype.check = function check() { + var hostname = window.location.hostname; + + if (this.environments) { + for (var env in this.environments) { + var hostnames = this.environments[env]; + + if (hostnames) { + for (var _iterator = hostnames, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var host = _ref; + + if (hostname.search(host) !== -1) { + this.setEnvironment(env); + } + } + } + } + } + }; + Configure.prototype.environmentEnabled = function environmentEnabled() { - return this.environment === 'DEFAULT' || this.environment === '' || !this.environment ? false : true; + return this.environment === 'default' || this.environment === '' || !this.environment ? false : true; }; Configure.prototype.environmentExists = function environmentExists() { @@ -145,6 +192,11 @@ var Configure = (function () { get: function get() { return ENVIRONMENT.get(this); } + }, { + key: 'environments', + get: function get() { + return ENVIRONMENTS.get(this); + } }, { key: 'cascadeMode', get: function get() { diff --git a/dist/es6/configure.js b/dist/es6/configure.js index 16db226..c5a0f8a 100644 --- a/dist/es6/configure.js +++ b/dist/es6/configure.js @@ -6,6 +6,7 @@ import {EventAggregator} from 'aurelia-event-aggregator'; // Secure references that can't be changed outside of Configure singleton class const ENVIRONMENT = new WeakMap(); +const ENVIRONMENTS = new WeakMap(); const DIRECTORY = new WeakMap(); const CONFIG_FILE = new WeakMap(); const CONFIG_OBJECT = new WeakMap(); @@ -20,7 +21,8 @@ export class Configure { CONFIG_OBJECT.set(this, {}); - ENVIRONMENT.set(this, 'DEFAULT'); + ENVIRONMENT.set(this, 'default'); + ENVIRONMENTS.set(this, false); DIRECTORY.set(this, 'config'); CONFIG_FILE.set(this, 'application.json'); CASCADE_MODE.set(this, true); @@ -56,12 +58,30 @@ export class Configure { ENVIRONMENT.set(this, environment); } + /** + * Set Environments + * Specify multiple environment domains to allow for + * dynamic environment switching. + * + * @param environments + */ + setEnvironments(environments = false) { + if (environments) { + ENVIRONMENTS.set(this, environments); + + // Check the hostname value and determine our environment + this.check(); + } + } + /** * Set Cascade Mode * By default if a environment config value is not found, it will * go looking up the config file to find it (a la inheritance style). Sometimes * you just want a config value from a specific environment and nowhere else * use this to disabled this functionality + * + * @param bool */ setCascadeMode(bool = true) { CASCADE_MODE.set(this, bool); @@ -87,6 +107,16 @@ export class Configure { return ENVIRONMENT.get(this); } + /** + * Get Environments + * Gets any user supplied environment mappings + * + * @returns {array} + */ + get environments() { + return ENVIRONMENTS.get(this); + } + /** * Get Cascade Mode * Gets the current cascade mode boolean @@ -116,6 +146,47 @@ export class Configure { return CONFIG_FILE.get(this); } + /** + * Is + * A method for determining if the current environment + * equals that of the supplied environment value* + * @param environment + * @returns {boolean} + */ + is(environment) { + return (environment === this.environment); + } + + /** + * Check + * Looks for a match of the hostName to any of the domain + * values specified during the configuration bootstrapping + * phase of Aurelia. + * + */ + check() { + let hostname = window.location.hostname; + + // Check we have environments we can loop + if (this.environments) { + // Loop over supplied environments + for (let env in this.environments) { + // Get environment hostnames + let hostnames = this.environments[env]; + + // Make sure we have hostnames + if (hostnames) { + // Loop the hostnames + for (let host of hostnames) { + if (hostname.search(host) !== -1) { + this.setEnvironment(env); + } + } + } + } + } + } + /** * Environment Enabled * A handy method for determining if we are using the default @@ -124,7 +195,7 @@ export class Configure { * @returns {boolean} */ environmentEnabled() { - return (this.environment === 'DEFAULT' || this.environment === '' || !this.environment) ? false : true; + return (this.environment === 'default' || this.environment === '' || !this.environment) ? false : true; } /** diff --git a/dist/system/configure.js b/dist/system/configure.js index ad18b4a..40df8f3 100644 --- a/dist/system/configure.js +++ b/dist/system/configure.js @@ -1,7 +1,7 @@ System.register(['core-js', 'aurelia-dependency-injection', 'aurelia-http-client', 'aurelia-event-aggregator'], function (_export) { 'use strict'; - var inject, HttpClient, EventAggregator, ENVIRONMENT, DIRECTORY, CONFIG_FILE, CONFIG_OBJECT, CASCADE_MODE, Configure; + var inject, HttpClient, EventAggregator, ENVIRONMENT, ENVIRONMENTS, DIRECTORY, CONFIG_FILE, CONFIG_OBJECT, CASCADE_MODE, Configure; var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); @@ -17,6 +17,7 @@ System.register(['core-js', 'aurelia-dependency-injection', 'aurelia-http-client }], execute: function () { ENVIRONMENT = new WeakMap(); + ENVIRONMENTS = new WeakMap(); DIRECTORY = new WeakMap(); CONFIG_FILE = new WeakMap(); CONFIG_OBJECT = new WeakMap(); @@ -31,7 +32,8 @@ System.register(['core-js', 'aurelia-dependency-injection', 'aurelia-http-client CONFIG_OBJECT.set(this, {}); - ENVIRONMENT.set(this, 'DEFAULT'); + ENVIRONMENT.set(this, 'default'); + ENVIRONMENTS.set(this, false); DIRECTORY.set(this, 'config'); CONFIG_FILE.set(this, 'application.json'); CASCADE_MODE.set(this, true); @@ -49,14 +51,59 @@ System.register(['core-js', 'aurelia-dependency-injection', 'aurelia-http-client ENVIRONMENT.set(this, environment); }; + Configure.prototype.setEnvironments = function setEnvironments() { + var environments = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + + if (environments) { + ENVIRONMENTS.set(this, environments); + + this.check(); + } + }; + Configure.prototype.setCascadeMode = function setCascadeMode() { var bool = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0]; CASCADE_MODE.set(this, bool); }; + Configure.prototype.is = function is(environment) { + return environment === this.environment; + }; + + Configure.prototype.check = function check() { + var hostname = window.location.hostname; + + if (this.environments) { + for (var env in this.environments) { + var hostnames = this.environments[env]; + + if (hostnames) { + for (var _iterator = hostnames, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { + var _ref; + + if (_isArray) { + if (_i >= _iterator.length) break; + _ref = _iterator[_i++]; + } else { + _i = _iterator.next(); + if (_i.done) break; + _ref = _i.value; + } + + var host = _ref; + + if (hostname.search(host) !== -1) { + this.setEnvironment(env); + } + } + } + } + } + }; + Configure.prototype.environmentEnabled = function environmentEnabled() { - return this.environment === 'DEFAULT' || this.environment === '' || !this.environment ? false : true; + return this.environment === 'default' || this.environment === '' || !this.environment ? false : true; }; Configure.prototype.environmentExists = function environmentExists() { @@ -147,6 +194,11 @@ System.register(['core-js', 'aurelia-dependency-injection', 'aurelia-http-client get: function get() { return ENVIRONMENT.get(this); } + }, { + key: 'environments', + get: function get() { + return ENVIRONMENTS.get(this); + } }, { key: 'cascadeMode', get: function get() { diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 7516606..7e03d2d 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,9 @@ +### 1.0.3 (04-09-2015) +* Added in new setEnvironments method for dynamic environments +* New is method for checking the current environment +* Better documentation +* Minor bugfixes and improvements + ### 1.0.2 (03-09-2015) * A tonne of bug fixes... * Get config method now has support for default values diff --git a/package.json b/package.json index 2b0394d..454dee6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-configuration", - "version": "1.0.2", + "version": "1.0.3", "description": "An Aurelia plugin for adding in configuration to your application.", "keywords": [ "aurelia",