From ff34743ea00664f450b084f1c5b74760c953bc43 Mon Sep 17 00:00:00 2001 From: Dwayne Charrington Date: Thu, 3 Mar 2016 15:14:21 +1000 Subject: [PATCH] chore(all): release 1.0.4 --- dist/amd/aurelia-configuration.d.ts | 172 ++++ ...{configure.js => aurelia-configuration.js} | 87 +- dist/amd/index.js | 26 - dist/aurelia-configuration.d.ts | 332 ++++---- .../configure.js => aurelia-configuration.js} | 118 +-- dist/commonjs/aurelia-configuration.d.ts | 172 ++++ ...{configure.js => aurelia-configuration.js} | 89 +- dist/commonjs/index.js | 26 - dist/es6/aurelia-configuration.d.ts | 172 ++++ dist/es6/aurelia-configuration.js | 321 ++++++++ dist/es6/index.js | 22 - dist/system/aurelia-configuration.d.ts | 172 ++++ ...{configure.js => aurelia-configuration.js} | 93 +-- dist/system/index.js | 34 - doc/CHANGELOG.md | 25 + doc/api.json | 778 +++++++++++++++++- package.json | 4 +- test/configure.spec.js | 87 -- 18 files changed, 2148 insertions(+), 582 deletions(-) create mode 100644 dist/amd/aurelia-configuration.d.ts rename dist/amd/{configure.js => aurelia-configuration.js} (77%) delete mode 100644 dist/amd/index.js rename dist/{es6/configure.js => aurelia-configuration.js} (78%) create mode 100644 dist/commonjs/aurelia-configuration.d.ts rename dist/commonjs/{configure.js => aurelia-configuration.js} (79%) delete mode 100644 dist/commonjs/index.js create mode 100644 dist/es6/aurelia-configuration.d.ts create mode 100644 dist/es6/aurelia-configuration.js delete mode 100644 dist/es6/index.js create mode 100644 dist/system/aurelia-configuration.d.ts rename dist/system/{configure.js => aurelia-configuration.js} (76%) delete mode 100644 dist/system/index.js delete mode 100644 test/configure.spec.js diff --git a/dist/amd/aurelia-configuration.d.ts b/dist/amd/aurelia-configuration.d.ts new file mode 100644 index 0000000..3f0cdc6 --- /dev/null +++ b/dist/amd/aurelia-configuration.d.ts @@ -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; +} \ No newline at end of file diff --git a/dist/amd/configure.js b/dist/amd/aurelia-configuration.js similarity index 77% rename from dist/amd/configure.js rename to dist/amd/aurelia-configuration.js index 9ee5128..e70f050 100644 --- a/dist/amd/configure.js +++ b/dist/amd/aurelia-configuration.js @@ -1,18 +1,13 @@ -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) { @@ -20,32 +15,32 @@ define(['exports', 'core-js', 'aurelia-dependency-injection', 'aurelia-loader'], 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(); } @@ -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) { @@ -159,14 +154,14 @@ 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() { @@ -174,40 +169,20 @@ define(['exports', 'core-js', 'aurelia-dependency-injection', 'aurelia-loader'], }; 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; } }]); @@ -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; }); \ No newline at end of file diff --git a/dist/amd/index.js b/dist/amd/index.js deleted file mode 100644 index 5e8e575..0000000 --- a/dist/amd/index.js +++ /dev/null @@ -1,26 +0,0 @@ -define(['exports', './configure'], function (exports, _configure) { - 'use strict'; - - exports.__esModule = true; - exports.configure = configure; - - function configure(aurelia, configCallback) { - var instance = aurelia.container.get(_configure.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.Configure; -}); \ No newline at end of file diff --git a/dist/aurelia-configuration.d.ts b/dist/aurelia-configuration.d.ts index c352b9f..3f0cdc6 100644 --- a/dist/aurelia-configuration.d.ts +++ b/dist/aurelia-configuration.d.ts @@ -1,180 +1,172 @@ declare module 'aurelia-configuration' { - import { HttpClient } from 'aurelia-http-client'; - + import { inject } from 'aurelia-dependency-injection'; + import { join } from 'aurelia-path'; + import { Loader } from 'aurelia-loader'; export class Configure { - constructor(http: HttpClient); - - /** - * Set Directory - * Sets the location to look for the config file - * - * @param path - */ - setDirectory(path: string): void; - - /** - * Set Config - * Sets the filename to look for in the defined directory - * - * @param name - */ - setConfig(name: string): void; - - /** - * Set Environment - * Changes the environment value - * - * @param environment - */ - setEnvironment(environment: string): void; - - /** - * Set Environments - * Specify multiple environment domains to allow for - * dynamic environment switching. - * - * @param environments - */ - setEnvironments(environments?: any): void; - - /** - * 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?: boolean): void; - - /** - * Get Config - * Returns the entire configuration object pulled and parsed from file - * - * @returns {V} - */ + 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 Environment - * Gets the current environment value - * - * @returns {V} - */ - environment: string; - - /** - * Get Environments - * Gets any user supplied environment mappings - * - * @returns {array} - */ - environments: string[]; - - /** - * Get Cascade Mode - * Gets the current cascade mode boolean - * @returns {boolean} - */ - cascadeMode: boolean; - - /** - * Get Directory - * Gets the current directory - * - * @returns {V} - */ - directory: string; - - /** - * Get Config - * Get the config file name - * - * @returns {V} - */ - config: string; - - /** - * Is - * A method for determining if the current environment - * equals that of the supplied environment value - * @param environment - * @returns {boolean} - */ - is(environment: string): boolean; - - /** - * Check - * Looks for a match of the hostName to any of the domain - * values specified during the configuration bootstrapping - * phase of Aurelia. - * - */ - check(): void; - - /** - * Environment Enabled - * A handy method for determining if we are using the default - * environment or have another specified like; staging - * - * @returns {boolean} - */ - environmentEnabled(): boolean; - - /** - * Environment Exists - * Checks if the environment section actually exists within - * the configuration file or defaults to default - * - * @returns {boolean} - */ - environmentExists(): boolean; - - /** - * 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: string, defaultValue?: any): any; - - /** - * Set - * Saves a config value temporarily - * - * @param key - * @param val - */ - set(key: string, val: any): void; - - /** - * Set All - * A dangerous method that sets the entire config object - * only used during bootstrapping phase - * - * @param obj - */ - setAll(obj: any): void; - - /** - * Get All - * Returns all configuration options as an object - * - * @returns {V} - */ + * 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(): Promise; + * 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; } \ No newline at end of file diff --git a/dist/es6/configure.js b/dist/aurelia-configuration.js similarity index 78% rename from dist/es6/configure.js rename to dist/aurelia-configuration.js index 343cf75..6362ff2 100644 --- a/dist/es6/configure.js +++ b/dist/aurelia-configuration.js @@ -1,29 +1,21 @@ -import 'core-js'; - import {inject} from 'aurelia-dependency-injection'; +import {join} from 'aurelia-path'; import {Loader} from 'aurelia-loader'; -// 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(); -const CASCADE_MODE = new WeakMap(); - @inject(Loader) export class Configure { + constructor(loader) { // Injected dependencies this.loader = loader; - - CONFIG_OBJECT.set(this, {}); - - ENVIRONMENT.set(this, 'default'); - ENVIRONMENTS.set(this, false); - DIRECTORY.set(this, 'config'); - CONFIG_FILE.set(this, 'config.json'); - CASCADE_MODE.set(this, true); + + this.environment = 'default'; + this.environments = false; + this.directory = 'config'; + this.config_file = 'config.json'; + this.cascade_mode = true; + + this._config_object = {}; } /** @@ -34,7 +26,7 @@ export class Configure { * @param path */ setDirectory(path) { - DIRECTORY.set(this, path); + this.directory = path; } /** @@ -45,7 +37,7 @@ export class Configure { * @param name */ setConfig(name) { - CONFIG_FILE.set(this, name); + this.config_file = name; } /** @@ -56,7 +48,7 @@ export class Configure { * @param environment */ setEnvironment(environment) { - ENVIRONMENT.set(this, environment); + this.environment = environment; } /** @@ -69,7 +61,7 @@ export class Configure { */ setEnvironments(environments = false) { if (environments) { - ENVIRONMENTS.set(this, environments); + this.environments = environments; // Check the hostname value and determine our environment this.check(); @@ -87,7 +79,7 @@ export class Configure { * @param bool */ setCascadeMode(bool = true) { - CASCADE_MODE.set(this, bool); + this.cascade_mode = bool; } /** @@ -98,50 +90,7 @@ export class Configure { * @returns {V} */ get obj() { - return CONFIG_OBJECT.get(this); - } - - /** - * Get Environment - * - * Gets the current environment value - * - * @returns {V} - */ - get environment() { - 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 - * @returns {boolean} - */ - get cascadeMode() { - return CASCADE_MODE.get(this); - } - - /** - * Get Directory - * - * Gets the current directory - * - * @returns {V} - */ - get directory() { - return DIRECTORY.get(this); + return this._config_object; } /** @@ -152,7 +101,7 @@ export class Configure { * @returns {V} */ get config() { - return CONFIG_FILE.get(this); + return this.config_file; } /** @@ -307,10 +256,10 @@ export class Configure { * */ merge(obj) { - let currentConfig = CONFIG_OBJECT.get(this); + let currentConfig = this._config_object; let merged = Object.assign(currentConfig, obj); - CONFIG_OBJECT.set(this, merged); + this._config_object = merged; } /** @@ -322,7 +271,7 @@ export class Configure { * @param obj */ setAll(obj) { - CONFIG_OBJECT.set(this, obj); + this._config_object = obj; } /** @@ -343,7 +292,30 @@ export class Configure { * @returns {Promise} */ loadConfig() { - return this.loader.loadText(`${this.directory}/${this.config}`) - .catch(() => reject(new Error('Configuration file could not be found or loaded.'))); + return this.loader.loadText(join(this.directory, this.config)) + .catch(() => { + throw new Error('Configuration file could not be found or loaded.') + }); } } + +export function configure(aurelia, configCallback) { + var instance = aurelia.container.get(Configure); + + // Do we have a callback function? + if (configCallback !== undefined && typeof(configCallback) === 'function') { + configCallback(instance); + } + + return new Promise((resolve, reject) => { + instance.loadConfig().then(data => { + data = JSON.parse(data); + instance.setAll(data); + resolve(); + }).catch(() => { + reject(new Error('Configuration file could not be loaded')); + }); + }) +} + +export {Configure}; diff --git a/dist/commonjs/aurelia-configuration.d.ts b/dist/commonjs/aurelia-configuration.d.ts new file mode 100644 index 0000000..3f0cdc6 --- /dev/null +++ b/dist/commonjs/aurelia-configuration.d.ts @@ -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; +} \ No newline at end of file diff --git a/dist/commonjs/configure.js b/dist/commonjs/aurelia-configuration.js similarity index 79% rename from dist/commonjs/configure.js rename to dist/commonjs/aurelia-configuration.js index 448228b..076d547 100644 --- a/dist/commonjs/configure.js +++ b/dist/commonjs/aurelia-configuration.js @@ -4,20 +4,15 @@ 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; -require('core-js'); +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var _aureliaDependencyInjection = require('aurelia-dependency-injection'); -var _aureliaLoader = require('aurelia-loader'); +var _aureliaPath = require('aurelia-path'); -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(); +var _aureliaLoader = require('aurelia-loader'); var Configure = (function () { function Configure(loader) { @@ -25,32 +20,32 @@ var Configure = (function () { 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(); } @@ -59,7 +54,7 @@ var Configure = (function () { 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) { @@ -164,14 +159,14 @@ var Configure = (function () { }; 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() { @@ -179,40 +174,20 @@ var Configure = (function () { }; 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; } }]); @@ -221,4 +196,24 @@ var Configure = (function () { return Configure; })(); +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; \ No newline at end of file diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js deleted file mode 100644 index 7c9dbc8..0000000 --- a/dist/commonjs/index.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -exports.__esModule = true; -exports.configure = configure; - -var _configure = require('./configure'); - -function configure(aurelia, configCallback) { - var instance = aurelia.container.get(_configure.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.Configure; \ No newline at end of file diff --git a/dist/es6/aurelia-configuration.d.ts b/dist/es6/aurelia-configuration.d.ts new file mode 100644 index 0000000..3f0cdc6 --- /dev/null +++ b/dist/es6/aurelia-configuration.d.ts @@ -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; +} \ No newline at end of file diff --git a/dist/es6/aurelia-configuration.js b/dist/es6/aurelia-configuration.js new file mode 100644 index 0000000..6362ff2 --- /dev/null +++ b/dist/es6/aurelia-configuration.js @@ -0,0 +1,321 @@ +import {inject} from 'aurelia-dependency-injection'; +import {join} from 'aurelia-path'; +import {Loader} from 'aurelia-loader'; + +@inject(Loader) +export class Configure { + + constructor(loader) { + // Injected dependencies + this.loader = loader; + + this.environment = 'default'; + this.environments = false; + this.directory = 'config'; + this.config_file = 'config.json'; + this.cascade_mode = true; + + this._config_object = {}; + } + + /** + * Set Directory + * + * Sets the location to look for the config file + * + * @param path + */ + setDirectory(path) { + this.directory = path; + } + + /** + * Set Config + * + * Sets the filename to look for in the defined directory + * + * @param name + */ + setConfig(name) { + this.config_file = name; + } + + /** + * Set Environment + * + * Changes the environment value + * + * @param environment + */ + setEnvironment(environment) { + this.environment = environment; + } + + /** + * Set Environments + * + * Specify multiple environment domains to allow for + * dynamic environment switching. + * + * @param environments + */ + setEnvironments(environments = false) { + if (environments) { + this.environments = 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) { + this.cascade_mode = bool; + } + + /** + * Get Config + * + * Returns the entire configuration object pulled and parsed from file + * + * @returns {V} + */ + get obj() { + return this._config_object; + } + + /** + * Get Config + * + * Get the config file name + * + * @returns {V} + */ + get config() { + return this.config_file; + } + + /** + * 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 + * environment or have another specified like; staging + * + * @returns {boolean} + */ + environmentEnabled() { + return (this.environment === 'default' || this.environment === '' || !this.environment) ? false : true; + } + + /** + * Environment Exists + * Checks if the environment section actually exists within + * the configuration file or defaults to default + * + * @returns {boolean} + */ + environmentExists() { + return (typeof this.obj[this.environment] === undefined) ? false : true; + } + + /** + * 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, defaultValue = null) { + // By default return the default value + let returnVal = defaultValue; + + // Singular non-namespaced value + if (key.indexOf('.') === -1) { + // Using default environment + if (!this.environmentEnabled()) { + return this.obj[key] ? this.obj[key] : defaultValue; + } else { + if (this.environmentExists()) { + // Value exists in environment + if (this.obj[this.environment][key]) { + returnVal = this.obj[this.environment][key]; + // Get default value from non-namespaced section if enabled + } else if (this.cascadeMode && this.obj[key]) { + returnVal = this.obj[key]; + } + } + + return returnVal; + } + } else { + let splitKey = key.split('.'); + let parent = splitKey[0]; + let child = splitKey[1]; + + if (!this.environmentEnabled()) { + if (this.obj[parent]) { + return this.obj[parent][child] ? this.obj[parent][child] : defaultValue; + } + } else { + if (this.environmentExists()) { + if (this.obj[this.environment][parent] && this.obj[this.environment][parent][child]) { + returnVal = this.obj[this.environment][parent][child]; + } else if (this.cascadeMode && this.obj[parent] && this.obj[parent][child]) { + returnVal = this.obj[parent][child]; + } + } + + return returnVal; + } + } + } + + /** + * Set + * Saves a config value temporarily + * + * @param key + * @param val + */ + set(key, val) { + if (key.indexOf('.') === -1) { + this.obj[key] = val; + } else { + let splitKey = key.split('.'); + let parent = splitKey[0]; + let child = splitKey[1]; + + if (this.obj[parent] === undefined) { + this.obj[parent] = {}; + } + + this.obj[parent][child] = val; + } + } + + /** + * 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) { + let currentConfig = this._config_object; + let merged = Object.assign(currentConfig, obj); + + this._config_object = merged; + } + + /** + * 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) { + this._config_object = obj; + } + + /** + * Get All + * Returns all configuration options as an object + * + * @returns {V} + */ + getAll() { + return this.obj; + } + + /** + * Load Config + * Loads the configuration file from specified location + * and then returns a Promise + * + * @returns {Promise} + */ + loadConfig() { + return this.loader.loadText(join(this.directory, this.config)) + .catch(() => { + throw new Error('Configuration file could not be found or loaded.') + }); + } +} + +export function configure(aurelia, configCallback) { + var instance = aurelia.container.get(Configure); + + // Do we have a callback function? + if (configCallback !== undefined && typeof(configCallback) === 'function') { + configCallback(instance); + } + + return new Promise((resolve, reject) => { + instance.loadConfig().then(data => { + data = JSON.parse(data); + instance.setAll(data); + resolve(); + }).catch(() => { + reject(new Error('Configuration file could not be loaded')); + }); + }) +} + +export {Configure}; diff --git a/dist/es6/index.js b/dist/es6/index.js deleted file mode 100644 index 3770ac3..0000000 --- a/dist/es6/index.js +++ /dev/null @@ -1,22 +0,0 @@ -import {Configure} from './configure'; - -export function configure(aurelia, configCallback) { - var instance = aurelia.container.get(Configure); - - // Do we have a callback function? - if (configCallback !== undefined && typeof(configCallback) === 'function') { - configCallback(instance); - } - - return new Promise((resolve, reject) => { - instance.loadConfig().then(data => { - data = JSON.parse(data); - instance.setAll(data); - resolve(); - }); - }).catch(() => { - reject(new Error('Configuration file could not be loaded')); - }); -} - -export {Configure}; diff --git a/dist/system/aurelia-configuration.d.ts b/dist/system/aurelia-configuration.d.ts new file mode 100644 index 0000000..3f0cdc6 --- /dev/null +++ b/dist/system/aurelia-configuration.d.ts @@ -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; +} \ No newline at end of file diff --git a/dist/system/configure.js b/dist/system/aurelia-configuration.js similarity index 76% rename from dist/system/configure.js rename to dist/system/aurelia-configuration.js index 292aaf6..db7eaef 100644 --- a/dist/system/configure.js +++ b/dist/system/aurelia-configuration.js @@ -1,58 +1,73 @@ -System.register(['core-js', 'aurelia-dependency-injection', 'aurelia-loader'], function (_export) { +System.register(['aurelia-dependency-injection', 'aurelia-path', 'aurelia-loader'], function (_export) { 'use strict'; - var inject, Loader, ENVIRONMENT, ENVIRONMENTS, DIRECTORY, CONFIG_FILE, CONFIG_OBJECT, CASCADE_MODE, Configure; + var inject, join, Loader, 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; }; })(); + _export('configure', configure); + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + 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')); + }); + }); + } + return { - setters: [function (_coreJs) {}, function (_aureliaDependencyInjection) { + setters: [function (_aureliaDependencyInjection) { inject = _aureliaDependencyInjection.inject; + }, function (_aureliaPath) { + join = _aureliaPath.join; }, function (_aureliaLoader) { Loader = _aureliaLoader.Loader; }], execute: function () { - ENVIRONMENT = new WeakMap(); - ENVIRONMENTS = new WeakMap(); - DIRECTORY = new WeakMap(); - CONFIG_FILE = new WeakMap(); - CONFIG_OBJECT = new WeakMap(); - CASCADE_MODE = new WeakMap(); - 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(); } @@ -61,7 +76,7 @@ System.register(['core-js', 'aurelia-dependency-injection', 'aurelia-loader'], f 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) { @@ -166,14 +181,14 @@ System.register(['core-js', 'aurelia-dependency-injection', 'aurelia-loader'], f }; 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() { @@ -181,40 +196,20 @@ System.register(['core-js', 'aurelia-dependency-injection', 'aurelia-loader'], f }; 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(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; } }]); @@ -224,6 +219,8 @@ System.register(['core-js', 'aurelia-dependency-injection', 'aurelia-loader'], f })(); _export('Configure', Configure); + + _export('Configure', Configure); } }; }); \ No newline at end of file diff --git a/dist/system/index.js b/dist/system/index.js deleted file mode 100644 index 88afa1b..0000000 --- a/dist/system/index.js +++ /dev/null @@ -1,34 +0,0 @@ -System.register(['./configure'], function (_export) { - 'use strict'; - - var Configure; - - _export('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')); - }); - } - - return { - setters: [function (_configure) { - Configure = _configure.Configure; - }], - execute: function () { - _export('Configure', Configure); - } - }; -}); \ No newline at end of file diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 7e03d2d..f89716b 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,28 @@ +### 1.0.4 (2016-03-03) + + +#### Bug Fixes + +* **all:** + * rely on path for loading config files to allow overrides and use path helper ([608d1476](http://github.com/Vheissu/Aurelia-Configuration/commit/608d147664babba85753bc8e6844e500129a3f58)) + * instantiate class properties from within constructor ([798e4104](http://github.com/Vheissu/Aurelia-Configuration/commit/798e41047c18882588b753905e258b7d4c3d781d)) + * changed build process to generate TypeScript definition files and more. ([f4db5f9e](http://github.com/Vheissu/Aurelia-Configuration/commit/f4db5f9efbfb75dc0c5614d9429fa67b4162342c)) + * removing core-js dependency ([ccb31f76](http://github.com/Vheissu/Aurelia-Configuration/commit/ccb31f760cafffb9b177878f68fb90e975c66e7e)) +* **configure:** + * remove weakmaps so we can have a polyfill free class ([346faf92](http://github.com/Vheissu/Aurelia-Configuration/commit/346faf92147cedd0d23634c8769283a4b8036d14)) + * parse data response as JSON ([e2a9a834](http://github.com/Vheissu/Aurelia-Configuration/commit/e2a9a834bee38099f83368b199ecfd0413209344)) +* **dependencies:** + * updating and fixing out-of-date dependencies ([75583c6d](http://github.com/Vheissu/Aurelia-Configuration/commit/75583c6d6e2257611e355757a5dd8bc6c7170959)) + * updating Aurelia dependencies again and fixing config.js file ([b5a33032](http://github.com/Vheissu/Aurelia-Configuration/commit/b5a33032b0b8732e2feb0fa787453e7e4bb4e7e6)) + * updating dependencies to beta versions for Aurelia and other dev deps ([5dd4eda0](http://github.com/Vheissu/Aurelia-Configuration/commit/5dd4eda009a64495a2ea33dede4f3ccd912ba4c7)) +* **package:** change JSPM registry format to Github ([4e54b748](http://github.com/Vheissu/Aurelia-Configuration/commit/4e54b748a93c9619d8bd76b9c885c3a87d332dad)) + + +#### Features + +* **configure:** use the Aurelia loader dependency to load configuration files instead of HTTP ([2b9a8144](http://github.com/Vheissu/Aurelia-Configuration/commit/2b9a81449f22f5a04b554ef61584fca42fbd44f7)) + + ### 1.0.3 (04-09-2015) * Added in new setEnvironments method for dynamic environments * New is method for checking the current environment diff --git a/doc/api.json b/doc/api.json index 6de3c0a..01c8530 100644 --- a/doc/api.json +++ b/doc/api.json @@ -1 +1,777 @@ -{"classes":[],"methods":[],"properties":[],"events":[]} \ No newline at end of file +{ + "id": 2, + "name": "\"aurelia-configuration\"", + "kind": 2, + "kindString": "Module", + "flags": {}, + "children": [ + { + "id": 3, + "name": "Configure", + "kind": 128, + "kindString": "Class", + "flags": { + "isExported": true + }, + "children": [ + { + "id": 4, + "name": "constructor", + "kind": 512, + "kindString": "Constructor", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 5, + "name": "new Configure", + "kind": 16384, + "kindString": "Constructor signature", + "flags": {}, + "parameters": [ + { + "id": 6, + "name": "loader", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "reference", + "name": "Configure", + "id": 3, + "moduleName": "\"aurelia-configuration\"" + } + } + ] + }, + { + "id": 23, + "name": "config", + "kind": 1024, + "kindString": "Property", + "flags": { + "isExported": true + }, + "comment": { + "shortText": "Get Config", + "text": "Get the config file name\n", + "tags": [ + { + "tag": "returns", + "text": "\n" + } + ] + }, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 22, + "name": "obj", + "kind": 1024, + "kindString": "Property", + "flags": { + "isExported": true + }, + "comment": { + "shortText": "Get Config", + "text": "Returns the entire configuration object pulled and parsed from file\n", + "tags": [ + { + "tag": "returns", + "text": "\n" + } + ] + }, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 27, + "name": "check", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 28, + "name": "check", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Check\nLooks for a match of the hostName to any of the domain\nvalues specified during the configuration bootstrapping\nphase of Aurelia." + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 29, + "name": "environmentEnabled", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 30, + "name": "environmentEnabled", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Environment Enabled\nA handy method for determining if we are using the default\nenvironment or have another specified like; staging", + "returns": "\n" + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 31, + "name": "environmentExists", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 32, + "name": "environmentExists", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Environment Exists\nChecks if the environment section actually exists within\nthe configuration file or defaults to default", + "returns": "\n" + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 33, + "name": "get", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 34, + "name": "get", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Get\nGets a configuration value from the main config object\nwith support for a default value if nothing found", + "returns": "\n" + }, + "parameters": [ + { + "id": 35, + "name": "key", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "comment": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 36, + "name": "defaultValue", + "kind": 32768, + "kindString": "Parameter", + "flags": { + "isOptional": true + }, + "comment": {}, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 47, + "name": "getAll", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 48, + "name": "getAll", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Get All\nReturns all configuration options as an object", + "returns": "\n" + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 24, + "name": "is", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 25, + "name": "is", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Is", + "text": "A method for determining if the current environment\nequals that of the supplied environment value*", + "returns": "\n" + }, + "parameters": [ + { + "id": 26, + "name": "environment", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "comment": {}, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 49, + "name": "loadConfig", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 50, + "name": "loadConfig", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Load Config\nLoads the configuration file from specified location\nand then returns a Promise", + "returns": "\n" + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 41, + "name": "merge", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 42, + "name": "merge", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Merge", + "text": "Allows you to merge in configuration options\nthis method might be used to merge in server-loaded\nconfiguration options with local ones.\n" + }, + "parameters": [ + { + "id": 43, + "name": "obj", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "comment": { + "text": "\n\n" + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 37, + "name": "set", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 38, + "name": "set", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Set\nSaves a config value temporarily" + }, + "parameters": [ + { + "id": 39, + "name": "key", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "comment": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 40, + "name": "val", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "comment": { + "text": "\n" + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 44, + "name": "setAll", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 45, + "name": "setAll", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Set All\nSets and overwrites the entire configuration object\nused internally, but also can be used to set the configuration\nfrom outside of the usual JSON loading logic." + }, + "parameters": [ + { + "id": 46, + "name": "obj", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "comment": { + "text": "\n" + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 19, + "name": "setCascadeMode", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 20, + "name": "setCascadeMode", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Set Cascade Mode", + "text": "By default if a environment config value is not found, it will\ngo looking up the config file to find it (a la inheritance style). Sometimes\nyou just want a config value from a specific environment and nowhere else\nuse this to disabled this functionality\n" + }, + "parameters": [ + { + "id": 21, + "name": "bool", + "kind": 32768, + "kindString": "Parameter", + "flags": { + "isOptional": true + }, + "comment": { + "text": "\n" + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 10, + "name": "setConfig", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 11, + "name": "setConfig", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Set Config", + "text": "Sets the filename to look for in the defined directory\n" + }, + "parameters": [ + { + "id": 12, + "name": "name", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "comment": { + "text": "\n" + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 7, + "name": "setDirectory", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 8, + "name": "setDirectory", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Set Directory", + "text": "Sets the location to look for the config file\n" + }, + "parameters": [ + { + "id": 9, + "name": "path", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "comment": { + "text": "\n" + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 13, + "name": "setEnvironment", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 14, + "name": "setEnvironment", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Set Environment", + "text": "Changes the environment value\n" + }, + "parameters": [ + { + "id": 15, + "name": "environment", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "comment": { + "text": "\n" + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + }, + { + "id": 16, + "name": "setEnvironments", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 17, + "name": "setEnvironments", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "Set Environments", + "text": "Specify multiple environment domains to allow for\ndynamic environment switching.\n" + }, + "parameters": [ + { + "id": 18, + "name": "environments", + "kind": 32768, + "kindString": "Parameter", + "flags": { + "isOptional": true + }, + "comment": { + "text": "\n" + }, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + } + ], + "groups": [ + { + "title": "Constructors", + "kind": 512, + "children": [ + 4 + ] + }, + { + "title": "Properties", + "kind": 1024, + "children": [ + 23, + 22 + ] + }, + { + "title": "Methods", + "kind": 2048, + "children": [ + 27, + 29, + 31, + 33, + 47, + 24, + 49, + 41, + 37, + 44, + 19, + 10, + 7, + 13, + 16 + ] + } + ] + }, + { + "id": 51, + "name": "configure", + "kind": 64, + "kindString": "Function", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 52, + "name": "configure", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "parameters": [ + { + "id": 53, + "name": "aurelia", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + }, + { + "id": 54, + "name": "configCallback", + "kind": 32768, + "kindString": "Parameter", + "flags": {}, + "type": { + "type": "instrinct", + "name": "any" + } + } + ], + "type": { + "type": "instrinct", + "name": "any" + } + } + ] + } + ], + "groups": [ + { + "title": "Classes", + "kind": 128, + "children": [ + 3 + ] + }, + { + "title": "Functions", + "kind": 64, + "children": [ + 51 + ] + } + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 8462f29..2979479 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-configuration", - "version": "1.0.3", + "version": "1.0.4", "description": "An Aurelia plugin for adding in configuration to your application.", "keywords": [ "aurelia", @@ -31,7 +31,7 @@ "peerDependencies": { "aurelia-dependency-injection": "^1.0.0-beta.1.1.4", "aurelia-loader": "^1.0.0-beta.1.1.1", - "aurelia-path": "^1.0.0-beta.1.1.0" + "aurelia-path": "^1.0.0-beta.1.1.0" }, "dependencies": { "aurelia-dependency-injection": "^1.0.0-beta.1.1.4", diff --git a/test/configure.spec.js b/test/configure.spec.js deleted file mode 100644 index e266dad..0000000 --- a/test/configure.spec.js +++ /dev/null @@ -1,87 +0,0 @@ -import {Configure} from '../src/configure'; - -class HttpStub { - get(url) { - - } -} - -describe('configure.js -- ', () => { - var config; - var mockedHttp; - - beforeEach(() => { - mockedHttp = new HttpStub(); - config = new Configure(mockedHttp); - - spyOn(config, 'loadConfig').and.callFake(() => { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve({ - name: "Test Application", - version: 1.0 - }); - }, 500); - }) - }); - }); - - describe('Basic tests: ', () => { - it('default directory value should be set', () => { - expect(config.directory).toEqual('config'); - }); - - it('default config file value should be set', () => { - expect(config.config).toEqual('application.json'); - }); - - it('default config object should be empty', () => { - expect(config.obj).toBeDefined(); - }); - - it('constructor should inject classes', () => { - expect(config.http).toBeDefined(); - }); - - it('loadConfig method should have been called', () => { - config.loadConfig(); - expect(config.loadConfig).toHaveBeenCalled(); - }); - }); - - describe('Config tests: ', () => { - it('change config directory', (done) => { - config.setDirectory('testdir'); - setTimeout(() => { - expect(config.directory).toEqual('testdir'); - done(); - }, 0); - }); - - it('change config filename', (done) => { - config.setConfig('testconfig.json'); - setTimeout(() => { - expect(config.config).toEqual('testconfig.json'); - done(); - }, 0); - }); - - it('set single config value', (done) => { - config.set('mykey', 'myval'); - setTimeout(() => { - expect(config.get('mykey')).toEqual('myval'); - done(); - }, 0); - }); - - it('set namespaced config value', (done) => { - config.set('mykey.childkey', 'myval'); - console.log(config.getAll()); - setTimeout(() => { - expect(config.get('mykey.childkey')).toEqual('myval'); - done(); - }, 0); - }); - }); - -});