m19c / gulp-run

Pipe to shell commands in gulp
ISC License
151 stars 25 forks source link

how to do something with stderr? #20

Open lunelson opened 9 years ago

lunelson commented 9 years ago

I'm currently using this plugin to run the binary of libsass (sassc) for testing purposes. What I would really like is a way to capture the stderr to a file. Currently with {verbosity: 1} the stderr is output in the terminal but what I really need for these purposes is to capture it to a file. Is there a way? My setup is as follows. You'll see that I use gulp-plumber to capture 'error' events but the output I'm interested in (they are compiler warnings in fact, not errors) is output to stderr without triggering an actual 'error' event, so this only works for fatal errors at the moment

gulp.task('sassc', function () {
  gulp.src('test.scss', { buffer: false })
    .pipe(plumber(function(err) {
        var errorTxt = err.message +'\n\n'+ err.source;
        gutil.beep();
        gutil.log(gutil.colors.red(errorTxt));
        fs.writeFile('test.log', errorTxt);
    }))
    .pipe(rename(function (path) { path.extname = ".css"; }))
    .pipe(run('/applications/libsass/sassc/bin/sassc -s', {verbosity: 1}))
    .pipe(buffer())
    .pipe(autoprefixer({
        browsers: ['last 5 versions'],
        cascade: false
    }))
    .pipe(gulp.dest('.'))
});
cbarrick commented 9 years ago

Currently the stderr of the process is not exposed, but that could easily be changed. Do you have any suggestions for an interface?

Perhaps there could be an option called stderr that takes a stream/buffer/vinyl that receives the stderr of the command. Something like

var buffer = new Buffer();
run('echo hello world', {stderr: buffer}).exec();
lunelson commented 9 years ago

I think I don't know enough about this too suggest something sensible. Maybe I made a false assumption but I was imagining that gulp must have some kind of convention such that the complete stdio could be passed along the stream and be available to subsequent plugins—is that not the case?