且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将 gulp 结果输出到控制台?

更新时间:2023-12-05 13:16:52

流上没有读取方法.你有两个选择:

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

  1. 使用实际的控制台流:process.stdout
  2. 使用数据事件到console.log.
  1. Use the actual console stream: process.stdout
  2. Use the the data event to console.log.

在代码中实现:

 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 '
' + match +'
'; 
            } 
            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 = '

' + Array(bufLength).join("_") + '

'
        if (contents.length > 1) {
            process.stdout.write(chunk.path + '
' + contents + '
');
            process.stdout.write(chunk.path + hr);
        }
    });
});