How do I output gulp results to console?

前端 未结 1 2009
孤街浪徒
孤街浪徒 2020-12-31 02:45

I want to put my spellcheck results out to the console instead of to a file and I think this should work since as I understand it gulp returns a stream.

Instead I g

相关标签:
1条回答
  • 2020-12-31 03:00

    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);
            }
        });
    });
    
    0 讨论(0)
提交回复
热议问题