Skip to content

Commit

Permalink
Merge pull request #245 from substack/cli-write-on-ready
Browse files Browse the repository at this point in the history
Wait until there is some data before creating the output stream in the CLI
  • Loading branch information
zertosh committed Oct 25, 2015
2 parents 2c95754 + 4dfacff commit b23c9c9
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var path = require('path');
var outpipe = require('outpipe');
var through = require('through2');

var fromArgs = require('./args.js');
var w = fromArgs(process.argv.slice(2));
Expand Down Expand Up @@ -33,24 +34,31 @@ bundle();

function bundle () {
var didError = false;
var outStream = outpipe(outfile);

var writer = through();
var wb = w.bundle();

w.pipeline.get('pack').once('readable', function() {
wb.pipe(writer);
});

wb.on('error', function (err) {
console.error(String(err));
didError = true;
outStream.end('console.error('+JSON.stringify(String(err))+');');
});
wb.pipe(outStream);

outStream.on('error', function (err) {
console.error(err);
writer.end('console.error(' + JSON.stringify(String(err)) + ');');
});
outStream.on('exit', function () {
if (verbose && !didError) {
console.error(bytes + ' bytes written to ' + outfile
+ ' (' + (time / 1000).toFixed(2) + ' seconds)'
);
}

writer.once('readable', function() {
var outStream = outpipe(outfile);
outStream.on('error', function (err) {
console.error(err);
});
outStream.on('exit', function () {
if (verbose && !didError) {
console.error(bytes + ' bytes written to ' + outfile
+ ' (' + (time / 1000).toFixed(2) + ' seconds)'
);
}
});
writer.pipe(outStream);
});
}

0 comments on commit b23c9c9

Please sign in to comment.