Skip to content

Commit

Permalink
CLI: Fixed handling of stdout if callback is specified, see #724
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Mar 24, 2017
1 parent 6423a41 commit 16adff0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
12 changes: 8 additions & 4 deletions cli/pbjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}

Expand Down
15 changes: 7 additions & 8 deletions cli/pbts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand Down

0 comments on commit 16adff0

Please sign in to comment.