easy-configuration
Advanced tools
Comparing version 1.6.6 to 2.0.0
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var EasyConfiguration, Extension, Helpers, merge; | ||
var EasyConfiguration, Extension, Helpers, callsite, isWindow, merge, path; | ||
@@ -11,12 +11,19 @@ merge = require('recursive-merge'); | ||
isWindow = typeof window !== 'undefined'; | ||
if (!isWindow) { | ||
callsite = require('callsite'); | ||
path = require('path'); | ||
} | ||
EasyConfiguration = (function() { | ||
EasyConfiguration.PARAMETER_REGEXP = /%([a-zA-Z.-_]+)%/g; | ||
EasyConfiguration.prototype.fileName = null; | ||
EasyConfiguration.prototype.files = null; | ||
EasyConfiguration.prototype.reserved = ['includes', 'parameters']; | ||
EasyConfiguration.prototype.reserved = null; | ||
EasyConfiguration.prototype.extensions = null; | ||
EasyConfiguration.prototype.files = null; | ||
EasyConfiguration.prototype.includes = null; | ||
@@ -29,10 +36,39 @@ EasyConfiguration.prototype._parameters = null; | ||
function EasyConfiguration(fileName) { | ||
this.fileName = fileName; | ||
function EasyConfiguration(_path, section) { | ||
if (_path == null) { | ||
_path = null; | ||
} | ||
if (section == null) { | ||
section = 'production'; | ||
} | ||
this.files = {}; | ||
this.reserved = ['includes', 'parameters', 'common']; | ||
this.extensions = {}; | ||
this.files = []; | ||
this.includes = {}; | ||
this._parameters = {}; | ||
this.parameters = {}; | ||
if (_path !== null) { | ||
this.addConfig(_path, section); | ||
} | ||
} | ||
EasyConfiguration.prototype.addConfig = function(_path, section) { | ||
var previous, stack; | ||
if (section == null) { | ||
section = 'production'; | ||
} | ||
if (_path[0] === '.' && isWindow) { | ||
throw new Error('Relative paths to config files are not supported in browser.'); | ||
} | ||
if (_path[0] === '.') { | ||
stack = callsite(); | ||
previous = stack[1].getFileName() === __filename ? stack[2] : stack[1]; | ||
_path = path.join(path.dirname(previous.getFileName()), _path); | ||
} | ||
if (Helpers.arrayIndexOf(this.reserved, section) === -1) { | ||
this.reserved.push(section); | ||
} | ||
return this.files[_path] = section; | ||
}; | ||
EasyConfiguration.prototype.addSection = function(name) { | ||
@@ -66,7 +102,12 @@ return this.addExtension(name, new Extension); | ||
EasyConfiguration.prototype.load = function() { | ||
var config, data; | ||
var config, data, section, _path, _ref; | ||
if (this.data === null) { | ||
config = this.loadConfig(this.fileName); | ||
config = {}; | ||
_ref = this.files; | ||
for (_path in _ref) { | ||
section = _ref[_path]; | ||
config = this.merge(this.loadConfig(_path, section), config); | ||
} | ||
data = this.parse(config); | ||
this.files = data.files; | ||
this.includes = data.files; | ||
this.parameters = data.parameters; | ||
@@ -78,6 +119,20 @@ this.data = data.sections; | ||
EasyConfiguration.prototype.loadConfig = function(file) { | ||
var data, include, path, _i, _len, _ref; | ||
EasyConfiguration.prototype.loadConfig = function(file, section) { | ||
var data, include, _data, _i, _len, _path, _ref; | ||
if (section == null) { | ||
section = 'production'; | ||
} | ||
data = require(file); | ||
data = Helpers.clone(data, false); | ||
if (typeof data[section] !== 'undefined' || typeof data.common !== 'undefined') { | ||
if (typeof data.common !== 'undefined') { | ||
_data = data.common; | ||
if (typeof data[section] !== 'undefined') { | ||
_data = this.merge(data[section], _data); | ||
} | ||
} else { | ||
_data = data[section]; | ||
} | ||
data = _data; | ||
} | ||
if (typeof data.includes !== 'undefined') { | ||
@@ -87,4 +142,4 @@ _ref = data.includes; | ||
include = _ref[_i]; | ||
path = Helpers.normalizePath(Helpers.dirName(file) + '/' + include); | ||
data = this.merge(data, this.loadConfig(path)); | ||
_path = Helpers.normalizePath(Helpers.dirName(file) + '/' + include); | ||
data = this.merge(data, this.loadConfig(_path)); | ||
} | ||
@@ -91,0 +146,0 @@ } |
{ | ||
"name": "easy-configuration", | ||
"description": "Simply extensible loader for json config files", | ||
"version": "1.6.6", | ||
"version": "2.0.0", | ||
"author": { | ||
@@ -27,11 +27,18 @@ "name": "David Kudera", | ||
"dependencies": { | ||
"recursive-merge": "~1.2.0" | ||
"recursive-merge": "~1.2.0", | ||
"callsite": "~1.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "~1.8.0", | ||
"mocha": "~1.14.0" | ||
"mocha": "~1.16.2", | ||
"mocha-phantomjs": "~3.3.1", | ||
"phantomjs": "~1.9.2-6" | ||
}, | ||
"scripts": { | ||
"test": "cd ./test; echo \"Testing in node:\"; mocha ./node/index.js --reporter spec; cd ./browser; echo \"Testing in browser:\"; mocha-phantomjs ./index.html;" | ||
"test": "npm run test-node && npm run test-browser", | ||
"build-and-test": "npm run test-build && npm run test", | ||
"test-build": "cd ./test/browser; simq build;", | ||
"test-node": "mocha ./test/node/index.js --reporter spec", | ||
"test-browser": "mocha-phantomjs ./test/browser/index.html" | ||
} | ||
} |
118
README.md
@@ -0,1 +1,5 @@ | ||
[![NPM version](https://badge.fury.io/js/easy-configuration.png)](http://badge.fury.io/js/easy-configuration) | ||
[![Dependency Status](https://gemnasium.com/sakren/node-easy-configuration.png)](https://gemnasium.com/sakren/node-easy-configuration) | ||
[![Build Status](https://travis-ci.org/sakren/node-easy-configuration.png?branch=master)](https://travis-ci.org/sakren/node-easy-configuration) | ||
# Easy Configuration | ||
@@ -15,3 +19,3 @@ | ||
var Configuration = require('easy-configuration'); | ||
var config = new Configuration('/var/data/config.json'); | ||
var config = new Configuration('./my/config.json'); | ||
@@ -21,7 +25,6 @@ var data = config.load(); | ||
Be careful with setting your path to the config file. Easy-Configuration uses required instead of fs module, because of | ||
ability to use it in browser. If you will set this path relatively, then it will be relative to the Easy-Configuration | ||
file, not to your actual file. | ||
**Relative paths to config files are supported only on node (not in browser)!!!** | ||
## Parameters | ||
In default, this configurator contains two basic sections: parameters and includes. | ||
@@ -44,2 +47,3 @@ Parameters section can holds all your variables which you will need in other sections | ||
## Including other config files | ||
If you will add section includes, you can set list of files, which you want to merge with main config file. | ||
@@ -56,19 +60,82 @@ Paths to these config files must be relative to main config file. | ||
## Own sections - main feature | ||
When you will try to add own section, Easy Configuration will tell you, that section was found, | ||
but there is no corresponding extension. | ||
There is example of registration a new one. | ||
## Different environments | ||
You may need different configuration for different environments (like production or development). First thing you need to | ||
do, is put your whole current configuration (also with all other sections - see below) into `common` section. | ||
**This feature is applied only to main config files, not to files included from `includes` section.** | ||
**It will be automatically turned on when there will be `common` section or section with name of current environment.** | ||
``` | ||
{ | ||
"common": { | ||
"parameters": { | ||
"database": {} | ||
} | ||
} | ||
} | ||
``` | ||
Common section is base section for all environments. But other environments can rewrite everything in `common` section. | ||
``` | ||
{ | ||
"common": { | ||
"parameters": { | ||
"database": { | ||
"host": "127.0.0.1", | ||
"user": "root", | ||
"database": "my-db" | ||
} | ||
} | ||
}, | ||
"production": { | ||
"parameters": { | ||
"database": { | ||
"password": "qwerty12345" | ||
} | ||
} | ||
}, | ||
"development": { | ||
"parameters": { | ||
"database": { | ||
"password": "root" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
Now we have got configuration with two different setups for database. | ||
``` | ||
process.env.NODE_ENV = 'production'; | ||
var config = new Configuration; | ||
config.addConfig('./some-config.json', process.env.NODE_ENV); // or new Configuration('./some-config.json', process.env.NODE_ENV); | ||
var data = config.load() | ||
console.log(config.parameters.database.password); // output: qwerty12345 | ||
``` | ||
With this setup, configurator will load data from `production` section merged with `common` section. | ||
## Own sections | ||
As you could see, there are prepared two base sections (`parameters` and `includes`). | ||
But you can create your own special sections. You just need to register them. | ||
``` | ||
var Configuration = require('easy-configuration'); | ||
var config = new Configuration('./config.json'); | ||
config.addSection('packages'); | ||
config.addSection('packages'); // register new section | ||
var data = config.load(); | ||
var packages = config.load().packages; // data from packages section in config.json file | ||
``` | ||
Now you will be able to add new section with name "packages" | ||
## Parameters in own sections | ||
## Parameters in own sections | ||
In your sections, you can use parameters from section "parameters". | ||
@@ -78,2 +145,3 @@ | ||
{ | ||
"parameters": { ... }, | ||
"packages": { | ||
@@ -102,4 +170,5 @@ "application": "%basePath%/application.js", | ||
## Customize packages | ||
Sometimes you may want to customize output of your package. Most simple way is to rewrite method loadConfiguration | ||
## Customize sections | ||
Sometimes you may want to customize output of your section. Most simple way is to rewrite method loadConfiguration | ||
of default Extension class. | ||
@@ -124,13 +193,10 @@ For example we always want some other data in our section, even if they are not in config file - let's say "defaults". | ||
section.loadConfiguration = function() { | ||
return this.getConfig(defaults); | ||
return this.getConfig(defaults); // data from your section will be merged with defaults variable | ||
}; | ||
var data = config.load(); | ||
var packages = config.load().packages; // updated data with defaults | ||
``` | ||
Method getConfig has got one optional argument and it is your defaults variable. This method will return configuration | ||
only of your section merged with defaults argument (if any). | ||
Of course, there can be more complex code. | ||
EasyConfiguration class has got one other useful method and it is merge (using [recursive-merge](https://npmjs.org/package/recursive-merge) package). | ||
With this you can create more complex sections. | ||
@@ -169,3 +235,3 @@ ``` | ||
var data = config.load(); | ||
var packages = config.load().packages; | ||
``` | ||
@@ -185,3 +251,3 @@ | ||
section.afterCompile = function(config) { | ||
return doSomething(config); | ||
return doSomeMagic(config); | ||
}; | ||
@@ -212,2 +278,10 @@ ``` | ||
* 2.0.0 | ||
+ Optimized tests | ||
+ Tests frameworks does not need to be installed globally (are in devDependencies) | ||
+ Added badges | ||
+ Added support for different environments | ||
+ Loading config files with relative paths in node.js | ||
+ Better documentation | ||
* 1.6.3 - 1.6.6 | ||
@@ -214,0 +288,0 @@ + Bugs in IE8 |
@@ -6,3 +6,3 @@ /** Generated by SimQ **/ | ||
(function() { | ||
var SUPPORTED, cache, modules, require, resolve, stats; | ||
var SUPPORTED, arrayIndexOf, cache, creating, modules, require, resolve, stats; | ||
@@ -14,2 +14,3 @@ if (!this.require) { | ||
cache = {}; | ||
creating = []; | ||
require = function(name, parent) { | ||
@@ -33,5 +34,11 @@ var fullName, m; | ||
}; | ||
modules[fullName].apply(modules[fullName], [m.exports, m]); | ||
if (arrayIndexOf(creating, fullName) === -1) { | ||
creating.push(fullName); | ||
modules[fullName].apply(window, [m.exports, m]); | ||
creating.splice(arrayIndexOf(creating, fullName)); | ||
cache[fullName] = m; | ||
} | ||
m.loaded = true; | ||
cache[fullName] = m; | ||
} else { | ||
m = cache[fullName]; | ||
} | ||
@@ -46,3 +53,3 @@ if (typeof stats[fullName] === 'undefined') { | ||
stats[fullName].atime = new Date; | ||
return cache[fullName].exports; | ||
return m.exports; | ||
}; | ||
@@ -96,2 +103,18 @@ resolve = function(name, parent) { | ||
}; | ||
arrayIndexOf = function(array, search) { | ||
var element, i, _i, _len; | ||
if (typeof Array.prototype.indexOf !== 'undefined') { | ||
return array.indexOf(search); | ||
} | ||
if (array.length === 0) { | ||
return -1; | ||
} | ||
for (i = _i = 0, _len = array.length; _i < _len; i = ++_i) { | ||
element = array[i]; | ||
if (element === search) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
}; | ||
this.require = function(name, parent) { | ||
@@ -111,10 +134,17 @@ if (parent == null) { | ||
}; | ||
this.require.define = function(bundle) { | ||
this.require.define = function(bundleOrName, obj) { | ||
var m, name, _results; | ||
_results = []; | ||
for (name in bundle) { | ||
m = bundle[name]; | ||
_results.push(modules[name] = m); | ||
if (obj == null) { | ||
obj = null; | ||
} | ||
return _results; | ||
if (typeof bundleOrName === 'string') { | ||
return modules[bundleOrName] = obj; | ||
} else { | ||
_results = []; | ||
for (name in bundleOrName) { | ||
m = bundleOrName[name]; | ||
_results.push(modules[name] = m); | ||
} | ||
return _results; | ||
} | ||
}; | ||
@@ -180,10 +210,27 @@ this.require.release = function() { | ||
(function() { | ||
var merge, | ||
var isArray, isObject, isScalar, merge, mergeArray, mergeObject, _type, | ||
__slice = [].slice; | ||
_type = Object.prototype.toString; | ||
isScalar = function(variable) { | ||
var _ref; | ||
return ((_ref = _type.call(variable)) !== '[object Array]' && _ref !== '[object Object]') || variable === null; | ||
}; | ||
isObject = function(variable) { | ||
return variable !== null && _type.call(variable) === '[object Object]'; | ||
}; | ||
isArray = function(variable) { | ||
return _type.call(variable) === '[object Array]'; | ||
}; | ||
merge = function(left, right) { | ||
var i, leftType, name, rightType, type, value, valueType, _i, _len; | ||
type = Object.prototype.toString; | ||
leftType = type.call(left); | ||
rightType = type.call(right); | ||
var leftType, rightType; | ||
if (isScalar(left) || isScalar(right)) { | ||
throw new Error('Can not merge scalar objects.'); | ||
} | ||
leftType = _type.call(left); | ||
rightType = _type.call(right); | ||
if (leftType !== rightType) { | ||
@@ -194,31 +241,55 @@ throw new Error('Can not merge ' + leftType + ' with ' + rightType + '.'); | ||
case '[object Array]': | ||
for (i = _i = 0, _len = right.length; _i < _len; i = ++_i) { | ||
value = right[i]; | ||
valueType = type.call(value); | ||
if ((valueType === '[object Array]' || valueType === '[object Object]') && value !== null) { | ||
left[i] = merge(left[i], value); | ||
} else { | ||
left.push(value); | ||
} | ||
} | ||
break; | ||
return mergeArray(left, right); | ||
case '[object Object]': | ||
for (name in right) { | ||
value = right[name]; | ||
if (right.hasOwnProperty(name) && (name !== '__proto__')) { | ||
valueType = type.call(value); | ||
if (typeof left[name] === 'undefined' || left[name] === null) { | ||
left[name] = value; | ||
} else if (valueType === '[object Array]' || valueType === '[object Object]') { | ||
left[name] = merge(left[name], value); | ||
} | ||
} | ||
} | ||
break; | ||
return mergeObject(left, right); | ||
default: | ||
throw new Error('Can not merge ' + leftType + ' objects.'); | ||
} | ||
}; | ||
mergeArray = function(left, right) { | ||
var add, i, leftValue, rightValue, value, _i, _j, _len, _len1; | ||
add = []; | ||
for (i = _i = 0, _len = right.length; _i < _len; i = ++_i) { | ||
rightValue = right[i]; | ||
leftValue = left[i]; | ||
if ((isObject(leftValue) && isObject(rightValue)) || (isArray(leftValue) && isArray(rightValue))) { | ||
left[i] = merge(leftValue, rightValue); | ||
} else if (isObject(rightValue)) { | ||
add.push(merge({}, rightValue)); | ||
} else if (isArray(rightValue)) { | ||
add.push(merge([], rightValue)); | ||
} else { | ||
add.push(rightValue); | ||
} | ||
} | ||
for (_j = 0, _len1 = add.length; _j < _len1; _j++) { | ||
value = add[_j]; | ||
left.push(value); | ||
} | ||
return left; | ||
}; | ||
mergeObject = function(left, right) { | ||
var key, mergeWith, value; | ||
for (key in right) { | ||
value = right[key]; | ||
if (right.hasOwnProperty(key) && (key !== '__proto__')) { | ||
if (isScalar(value)) { | ||
if (!left.hasOwnProperty(key)) { | ||
left[key] = value; | ||
} | ||
} else { | ||
if (left.hasOwnProperty(key)) { | ||
left[key] = merge(left[key], value); | ||
} else { | ||
mergeWith = isObject(value) ? {} : []; | ||
left[key] = merge(mergeWith, value); | ||
} | ||
} | ||
} | ||
} | ||
return left; | ||
}; | ||
module.exports = function() { | ||
@@ -392,2 +463,26 @@ var left, r, right, _i, _len; | ||
}, 'callsite/index.js': function(exports, module) { | ||
/** node globals **/ | ||
var require = function(name) {return window.require(name, 'callsite/index.js');}; | ||
require.resolve = function(name, parent) {if (parent === null) {parent = 'callsite/index.js';} return window.require.resolve(name, parent);}; | ||
require.define = function(bundle) {window.require.define(bundle);}; | ||
require.cache = window.require.cache; | ||
var __filename = 'callsite/index.js'; | ||
var __dirname = 'callsite'; | ||
var process = {cwd: function() {return '/';}, argv: ['node', 'callsite/index.js'], env: {}}; | ||
/** code **/ | ||
module.exports = function(){ | ||
var orig = Error.prepareStackTrace; | ||
Error.prepareStackTrace = function(_, stack){ return stack; }; | ||
var err = new Error; | ||
Error.captureStackTrace(err, arguments.callee); | ||
var stack = err.stack; | ||
Error.prepareStackTrace = orig; | ||
return stack; | ||
}; | ||
}, '/lib/EasyConfiguration.js': function(exports, module) { | ||
@@ -407,3 +502,3 @@ | ||
(function() { | ||
var EasyConfiguration, Extension, Helpers, merge; | ||
var EasyConfiguration, Extension, Helpers, callsite, isWindow, merge, path; | ||
@@ -416,12 +511,19 @@ merge = require('recursive-merge'); | ||
isWindow = typeof window !== 'undefined'; | ||
if (!isWindow) { | ||
callsite = require('callsite'); | ||
path = require('path'); | ||
} | ||
EasyConfiguration = (function() { | ||
EasyConfiguration.PARAMETER_REGEXP = /%([a-zA-Z.-_]+)%/g; | ||
EasyConfiguration.prototype.fileName = null; | ||
EasyConfiguration.prototype.files = null; | ||
EasyConfiguration.prototype.reserved = ['includes', 'parameters']; | ||
EasyConfiguration.prototype.reserved = null; | ||
EasyConfiguration.prototype.extensions = null; | ||
EasyConfiguration.prototype.files = null; | ||
EasyConfiguration.prototype.includes = null; | ||
@@ -434,10 +536,39 @@ EasyConfiguration.prototype._parameters = null; | ||
function EasyConfiguration(fileName) { | ||
this.fileName = fileName; | ||
function EasyConfiguration(_path, section) { | ||
if (_path == null) { | ||
_path = null; | ||
} | ||
if (section == null) { | ||
section = 'production'; | ||
} | ||
this.files = {}; | ||
this.reserved = ['includes', 'parameters', 'common']; | ||
this.extensions = {}; | ||
this.files = []; | ||
this.includes = {}; | ||
this._parameters = {}; | ||
this.parameters = {}; | ||
if (_path !== null) { | ||
this.addConfig(_path, section); | ||
} | ||
} | ||
EasyConfiguration.prototype.addConfig = function(_path, section) { | ||
var previous, stack; | ||
if (section == null) { | ||
section = 'production'; | ||
} | ||
if (_path[0] === '.' && isWindow) { | ||
throw new Error('Relative paths to config files are not supported in browser.'); | ||
} | ||
if (_path[0] === '.') { | ||
stack = callsite(); | ||
previous = stack[1].getFileName() === __filename ? stack[2] : stack[1]; | ||
_path = path.join(path.dirname(previous.getFileName()), _path); | ||
} | ||
if (Helpers.arrayIndexOf(this.reserved, section) === -1) { | ||
this.reserved.push(section); | ||
} | ||
return this.files[_path] = section; | ||
}; | ||
EasyConfiguration.prototype.addSection = function(name) { | ||
@@ -471,7 +602,12 @@ return this.addExtension(name, new Extension); | ||
EasyConfiguration.prototype.load = function() { | ||
var config, data; | ||
var config, data, section, _path, _ref; | ||
if (this.data === null) { | ||
config = this.loadConfig(this.fileName); | ||
config = {}; | ||
_ref = this.files; | ||
for (_path in _ref) { | ||
section = _ref[_path]; | ||
config = this.merge(this.loadConfig(_path, section), config); | ||
} | ||
data = this.parse(config); | ||
this.files = data.files; | ||
this.includes = data.files; | ||
this.parameters = data.parameters; | ||
@@ -483,6 +619,20 @@ this.data = data.sections; | ||
EasyConfiguration.prototype.loadConfig = function(file) { | ||
var data, include, path, _i, _len, _ref; | ||
EasyConfiguration.prototype.loadConfig = function(file, section) { | ||
var data, include, _data, _i, _len, _path, _ref; | ||
if (section == null) { | ||
section = 'production'; | ||
} | ||
data = require(file); | ||
data = Helpers.clone(data, false); | ||
if (typeof data[section] !== 'undefined' || typeof data.common !== 'undefined') { | ||
if (typeof data.common !== 'undefined') { | ||
_data = data.common; | ||
if (typeof data[section] !== 'undefined') { | ||
_data = this.merge(data[section], _data); | ||
} | ||
} else { | ||
_data = data[section]; | ||
} | ||
data = _data; | ||
} | ||
if (typeof data.includes !== 'undefined') { | ||
@@ -492,4 +642,4 @@ _ref = data.includes; | ||
include = _ref[_i]; | ||
path = Helpers.normalizePath(Helpers.dirName(file) + '/' + include); | ||
data = this.merge(data, this.loadConfig(path)); | ||
_path = Helpers.normalizePath(Helpers.dirName(file) + '/' + include); | ||
data = this.merge(data, this.loadConfig(_path)); | ||
} | ||
@@ -653,2 +803,9 @@ } | ||
}); | ||
describe('#constructor()', function() { | ||
return it('should throw an error for relative paths', function() { | ||
return expect(function() { | ||
return new EasyConfiguration('../../data/config.json'); | ||
}).to["throw"](Error, 'Relative paths to config files are not supported in browser.'); | ||
}); | ||
}); | ||
describe('#load()', function() { | ||
@@ -699,3 +856,3 @@ it('should return loaded configuration without parameters', function() { | ||
}); | ||
return describe('sections', function() { | ||
describe('sections', function() { | ||
it('should throw an error for unknown section', function() { | ||
@@ -761,2 +918,53 @@ configuration = new EasyConfiguration("" + dir + "/unknownSection"); | ||
}); | ||
describe('environments', function() { | ||
it('should load data from base environment section', function() { | ||
configuration = new EasyConfiguration("" + dir + "/environments"); | ||
configuration.load(); | ||
return expect(configuration.parameters).to.be.eql({ | ||
database: { | ||
host: '127.0.0.1', | ||
database: 'db', | ||
user: 'root', | ||
password: 'qwerty' | ||
} | ||
}); | ||
}); | ||
it('should load data from different environment section', function() { | ||
configuration = new EasyConfiguration("" + dir + "/environments", 'development'); | ||
configuration.load(); | ||
return expect(configuration.parameters).to.be.eql({ | ||
database: { | ||
host: '127.0.0.1', | ||
database: 'db', | ||
user: 'root', | ||
password: 'toor' | ||
} | ||
}); | ||
}); | ||
return it('should load data from local environment section without common section', function() { | ||
configuration = new EasyConfiguration("" + dir + "/environmentsNoCommon", 'local'); | ||
configuration.load(); | ||
return expect(configuration.parameters).to.be.eql({ | ||
database: { | ||
password: 'toor' | ||
} | ||
}); | ||
}); | ||
}); | ||
return describe('#addConfig()', function() { | ||
return it('should add more config files', function() { | ||
configuration = new EasyConfiguration; | ||
configuration.addConfig("" + dir + "/environmentsNoCommon", 'local'); | ||
configuration.addConfig("" + dir + "/environments", 'production'); | ||
configuration.load(); | ||
return expect(configuration.parameters).to.be.eql({ | ||
database: { | ||
password: 'qwerty', | ||
host: '127.0.0.1', | ||
database: 'db', | ||
user: 'root' | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -944,2 +1152,76 @@ | ||
}, '/test/data/environments.json': function(exports, module) { | ||
/** node globals **/ | ||
var require = function(name) {return window.require(name, '/test/data/environments.json');}; | ||
require.resolve = function(name, parent) {if (parent === null) {parent = '/test/data/environments.json';} return window.require.resolve(name, parent);}; | ||
require.define = function(bundle) {window.require.define(bundle);}; | ||
require.cache = window.require.cache; | ||
var __filename = '/test/data/environments.json'; | ||
var __dirname = '/test/data'; | ||
var process = {cwd: function() {return '/';}, argv: ['node', '/test/data/environments.json'], env: {}}; | ||
/** code **/ | ||
module.exports = (function() { | ||
return { | ||
"common": { | ||
"parameters": { | ||
"database": { | ||
"host": "127.0.0.1", | ||
"database": "db", | ||
"user": "root", | ||
"password": "" | ||
} | ||
} | ||
}, | ||
"production": { | ||
"parameters": { | ||
"database": { | ||
"password": "qwerty" | ||
} | ||
} | ||
}, | ||
"development": { | ||
"parameters": { | ||
"database": { | ||
"password": "toor" | ||
} | ||
} | ||
} | ||
} | ||
}).call(this); | ||
}, '/test/data/environmentsNoCommon.json': function(exports, module) { | ||
/** node globals **/ | ||
var require = function(name) {return window.require(name, '/test/data/environmentsNoCommon.json');}; | ||
require.resolve = function(name, parent) {if (parent === null) {parent = '/test/data/environmentsNoCommon.json';} return window.require.resolve(name, parent);}; | ||
require.define = function(bundle) {window.require.define(bundle);}; | ||
require.cache = window.require.cache; | ||
var __filename = '/test/data/environmentsNoCommon.json'; | ||
var __dirname = '/test/data'; | ||
var process = {cwd: function() {return '/';}, argv: ['node', '/test/data/environmentsNoCommon.json'], env: {}}; | ||
/** code **/ | ||
module.exports = (function() { | ||
return { | ||
"production": { | ||
"parameters": { | ||
"database": { | ||
"password": "qwerty" | ||
} | ||
} | ||
}, | ||
"local": { | ||
"parameters": { | ||
"database": { | ||
"password": "toor" | ||
} | ||
} | ||
} | ||
} | ||
}).call(this); | ||
}, '/test/data/other.json': function(exports, module) { | ||
@@ -1005,3 +1287,3 @@ | ||
"description": "Simply extensible loader for json config files", | ||
"version": "1.6.5", | ||
"version": "2.0.0", | ||
"author": { | ||
@@ -1029,10 +1311,17 @@ "name": "David Kudera", | ||
"dependencies": { | ||
"recursive-merge": "~1.1.3" | ||
"recursive-merge": "~1.2.0", | ||
"callsite": "~1.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "~1.8.0", | ||
"mocha": "~1.14.0" | ||
"mocha": "~1.16.2", | ||
"mocha-phantomjs": "~3.3.1", | ||
"phantomjs": "~1.9.2-6" | ||
}, | ||
"scripts": { | ||
"test": "cd ./test; echo \"Testing in node:\"; mocha ./node/index.js --reporter spec; cd ./browser; echo \"Testing in browser:\"; simq build; mocha-phantomjs ./index.html;" | ||
"test": "npm run test-node && npm run test-browser", | ||
"build-and-test": "npm run test-build && npm run test", | ||
"test-build": "cd ./test/browser; simq build;", | ||
"test-node": "mocha ./test/node/index.js --reporter spec", | ||
"test-browser": "mocha-phantomjs ./test/browser/index.html" | ||
} | ||
@@ -1059,3 +1348,3 @@ } | ||
"description": "Recursive merge tool for arrays and objects", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"author": { | ||
@@ -1087,5 +1376,5 @@ "name": "David Kudera", | ||
"scripts": { | ||
"test": "cd ./test; echo \"Testing in node:\"; mocha ./node/index.js --reporter spec; cd ./browser; echo \"Testing in browser:\"; mocha-phantomjs ./index.html;" | ||
"test": "cd ./test; echo \"Testing in node:\"; mocha ./node/index.js --reporter spec; cd ./browser; echo \"Testing in browser:\"; simq build; mocha-phantomjs ./index.html;" | ||
}, | ||
"readme": "# Recursive merge\n\nRecursive merge tool for arrays and objects.\n\n## Installation\n\n```\n$ npm install recursive-merge\n```\n\n## Usage\n\nWith this tool, you can recursively merge arrays or objects.\n\n```\nvar merge = require('merge');\n\nvar result = merge(\n\t[1, 1, 2, 3],\n\t[3, 4, 4, 5],\n\t[10, 9, 8, 1]\n);\t\t\t\t// result: [1, 1, 2, 3, 3, 4, 4, 5, 10, 9, 8, 1]\n```\n\nAs you can see, this library just merging objects and not removing duplicates.\n\nYou should also know, that this affects first object passed to merge function. Every other objects (arrays, objects) are\nadded to the first one. There is not any fast simple and universal solution for cloning objects (arrays yes).\n\nIn the same way, you can merge also objects.\n\nIf you will try to merge two different types of objects, exception will be thrown. Also if you will try to merge other\nobjects than arrays or objects, exception will be also thrown.\n\n## Tests\n\n```\n$ npm test\n```\n\n## Changelog\n\n* 1.1.2 - 1.1.3\n\t+ Bugs in IE8\n\n* 1.1.0 - 1.1.1\n\t+ Rewritten tests\n\t+ Using chai for assertion (not should)\n\t+ Added some tests\n\t+ Added tests for browser\n\n* 1.0.0\n\t+ Initial first version", | ||
"readme": "# Recursive merge\n\nRecursive merge tool for arrays and objects.\n\n## Installation\n\n```\n$ npm install recursive-merge\n```\n\n## Usage\n\nWith this tool, you can recursively merge arrays or objects.\n\n```\nvar merge = require('merge');\n\nvar result = merge(\n\t[1, 1, 2, 3],\n\t[3, 4, 4, 5],\n\t[10, 9, 8, 1]\n);\t\t\t\t// result: [1, 1, 2, 3, 3, 4, 4, 5, 10, 9, 8, 1]\n```\n\nAs you can see, this library just merging objects and not removing duplicates.\n\nYou should also know, that this affects first object passed to merge function. Every other objects (arrays, objects) are\nadded to the first one. There is not any fast simple and universal solution for cloning objects (arrays yes).\n\nIn the same way, you can merge also objects.\n\nIf you will try to merge two different types of objects, exception will be thrown. Also if you will try to merge other\nobjects than arrays or objects, exception will be also thrown.\n\n## Tests\n\n```\n$ npm test\n```\n\n## Changelog\n\n* 1.2.0\n\t+ Rewritten\n\n* 1.1.2 - 1.1.3\n\t+ Bugs in IE8\n\n* 1.1.0 - 1.1.1\n\t+ Rewritten tests\n\t+ Using chai for assertion (not should)\n\t+ Added some tests\n\t+ Added tests for browser\n\n* 1.0.0\n\t+ Initial first version", | ||
"readmeFilename": "README.md", | ||
@@ -1096,4 +1385,4 @@ "bugs": { | ||
"homepage": "https://github.com/sakren/node-recursive-merge", | ||
"_id": "recursive-merge@1.1.3", | ||
"_from": "recursive-merge@~1.1.3" | ||
"_id": "recursive-merge@1.2.0", | ||
"_from": "recursive-merge@~1.2.0" | ||
} | ||
@@ -1104,7 +1393,52 @@ | ||
}, 'callsite/package.json': function(exports, module) { | ||
/** node globals **/ | ||
var require = function(name) {return window.require(name, 'callsite/package.json');}; | ||
require.resolve = function(name, parent) {if (parent === null) {parent = 'callsite/package.json';} return window.require.resolve(name, parent);}; | ||
require.define = function(bundle) {window.require.define(bundle);}; | ||
require.cache = window.require.cache; | ||
var __filename = 'callsite/package.json'; | ||
var __dirname = 'callsite'; | ||
var process = {cwd: function() {return '/';}, argv: ['node', 'callsite/package.json'], env: {}}; | ||
/** code **/ | ||
module.exports = (function() { | ||
return { | ||
"name": "callsite", | ||
"version": "1.0.0", | ||
"description": "access to v8's CallSites", | ||
"keywords": [ | ||
"stack", | ||
"trace", | ||
"line" | ||
], | ||
"author": { | ||
"name": "TJ Holowaychuk", | ||
"email": "tj@vision-media.ca" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*" | ||
}, | ||
"main": "index", | ||
"engines": { | ||
"node": "*" | ||
}, | ||
"readme": "# callstack\n\n Access to v8's \"raw\" `CallSite`s.\n\n## Installation\n\n $ npm install callsite\n\n## Example\n\n```js\nvar stack = require('callsite');\n\nfoo();\n\nfunction foo() {\n bar();\n}\n\nfunction bar() {\n baz();\n}\n\nfunction baz() {\n console.log();\n stack().forEach(function(site){\n console.log(' \\033[36m%s\\033[90m in %s:%d\\033[0m'\n , site.getFunctionName() || 'anonymous'\n , site.getFileName()\n , site.getLineNumber());\n });\n console.log();\n}\n```\n\n## Why?\n\n Because you can do weird, stupid, clever, wacky things such as:\n\n - [better-assert](https://github.com/visionmedia/better-assert)\n\n## License\n\n MIT\n", | ||
"readmeFilename": "Readme.md", | ||
"_id": "callsite@1.0.0", | ||
"_from": "callsite@~1.0.0" | ||
} | ||
}).call(this); | ||
}, 'recursive-merge': function(exports, module) { module.exports = window.require('recursive-merge/lib/Merge.js'); } | ||
, 'callsite': function(exports, module) { module.exports = window.require('callsite/index.js'); } | ||
}); | ||
require.__setStats({"recursive-merge/lib/Merge.js":{"atime":1385388668000,"mtime":1385388458000,"ctime":1385388613000},"/lib/Extension.js":{"atime":1385388668000,"mtime":1385388653000,"ctime":1385388653000},"/lib/Helpers.js":{"atime":1385388668000,"mtime":1385388653000,"ctime":1385388653000},"/lib/EasyConfiguration.js":{"atime":1385388668000,"mtime":1385388653000,"ctime":1385388653000},"/test/browser/tests/EasyConfiguration.coffee":{"atime":1385385683000,"mtime":1385385677000,"ctime":1385385677000},"/test/browser/tests/Helpers.coffee":{"atime":1385388669000,"mtime":1385301962000,"ctime":1385301962000},"/test/data/advanced.json":{"atime":1385385635000,"mtime":1385285347000,"ctime":1385285347000},"/test/data/circular.json":{"atime":1385308755000,"mtime":1385308754000,"ctime":1385308754000},"/test/data/config.json":{"atime":1385385635000,"mtime":1385285347000,"ctime":1385285347000},"/test/data/other.json":{"atime":1385385635000,"mtime":1385285347000,"ctime":1385285347000},"/test/data/unknownSection.json":{"atime":1385385635000,"mtime":1385285347000,"ctime":1385285347000},"/package.json":{"atime":1385388668000,"mtime":1385388625000,"ctime":1385388625000},"recursive-merge/package.json":{"atime":1385388616000,"mtime":1385388613000,"ctime":1385388613000}}); | ||
require.version = '5.1.2'; | ||
require.__setStats({"recursive-merge/lib/Merge.js":{"atime":1389093656000,"mtime":1385409966000,"ctime":1389093405000},"/lib/Extension.js":{"atime":1389093423000,"mtime":1389093412000,"ctime":1389093412000},"/lib/Helpers.js":{"atime":1389093423000,"mtime":1389093412000,"ctime":1389093412000},"callsite/index.js":{"atime":1389098455000,"mtime":1359062982000,"ctime":1389098450000},"/lib/EasyConfiguration.js":{"atime":1389106579000,"mtime":1389106575000,"ctime":1389106575000},"/test/browser/tests/EasyConfiguration.coffee":{"atime":1389106271000,"mtime":1389106264000,"ctime":1389106264000},"/test/browser/tests/Helpers.coffee":{"atime":1389093388000,"mtime":1389093388000,"ctime":1389093388000},"/test/data/advanced.json":{"atime":1389093656000,"mtime":1385133048000,"ctime":1385133048000},"/test/data/circular.json":{"atime":1389093388000,"mtime":1389093388000,"ctime":1389093388000},"/test/data/config.json":{"atime":1389093656000,"mtime":1385131455000,"ctime":1385131455000},"/test/data/environments.json":{"atime":1389098316000,"mtime":1389098315000,"ctime":1389098315000},"/test/data/environmentsNoCommon.json":{"atime":1389097038000,"mtime":1389097036000,"ctime":1389097036000},"/test/data/other.json":{"atime":1389093656000,"mtime":1384939927000,"ctime":1384939927000},"/test/data/unknownSection.json":{"atime":1389093656000,"mtime":1385132042000,"ctime":1385132042000},"/package.json":{"atime":1389098449000,"mtime":1389098440000,"ctime":1389098440000},"recursive-merge/package.json":{"atime":1389093423000,"mtime":1389093405000,"ctime":1389093405000},"callsite/package.json":{"atime":1389098455000,"mtime":1389098450000,"ctime":1389098450000}}); | ||
require.version = '5.5.1'; | ||
@@ -1111,0 +1445,0 @@ /** run section **/ |
@@ -5,3 +5,3 @@ { | ||
"base": "../../", | ||
"application": "./test/browser/application.js", | ||
"target": "./test/browser/application.js", | ||
"modules": [ | ||
@@ -8,0 +8,0 @@ "./lib/*.js", |
@@ -1,7 +0,2 @@ | ||
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
require('./Helpers'); | ||
require('./EasyConfiguration'); | ||
}).call(this); | ||
require('./lib/Helpers'); | ||
require('./lib/EasyConfiguration'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
103839
30
1995
371
2
4
+ Addedcallsite@~1.0.0
+ Addedcallsite@1.0.0(transitive)