Skip to content

Commit

Permalink
Release 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Vheissu committed Sep 3, 2015
1 parent 79de0a5 commit 2156cca
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 10 deletions.
56 changes: 54 additions & 2 deletions dist/amd/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
56 changes: 54 additions & 2 deletions dist/commonjs/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
75 changes: 73 additions & 2 deletions dist/es6/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

/**
Expand Down
Loading

0 comments on commit 2156cca

Please sign in to comment.