Skip to content

Commit

Permalink
fix CLI when overwriting input
Browse files Browse the repository at this point in the history
fixes #829
  • Loading branch information
alexlamsl committed Jul 22, 2017
1 parent b1a31b2 commit 471f9f2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ mainOptionKeys.forEach(function(key) {
program.option(key, option);
}
});
program.option('-o --output <file>', 'Specify output file (if not specified STDOUT will be used for output)', function(outputPath) {
return fs.createWriteStream(outputPath).on('error', function(e) {
fatal('Cannot write ' + outputPath + '\n' + e.message);
});
}, process.stdout);
program.option('-o --output <file>', 'Specify output file (if not specified STDOUT will be used for output)');

function readFile(file) {
try {
Expand Down Expand Up @@ -280,7 +276,9 @@ function writeMinify() {
catch (e) {
fatal('Minification error:\n' + e.message);
}
program.output.write(minified);
(program.output ? fs.createWriteStream(program.output).on('error', function(e) {
fatal('Cannot write ' + program.output + '\n' + e.message);
}) : process.stdout).write(minified);
}

var inputDir = program.inputDir;
Expand Down

0 comments on commit 471f9f2

Please sign in to comment.