1

The return from this function needs to be a stream. In non-watch mode that's easy; just return rebundle, browserify stream is converted, blah blah, ok. In watch mode, however, rebundle is run on each update and creates a new stream every time. I need a way to consolidate all of those streams as they're created into a single endless stream that I can return and that can actually be consumed down the line. Playing with combined-stream, it seems like once data is read the stream ceases to be writable, so that's a no go. Any help would be appreciated!

var bundleify = function(watch) {

    var bundler = (watch?watchify:browserify)('main.js');

    var rebundle = function () {
        return bundler.bundle()
            .on('error', console.log)
            .pipe(source('main.js'))
            .pipe(rename('app.js'))
            .pipe(jsTasks()); // lazypipe with other tasks
    };

    // Regular browserify, just return the stream.
    if (!watch) {
        return rebundle();
    }

    // Watchify, rebundle on update.
    bundler.on('update', function() {
        rebundle();
    });

    // return ????
}
Alex Guerra
  • 2,556
  • 3
  • 18
  • 24
  • I'm confused as to what you're trying to accomplish. Are you trying to do something like concatenate a bunch of streams such that they're kind of treated like strings (where one stream is completely first, then the next stream, then the next)? Or are you trying to interleave their data? – B T Sep 08 '14 at 07:26

1 Answers1

0

Here's the solution I came up with. It's pretty ghetto (admittedly I don't have a great understanding of streams) but it looks like it's working. Still interested in finding a nicer way.

var outstream = through2.obj();
var interceptor = function(){
    return through2.obj(function(obj, enc, cb) {
        outstream.push(obj);
        cb()
    });
}

bundler.on('update', function() {
    rebundle().pipe(interceptor());
});

rebundle().pipe(interceptor());
return outstream;
Alex Guerra
  • 2,556
  • 3
  • 18
  • 24