Permalink
Browse files

CLI: Fixed handling of stdout if callback is specified, see #724

  • Loading branch information...
dcodeIO committed Mar 24, 2017
1 parent 6423a41 commit 16adff0c7b67c69a2133b6aac375365c5f2bdbf7
Showing with 15 additions and 12 deletions.
  1. +8 −4 cli/pbjs.js
  2. +7 −8 cli/pbts.js
@@ -275,15 +275,19 @@ exports.main = function main(args, callback) {
return callback(err);
throw err;
}
if (output !== "") {
try {
if (argv.out)
fs.writeFileSync(argv.out, output, { encoding: "utf8" });
else if (!callback)
process.stdout.write(output, "utf8");
return callback
? callback(null, output)
: undefined;
} catch (err) {
if (callback)
return callback(err);
throw err;
}
return callback
? callback(null, output)
: undefined;
});
}
@@ -140,16 +140,15 @@ exports.main = function(args, callback) {
try {
if (argv.out)
fs.writeFileSync(argv.out, output);
else
fs.writeFileSync(argv.out, output, { encoding: "utf8" });
else if (!callback)
process.stdout.write(output, "utf8");
if (callback)
callback(null); // eslint-disable-line callback-return
return callback
? callback(null, output)
: undefined;
} catch (err) {
if (callback) {
callback(err);
return;
}
if (callback)
return callback(err);
throw err;
}
});

0 comments on commit 16adff0

Please sign in to comment.