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 2.1.0 to 3.0.0

test/hello.json

74

cli.js

@@ -6,52 +6,46 @@ /**

var conf = require('./conf.js'),
const conf = require('./conf.js'),
fs = require('fs-extra'),
exit = require('exit'),
configurationPath,
isRead;
argParser = new require('argparse').ArgumentParser({
'addHelp': true,
'epilog': 'Default is to display the configuration at stdout.'
});
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.');
exit(1);
}
argParser.addArgument(
'-u', {
'metavar': '<upload file>',
'help': 'Update configuration. Configuration is read from upload file.'
});
argParser.addArgument(
'configPath',
{
'help': 'Configuration path'
});
isRead = process.argv.length === 3;
configurationPath = isRead ? process.argv[2] : process.argv[3];
const args = argParser.parseArgs(),
uploadPath = args['u'];
conf.initOnlyFiles(configurationPath);
conf.initOnlyFiles(args['configPath']);
if (isRead) {
var value = conf.get();
process.stdout.write(JSON.stringify(value, null, 2));
exit(0);
} else {
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function () {
var chunk = process.stdin.read();
var actualConfig;
if (chunk !== null) {
try {
actualConfig = JSON.parse(chunk);
} catch (e) {
if (e instanceof SyntaxError) {
process.stderr.write('Invalid JSON: ');
process.stderr.write(e.message);
exit(1);
} else {
process.stderr.write(e);
exit(2);
}
if (uploadPath) {
fs.readJsonFile(uploadPath, function (err, actualConfig) {
if (err) {
if (err instanceof SyntaxError) {
process.stderr.write(`Invalid JSON: ${err.message}`);
exit(1);
} else {
process.stderr.write(err.message);
exit(2);
}
}
if (actualConfig !== null) {
conf.save(actualConfig, function () {
exit();
})
});
}
});
} else {
process.stdout.write(JSON.stringify(conf.get(), null, 2));
exit(0);
}
{
"name": "e2e-conf",
"version": "2.1.0",
"version": "3.0.0",
"main": "conf.js",

@@ -5,0 +5,0 @@ "dependencies": {

@@ -58,2 +58,9 @@ # e2e-conf - Easy Configuration for E2E Bridge Node.js Services

## Changelog
### 3.0.0 (2018-07-11)
- The command line interface to update a configuration reads now from a file instead of stdin,
because stdin has a size limitation.
## License

@@ -63,3 +70,3 @@

Copyright (c) 2014-2015 E2E Technologies
Copyright (c) 2014-2018 Scheer E2E AG

@@ -66,0 +73,0 @@ Permission is hereby granted, free of charge, to any person obtaining

@@ -37,3 +37,3 @@ /**

subprocess.on('close', function (code) {
test.equals(code, 1);
test.equals(code, 2);
test.done();

@@ -40,0 +40,0 @@ });

@@ -145,4 +145,3 @@ /**

conf.save(function (err) {
test.ok((err.message === 'Unexpected token /') // node > 4.0
|| (err.type === "unexpected_token")); // node = 0.10
test.ok(err.message.search(/unexpected[ _]token/i) !== -1);

@@ -149,0 +148,0 @@ test.done();

@@ -37,3 +37,3 @@ /**

update.on('close', function (code) {
test.equals(1, code);
test.equals(code, 2);
test.done();

@@ -51,3 +51,3 @@ });

update.on('close', function (code) {
test.equals(1, code);
test.equals(code, 2);
test.done();

@@ -66,3 +66,3 @@ });

path.resolve(__dirname, '../cli.js'),
"-u",
'-u', 'test/hello.json',
this.basePath

@@ -72,3 +72,3 @@ ]);

update.on('close', function (code) {
test.equals(0, code);
test.equals(code, 0);

@@ -83,4 +83,2 @@ conf.init(self.basePath);

});
update.stdin.end('{"hello":"changed"}');
},

@@ -98,3 +96,3 @@

path.resolve(__dirname, '../cli.js'),
"-u",
'-u', 'test/invalid.json',
this.basePath

@@ -105,3 +103,3 @@ ]);

test.equals(1, code);
test.equals('Invalid JSON: Unexpected token o', output);
test.notEqual(output.search(/Unexpected token o in JSON at position 1/), -1);

@@ -118,4 +116,2 @@ conf.init(self.basePath);

});
update.stdin.end('no JSON');
}

@@ -155,3 +151,3 @@

path.resolve(__dirname, '../cli.js'),
"-u",
'-u', 'test/updateChanged.json',
this.basePath

@@ -161,3 +157,3 @@ ]);

update.on('close', function (code) {
test.equals(0, code);
test.equals(code, 0);

@@ -173,7 +169,2 @@ conf.init(self.basePath);

});
update.stdin.end(
'{ "connection": {"user": "changed", "passwd": "changed"}, ' +
'"performance": {"truncateArrays": 100}, ' +
'"NODE_ENV": "production"}');
},

@@ -190,3 +181,3 @@

path.resolve(__dirname, '../cli.js'),
"-u",
'-u', 'test/updateNew.json',
this.basePath

@@ -208,8 +199,2 @@ ]);

});
update.stdin.end(
'{ "somethingnew": 1, ' +
'"connection": { "user": "local", "passwd": "local" }, ' +
'"performance": {"truncateArrays": 100}, ' +
'"NODE_ENV": "production"}');
},

@@ -227,3 +212,3 @@

path.resolve(__dirname, '../cli.js'),
"-u",
'-u', 'test/invalid.json',
this.basePath

@@ -233,4 +218,4 @@ ]);

update.on('close', function (code) {
test.equals(1, code);
test.equals('Invalid JSON: Unexpected token o', output);
test.equals(code, 1);
test.notEqual(output.search(/Unexpected token o in JSON at position 1/), -1);

@@ -250,4 +235,2 @@ conf.init(self.basePath);

});
update.stdin.end('no JSON');
}

@@ -254,0 +237,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