1

I'm using gulp to convert SCSS into CSS code with the gulp-sass plugin. This is all working fine, but I also want to use gulp to receive input (SCSS code) from a Unix pipe (i.e. read process.stdin) and consume this and stream the output to process.stdout.

From reading around process.stdin is a ReadableStream and vinyl seems like it could wrap stdin and then be used onwards in a gulp task, e.g.

gulp.task('stdin-sass', function () {
    process.stdin.setEncoding('utf8');
    var file = new File({contents: process.stdin, path: './test.scss'});
    file.pipe(convert_sass_to_css())
        .pipe(gulp.dest('.'));
});

However, when I do this I get an error:

TypeError: file.isNull is not a function

This makes me think that stdin is somehow special, but the official documentation for node.js states that it is a true ReadableStream.

Euan
  • 399
  • 1
  • 12

1 Answers1

1

So I got this to work by processing process.stdin and writing to process.stdout:

var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var through = require('through2');

gulp.task('stdio-sass', function () {
    process.stdin.setEncoding('utf8');
    process.stdin.pipe(source('input.scss'))
        .pipe(buffer())
        .pipe(convert_sass_to_css())
        .pipe(stdout_stream());
});


var stdout_stream = function () {
    process.stdout.setEncoding('utf8');
    return through.obj(function (file, enc, complete) {
        process.stdout.write(file.contents.toString());

        this.push(file);
        complete();
    });
};
Euan
  • 399
  • 1
  • 12