How do I output gulp results to console?

£可爱£侵袭症+ 提交于 2019-11-30 08:15:12
leogdion

There is no read method on a stream. You have have two choices:

  1. Use the actual console stream: process.stdout
  2. Use the the data event to console.log.

Implemented in code:

 gulp.task('spellcheck', function () {
    var patterns = [
      {
        // Strip tags from HTML
        pattern: /(<([^>]+)>)/ig,
        replacement: ''
      }];

    var nonSuggestions = [
    {
        pattern:  /<<<.+>>>|([^\s]+[^<]+)/g,
        replacement: function(match) {
            if (match.indexOf('<')==0) {
                return '\n' + match +'\n'; 
            } 
            return '';
        }
      }];
    var a = gulp.src('./_site/**/*.html')
        .pipe(frep(patterns))
        .pipe(spellcheck(({replacement: '<<<%s (suggestions: %s)>>>'})))
        .pipe(frep(nonSuggestions))
        ;   

    a.on('data', function(chunk) {
        var contents = chunk.contents.toString().trim(); 
        var bufLength = process.stdout.columns;
        var hr = '\n\n' + Array(bufLength).join("_") + '\n\n'
        if (contents.length > 1) {
            process.stdout.write(chunk.path + '\n' + contents + '\n');
            process.stdout.write(chunk.path + hr);
        }
    });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!