Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

e2e-conf

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

e2e-conf - npm Package Compare versions

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 @@ }

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc