node.js - How can I pipe the output from gulp-w3c-css to the console -


when follow examples gulp-w3c-css unable results print in console instead of in output directory.

compare how using csslint , w3c-css below. i'd function identical.

var gulp = require('gulp'),     csslint = require('gulp-csslint'),     cssvalidate = require('gulp-w3c-css');   gulp.task('csslint', () =>     gulp.src('testcss/laxhjalpen.css')     .pipe(csslint('.csslintrc'))     .pipe(csslint.reporter()) );  // not work gulp.task('cssvalid', () =>     gulp.src('testcss/*css')     .pipe(cssvalidate())     // next line works not want     .pipe(gulp.dest('reports'))     // suppose need construct work can't     .pipe(gutil.buffer(function(err, files) {         if (err) {             gutil.log('an error occured', err);         } else {             // no idea write             // files - array of validation results (from manual)         }     })) ); 

the best solution have reporter function works csslint.reporter does.

the gulp-w3c-css plugin serializes validation results each file json , stores json in file.contents property. format of json serialization looks following (for more details see w3c-css documentation):

{   errors: [ { line: 5, message: 'some error' },             { line: 42, message: 'some error' } ],   warnings: [ { line: 13, message: 'some warning' },               { line: 23, message: 'some warning' } ] } 

so have parse json , log information console in way want.

here's simple example of how it:

var gulp = require('gulp'); var cssvalidate = require('gulp-w3c-css'); var gutil = require('gulp-util'); var map = require('map-stream');  gulp.task('cssvalid', function () {   return gulp.src('testcss/*css')     .pipe(cssvalidate())     .pipe(map(function(file, done) {       if (file.contents.length == 0) {         console.log('success: ' + file.path);         console.log(gutil.colors.green('no errors or warnings\n'));       } else {         var results = json.parse(file.contents.tostring());         results.errors.foreach(function(error) {           console.log('error: ' + file.path + ': line ' + error.line);           console.log(gutil.colors.red(error.message) + '\n');         });         results.warnings.foreach(function(warning) {           console.log('warning: ' + file.path + ': line ' + warning.line);           console.log(gutil.colors.yellow(warning.message) + '\n');         });       }       done(null, file);     })); }); 

i used map-stream instead of gutil.buffer() results each file printed available instead of printing @ end.


Comments