Comparing version 1.0.0 to 1.0.2
31
cli.js
@@ -7,13 +7,15 @@ /** | ||
var conf = require('./conf.js'), | ||
exit = require('exit'), | ||
configurationPath, | ||
isRead; | ||
if( process.argv.length < 3 | ||
if (process.argv.length < 3 | ||
|| process.argv.length > 4 | ||
|| process.argv.length === 4 && process.argv[2] !== '-u' | ||
|| process.argv.length === 3 && process.argv[2] === '-u') { | ||
console.log( 'Usage: node ' + process.argv[1] + ' [-u] <configuration path>\n\n' + | ||
'-u: Update configuration. Configuration is read from stdin.\n' + | ||
'Default is to display the configuration at stdout.'); | ||
process.exit(1); | ||
console.log( | ||
'Usage: node ' + process.argv[1] + ' [-u] <configuration path>\n\n' + | ||
'-u: Update configuration. Configuration is read from stdin.\n' + | ||
'Default is to display the configuration at stdout.'); | ||
exit(1); | ||
} | ||
@@ -26,26 +28,27 @@ | ||
if( isRead) { | ||
if (isRead) { | ||
var value = conf.get(); | ||
process.stdout.write(JSON.stringify(value, null, 2)); | ||
process.exit(); | ||
exit(0); | ||
} else { | ||
process.stdin.setEncoding('utf8'); | ||
process.stdin.on('readable', function() { | ||
process.stdin.on('readable', function () { | ||
var chunk = process.stdin.read(); | ||
var actualConfig; | ||
if (chunk !== null) { | ||
try { | ||
conf.setObject( JSON.parse(chunk)); | ||
actualConfig = JSON.parse(chunk); | ||
} catch (e) { | ||
if(e instanceof SyntaxError) { | ||
if (e instanceof SyntaxError) { | ||
process.stderr.write('Invalid JSON: '); | ||
process.stderr.write(e.message); | ||
process.exit(1); | ||
exit(1); | ||
} else { | ||
process.stderr.write(e); | ||
process.exit(2); | ||
exit(2); | ||
} | ||
} | ||
conf.save(function () { | ||
process.exit(); | ||
conf.save(actualConfig, function () { | ||
exit(); | ||
}) | ||
@@ -52,0 +55,0 @@ } |
19
conf.js
@@ -40,4 +40,4 @@ /** | ||
nconf.file('local', { file: this.localFileName }) | ||
.file('default', { file: this.defaultFileName }); | ||
nconf.file('local', {file: this.localFileName}) | ||
.file('default', {file: this.defaultFileName}); | ||
} | ||
@@ -96,3 +96,3 @@ | ||
* | ||
* @param {String} key If you want to get a property of an object use 'object_name:property' | ||
* @param {String?} key If you want to get a property of an object use 'object_name:property' | ||
* otherwise use simple 'root_property'. | ||
@@ -140,5 +140,6 @@ * @returns {*} Value of name or undefined. Can be a simple type, object or array. | ||
* Save changes to local configuration file (difference only). | ||
* @param [actualConf] Current configuration which should be saved. | ||
* @param callback | ||
*/ | ||
exports.save = function save(callback) { | ||
exports.save = function save(actualConf, callback) { | ||
var self = this; | ||
@@ -149,5 +150,10 @@ if (!initialized) { | ||
if (typeof actualConf === 'function') { | ||
callback = actualConf; | ||
actualConf = nconf.stores.local.store; | ||
} | ||
async.waterfall([ | ||
function (callback) { | ||
fs.ensureDir(self.localDirectory, function(err, dirName) { | ||
fs.ensureDir(self.localDirectory, function (err, dirName) { | ||
callback(err, dirName); | ||
@@ -157,3 +163,3 @@ }); | ||
function (dirName, callback) { | ||
fs.readJsonFile(self.defaultFileName, function(err, defaultConf) { | ||
fs.readJsonFile(self.defaultFileName, function (err, defaultConf) { | ||
callback(err, defaultConf); | ||
@@ -163,3 +169,2 @@ }); | ||
function (defaultConf, callback) { | ||
var actualConf = nconf.stores.local.store; | ||
var diff = difference(defaultConf, actualConf); | ||
@@ -166,0 +171,0 @@ |
{ | ||
"name": "e2e-conf", | ||
"version": "1.0.0", | ||
"version": "1.0.2", | ||
"main": "conf.js", | ||
"dependencies": { | ||
"nconf": "^0.6.9", | ||
"fs-extra": "^0.9.1", | ||
"async": "^0.9.0" | ||
"nconf": "^0.7.1", | ||
"fs-extra": "^0.16.3", | ||
"async": "^0.9.0", | ||
"exit": "^0.1.2" | ||
}, | ||
@@ -28,7 +29,5 @@ "devDependencies": { | ||
], | ||
"scripts": [ | ||
{ | ||
"test": "node ./node_modules/nodeunit/bin/nodeunit test/conf.test.js" | ||
} | ||
], | ||
"scripts": { | ||
"test": "node ./node_modules/nodeunit/bin/nodeunit" | ||
}, | ||
"license": "MIT", | ||
@@ -35,0 +34,0 @@ "description": "E2E Bridge can manage service configurations for different deployments", |
@@ -37,3 +37,3 @@ # e2e-conf - Easy Configuration for E2E Bridge Node.js Services | ||
If you want to change the configuration from the program you can use **set()** to change it and **save()** to store it. | ||
The changes are save to **config/local/config.json** but only as difference to the default values from the file | ||
The changes are saved to **config/local/config.json** but only as difference to the default values from the file | ||
**config/default/config.json**. | ||
@@ -62,3 +62,3 @@ | ||
Copyright (c) 2014 E2E Technologies | ||
Copyright (c) 2014-2015 E2E Technologies | ||
@@ -65,0 +65,0 @@ Permission is hereby granted, free of charge, to any person obtaining |
{ | ||
"connection": { | ||
"sysid": "", | ||
"sysnr": "", | ||
"user": "", | ||
"passwd": "", | ||
"client": "", | ||
"ashost": "", | ||
"lang": "" | ||
}, | ||
"pool": { | ||
"maxCount": 5, | ||
"maxIdle": 300 | ||
}, | ||
"performance": { | ||
"truncateArrays": 100 | ||
}, | ||
"debug": false, | ||
"pageSize": 25, | ||
"PORT": 3000, | ||
"NODE_ENV": "production" | ||
"connection": { | ||
"user": "", | ||
"passwd": "" | ||
}, | ||
"performance": { | ||
"truncateArrays": 100 | ||
}, | ||
"NODE_ENV": "production" | ||
} |
{ | ||
"connection": { | ||
"user": "ee", | ||
"passwd": "ee", | ||
"client": "ee", | ||
"ashost": "eee" | ||
} | ||
"user": "local", | ||
"passwd": "local" | ||
}, | ||
"local": 1 | ||
} |
{ | ||
"hello": "world", | ||
"sub": { | ||
"a": "default", | ||
"b": "default" | ||
}, | ||
"many": [ | ||
1, 2, 3 | ||
] | ||
"hello": "world", | ||
"sub": { | ||
"a": "default", | ||
"b": "default" | ||
}, | ||
"many": [ | ||
1, | ||
2, | ||
3 | ||
] | ||
} |
@@ -57,3 +57,9 @@ /** | ||
test.deepEqual(conf._difference({o: {a: 1, b: 1, c: []}}, {o: {a: 2, b: 1, c: [2]}}), {o: {a: 2, c: [2]}}); | ||
test.deepEqual(conf._difference({ | ||
o: {a: 1, b: 1, c: []} | ||
}, { | ||
o: {a: 2, b: 1, c: [2]} | ||
}), { | ||
o: {a: 2, c: [2]} | ||
}); | ||
test.done(); | ||
@@ -65,3 +71,9 @@ }, | ||
test.deepEqual(conf._difference({o: {a: 1, b: 1, c: []}}, {o: {a: 2, b: 1, c: [2], d: 7}}), {o: {a: 2, c: [2], d: 7}}); | ||
test.deepEqual(conf._difference({ | ||
o: {a: 1, b: 1, c: []} | ||
}, { | ||
o: {a: 2, b: 1, c: [2], d: 7} | ||
}), { | ||
o: {a: 2, c: [2], d: 7} | ||
}); | ||
test.done(); | ||
@@ -68,0 +80,0 @@ }, |
{ | ||
"hello": "world", | ||
"sub": { | ||
"a": "default", | ||
"b": "default" | ||
}, | ||
"many": [ | ||
1, 2, 3 | ||
] | ||
"hello": "world", | ||
"sub": { | ||
"a": "default", | ||
"b": "default" | ||
}, | ||
"many": [ | ||
1, | ||
2, | ||
3 | ||
] | ||
} |
{ | ||
"hello": "changed", | ||
"sub": { | ||
"a": "changed", | ||
"c": "changed" | ||
}, | ||
"many": [ | ||
4, 3 | ||
] | ||
"hello": "changed", | ||
"sub": { | ||
"a": "changed", | ||
"c": "changed" | ||
}, | ||
"many": [ | ||
4, | ||
3 | ||
] | ||
} |
@@ -34,3 +34,3 @@ /** | ||
subprocess = child_process.spawn( process.execPath, [ path.resolve( __dirname, '../cli.js')]); | ||
subprocess = child_process.spawn(process.execPath, [path.resolve(__dirname, '../cli.js')]); | ||
@@ -50,4 +50,4 @@ subprocess.on('close', function (code) { | ||
subprocess = child_process.spawn( process.execPath, [ | ||
path.resolve( __dirname, '../cli.js'), | ||
subprocess = child_process.spawn(process.execPath, [ | ||
path.resolve(__dirname, '../cli.js'), | ||
this.basePath | ||
@@ -58,4 +58,4 @@ ]); | ||
subprocess.stdout.on('data', function(chunk) { | ||
test.equals( "{\n \"hello\": \"world\",\n \"sub\": {\n \"a\": \"default\",\n \"b\": \"default\"\n },\n \"many\": [\n 1,\n 2,\n 3\n ]\n}", chunk); | ||
subprocess.stdout.on('data', function (chunk) { | ||
test.equals("{\n \"hello\": \"world\",\n \"sub\": {\n \"a\": \"default\",\n \"b\": \"default\"\n },\n \"many\": [\n 1,\n 2,\n 3\n ]\n}", chunk); | ||
}); | ||
@@ -62,0 +62,0 @@ |
@@ -10,3 +10,3 @@ /** | ||
exports.testConf = { | ||
exports.testNoLocalConf = { | ||
setUp: function (callback) { | ||
@@ -35,3 +35,3 @@ var defaultPath; | ||
update = child_process.spawn(process.execPath, [ path.resolve(__dirname, '../cli.js'), "-u"]); | ||
update = child_process.spawn(process.execPath, [path.resolve(__dirname, '../cli.js'), "-u"]); | ||
@@ -49,3 +49,3 @@ update.on('close', function (code) { | ||
update = child_process.spawn(process.execPath, [ path.resolve(__dirname, '../cli.js'), "-wrong", "dir/"]); | ||
update = child_process.spawn(process.execPath, [path.resolve(__dirname, '../cli.js'), "-wrong", "dir/"]); | ||
@@ -111,3 +111,3 @@ update.on('close', function (code) { | ||
update.stderr.on('data', function(chunk){ | ||
update.stderr.on('data', function (chunk) { | ||
output += chunk.toString(); | ||
@@ -120,7 +120,5 @@ }); | ||
}; | ||
exports.testConf2 = { | ||
exports.testLocalConf = { | ||
setUp: function (callback) { | ||
@@ -145,3 +143,3 @@ var defaultPath; | ||
testUpdate: function (test) { | ||
testUpdateChangedProperty: function (test) { | ||
var conf = this.conf, | ||
@@ -154,3 +152,4 @@ self = this, | ||
update = child_process.spawn(process.execPath, [ | ||
path.resolve(__dirname, '../update_conf.js'), | ||
path.resolve(__dirname, '../cli.js'), | ||
"-u", | ||
this.basePath | ||
@@ -165,4 +164,3 @@ ]); | ||
{ | ||
connection: { user: 'ttt', passwd: 'ee', client: 'ee', ashost: 'eee' }, | ||
pool: {}, | ||
connection: {user: 'changed', passwd: 'changed'}, | ||
performance: {} | ||
@@ -175,5 +173,77 @@ } | ||
update.stdin.end('{\n "connection": {\n "sysid": "",\n "sysnr": "",\n "user": "ttt",\n "passwd": "ee",\n "client": "ee",\n "ashost": "eee",\n "lang": ""\n },\n "pool": {\n "maxCount": 5,\n "maxIdle": 300\n },\n "performance": {\n "truncateArrays": 100\n },\n "debug": false,\n "pageSize": 25,\n "PORT": 3000,\n "NODE_ENV": "production"\n}\n'); | ||
update.stdin.end( | ||
'{ "connection": {"user": "changed", "passwd": "changed"}, ' + | ||
'"performance": {"truncateArrays": 100}, ' + | ||
'"NODE_ENV": "production"}'); | ||
}, | ||
testUpdateNewProperty: function (test) { | ||
var conf = this.conf, | ||
self = this, | ||
update; | ||
test.expect(2); | ||
update = child_process.spawn(process.execPath, [ | ||
path.resolve(__dirname, '../cli.js'), | ||
"-u", | ||
this.basePath | ||
]); | ||
update.on('close', function (code) { | ||
test.equals(0, code); | ||
conf.init(self.basePath); | ||
test.deepEqual(fs.readJsonFileSync(conf.localFile()), | ||
{ | ||
connection: {user: 'local', passwd: 'local'}, | ||
somethingnew: 1, | ||
performance: {} | ||
} | ||
); | ||
test.done(); | ||
}); | ||
update.stdin.end( | ||
'{ "somethingnew": 1, ' + | ||
'"connection": { "user": "local", "passwd": "local" }, ' + | ||
'"performance": {"truncateArrays": 100}, ' + | ||
'"NODE_ENV": "production"}'); | ||
}, | ||
testUpdateInvalidJSON: function (test) { | ||
var conf = this.conf, | ||
self = this, | ||
update, | ||
output = ''; | ||
test.expect(3); | ||
update = child_process.spawn(process.execPath, [ | ||
path.resolve(__dirname, '../cli.js'), | ||
"-u", | ||
this.basePath | ||
]); | ||
update.on('close', function (code) { | ||
test.equals(1, code); | ||
test.equals('Invalid JSON: Unexpected token o', output); | ||
conf.init(self.basePath); | ||
test.deepEqual(fs.readJsonFileSync(conf.localFile()), | ||
{ | ||
connection: {user: 'local', passwd: 'local'}, | ||
local: 1 | ||
} | ||
); | ||
test.done(); | ||
}); | ||
update.stderr.on('data', function (chunk) { | ||
output += chunk.toString(); | ||
}); | ||
update.stdin.end('no JSON'); | ||
} | ||
}; | ||
@@ -180,0 +250,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
29575
807
4
16
3
+ Addedexit@^0.1.2
+ Addedalign-text@0.1.4(transitive)
+ Addedcamelcase@1.2.1(transitive)
+ Addedcenter-align@0.1.3(transitive)
+ Addedcliui@2.1.0(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedexit@0.1.2(transitive)
+ Addedfs-extra@0.16.5(transitive)
+ Addedgraceful-fs@3.0.124.2.11(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedjsonfile@2.4.0(transitive)
+ Addedkind-of@3.2.2(transitive)
+ Addedlazy-cache@1.0.4(transitive)
+ Addedlongest@1.0.1(transitive)
+ Addednatives@1.1.6(transitive)
+ Addednconf@0.7.2(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedright-align@0.1.3(transitive)
+ Addedwindow-size@0.1.4(transitive)
+ Addedwordwrap@0.0.2(transitive)
+ Addedyargs@3.15.0(transitive)
- Removedasync@0.2.9(transitive)
- Removedfs-extra@0.9.1(transitive)
- Removedjsonfile@1.1.1(transitive)
- Removedminimist@0.0.101.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednconf@0.6.9(transitive)
- Removedncp@0.5.1(transitive)
- Removedoptimist@0.6.0(transitive)
- Removedwordwrap@0.0.3(transitive)
Updatedfs-extra@^0.16.3
Updatednconf@^0.7.1