且构网

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

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

更新时间:2023-12-05 13:07:58

流中没有读取方法。您有两种选择:

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.



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);
        }
    });
});