Skip to content

Commit

Permalink
chore(all): release 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Vheissu committed Mar 3, 2016
1 parent 7535678 commit ff34743
Show file tree
Hide file tree
Showing 18 changed files with 2,148 additions and 582 deletions.
172 changes: 172 additions & 0 deletions dist/amd/aurelia-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
declare module 'aurelia-configuration' {
import { inject } from 'aurelia-dependency-injection';
import { join } from 'aurelia-path';
import { Loader } from 'aurelia-loader';
export class Configure {
constructor(loader: any);

/**
* Set Directory
*
* Sets the location to look for the config file
*
* @param path
*/
setDirectory(path: any): any;

/**
* Set Config
*
* Sets the filename to look for in the defined directory
*
* @param name
*/
setConfig(name: any): any;

/**
* Set Environment
*
* Changes the environment value
*
* @param environment
*/
setEnvironment(environment: any): any;

/**
* Set Environments
*
* Specify multiple environment domains to allow for
* dynamic environment switching.
*
* @param environments
*/
setEnvironments(environments?: any): any;

/**
* 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?: any): any;

/**
* Get Config
*
* Returns the entire configuration object pulled and parsed from file
*
* @returns {V}
*/
obj: any;

/**
* Get Config
*
* Get the config file name
*
* @returns {V}
*/
config: any;

/**
* Is
*
* A method for determining if the current environment
* equals that of the supplied environment value*
* @param environment
* @returns {boolean}
*/
is(environment: any): any;

/**
* Check
* Looks for a match of the hostName to any of the domain
* values specified during the configuration bootstrapping
* phase of Aurelia.
*
*/
check(): any;

/**
* Environment Enabled
* A handy method for determining if we are using the default
* environment or have another specified like; staging
*
* @returns {boolean}
*/
environmentEnabled(): any;

/**
* Environment Exists
* Checks if the environment section actually exists within
* the configuration file or defaults to default
*
* @returns {boolean}
*/
environmentExists(): any;

/**
* Get
* Gets a configuration value from the main config object
* with support for a default value if nothing found
*
* @param key
* @param defaultValue
* @returns {*}
*/
get(key: any, defaultValue?: any): any;

/**
* Set
* Saves a config value temporarily
*
* @param key
* @param val
*/
set(key: any, val: any): any;

/**
* Merge
*
* Allows you to merge in configuration options
* this method might be used to merge in server-loaded
* configuration options with local ones.
*
* @param obj
*
*/
merge(obj: any): any;

/**
* Set All
* Sets and overwrites the entire configuration object
* used internally, but also can be used to set the configuration
* from outside of the usual JSON loading logic.
*
* @param obj
*/
setAll(obj: any): any;

/**
* Get All
* Returns all configuration options as an object
*
* @returns {V}
*/
getAll(): any;

/**
* Load Config
* Loads the configuration file from specified location
* and then returns a Promise
*
* @returns {Promise}
*/
loadConfig(): any;
}
export function configure(aurelia: any, configCallback: any): any;
}
87 changes: 41 additions & 46 deletions dist/amd/configure.js → dist/amd/aurelia-configuration.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,46 @@
define(['exports', 'core-js', 'aurelia-dependency-injection', 'aurelia-loader'], function (exports, _coreJs, _aureliaDependencyInjection, _aureliaLoader) {
define(['exports', 'aurelia-dependency-injection', 'aurelia-path', 'aurelia-loader'], function (exports, _aureliaDependencyInjection, _aureliaPath, _aureliaLoader) {
'use strict';

exports.__esModule = true;

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; }; })();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
exports.configure = configure;

var ENVIRONMENT = new WeakMap();
var ENVIRONMENTS = new WeakMap();
var DIRECTORY = new WeakMap();
var CONFIG_FILE = new WeakMap();
var CONFIG_OBJECT = new WeakMap();
var CASCADE_MODE = new WeakMap();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

var Configure = (function () {
function Configure(loader) {
_classCallCheck(this, _Configure);

this.loader = loader;

CONFIG_OBJECT.set(this, {});
this.environment = 'default';
this.environments = false;
this.directory = 'config';
this.config_file = 'config.json';
this.cascade_mode = true;

ENVIRONMENT.set(this, 'default');
ENVIRONMENTS.set(this, false);
DIRECTORY.set(this, 'config');
CONFIG_FILE.set(this, 'config.json');
CASCADE_MODE.set(this, true);
this._config_object = {};
}

Configure.prototype.setDirectory = function setDirectory(path) {
DIRECTORY.set(this, path);
this.directory = path;
};

Configure.prototype.setConfig = function setConfig(name) {
CONFIG_FILE.set(this, name);
this.config_file = name;
};

Configure.prototype.setEnvironment = function setEnvironment(environment) {
ENVIRONMENT.set(this, environment);
this.environment = environment;
};

Configure.prototype.setEnvironments = function setEnvironments() {
var environments = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];

if (environments) {
ENVIRONMENTS.set(this, environments);
this.environments = environments;

this.check();
}
Expand All @@ -54,7 +49,7 @@ define(['exports', 'core-js', 'aurelia-dependency-injection', 'aurelia-loader'],
Configure.prototype.setCascadeMode = function setCascadeMode() {
var bool = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];

CASCADE_MODE.set(this, bool);
this.cascade_mode = bool;
};

Configure.prototype.is = function is(environment) {
Expand Down Expand Up @@ -159,55 +154,35 @@ define(['exports', 'core-js', 'aurelia-dependency-injection', 'aurelia-loader'],
};

Configure.prototype.merge = function merge(obj) {
var currentConfig = CONFIG_OBJECT.get(this);
var currentConfig = this._config_object;
var merged = Object.assign(currentConfig, obj);

CONFIG_OBJECT.set(this, merged);
this._config_object = merged;
};

Configure.prototype.setAll = function setAll(obj) {
CONFIG_OBJECT.set(this, obj);
this._config_object = obj;
};

Configure.prototype.getAll = function getAll() {
return this.obj;
};

Configure.prototype.loadConfig = function loadConfig() {
return this.loader.loadText(this.directory + '/' + this.config)['catch'](function () {
return reject(new Error('Configuration file could not be found or loaded.'));
return this.loader.loadText(_aureliaPath.join(this.directory, this.config))['catch'](function () {
throw new Error('Configuration file could not be found or loaded.');
});
};

_createClass(Configure, [{
key: 'obj',
get: function get() {
return CONFIG_OBJECT.get(this);
}
}, {
key: 'environment',
get: function get() {
return ENVIRONMENT.get(this);
}
}, {
key: 'environments',
get: function get() {
return ENVIRONMENTS.get(this);
}
}, {
key: 'cascadeMode',
get: function get() {
return CASCADE_MODE.get(this);
}
}, {
key: 'directory',
get: function get() {
return DIRECTORY.get(this);
return this._config_object;
}
}, {
key: 'config',
get: function get() {
return CONFIG_FILE.get(this);
return this.config_file;
}
}]);

Expand All @@ -217,4 +192,24 @@ define(['exports', 'core-js', 'aurelia-dependency-injection', 'aurelia-loader'],
})();

exports.Configure = Configure;

function configure(aurelia, configCallback) {
var instance = aurelia.container.get(Configure);

if (configCallback !== undefined && typeof configCallback === 'function') {
configCallback(instance);
}

return new Promise(function (resolve, reject) {
instance.loadConfig().then(function (data) {
data = JSON.parse(data);
instance.setAll(data);
resolve();
})['catch'](function () {
reject(new Error('Configuration file could not be loaded'));
});
});
}

exports.Configure = Configure;
});
26 changes: 0 additions & 26 deletions dist/amd/index.js

This file was deleted.

Loading

0 comments on commit ff34743

Please sign in to comment.