2

This is a setup for running the libsass "sassc" binary directly (shown below) using Gulp.js, for which I am currently using the plugin gulp-run. This was after much tinkering, as I'm not a node or gulp expert at all, and it still has a few problems.

The sassc binary normally takes input and output file arguments (e.g ../bin/sassc file.scss > file.css), but it can also be run with the -s argument to accept stdin, and so can be passed a file from gulp.src() as it is here. It seems under these conditions, to successfully pass on its result as stdout, if I understand correctly. A file called "test.css" is written in the same directory. Note that without the 'verbosity' setting on the gulp-run command as it is, the resulting CSS will be output to the terminal. Here that is suppressed and the result is passed down the chain; however this still does not seem to create a proper output stream because I've had no success adding processes such as gulp-autoprefixer inline after this. Furthermore, I need a way to capture stderr (if there is one) to a log file (right now if there's an error it outputs in the console).

Any guidance appreciated. I may also be using the wrong plugin for it with gulp-run. There are also gulp-exec and gulp-shell, and possibly others but I don't really know what difference to look for.

var gulp         = require('gulp');
var run          = require('gulp-run');
var rename       = require("gulp-rename");

gulp.task('sassc', function () {
  gulp.src('test.scss')
    .pipe(run('../bin/sassc -s', {verbosity: 1}))
    .on('error', function (err) { this.end(); })
    .pipe(rename(function (path) { path.extname = ".css"; }))
    .pipe(gulp.dest('.'))
});

gulp.task('watch', function () {
    gulp.watch('test.scss', ['sassc']);
});

gulp.task('default', ['watch']);
lunelson
  • 561
  • 6
  • 11
  • Why `gulp-sass` does not satisfy you? – baldrs Nov 28 '14 at 13:27
  • Part of the point of this setup is to be able to test libsass directly, so I'm working from a clone of the libsass repo itself, from which I can pull changes and build the sassc binary, to be sure I always have the latest version – lunelson Dec 01 '14 at 11:26
  • You just then can examine the sources of `gulp-sass` to see how they do it. – baldrs Dec 02 '14 at 14:40
  • yeah, well the gulp-sass source is a bit beyond me. I was hoping someone who knew streams could just help me with streaming `stdout` and `stderr` here – lunelson Dec 08 '14 at 11:56

1 Answers1

0

maybe gulp-log-capture (https://www.npmjs.com/package/gulp-log-capture) will be of some help in capturing stdout

rravuri
  • 411
  • 3
  • 4