Gulp: how do I see filenames of my glob

2.4k Views Asked by At

in Gulp, I have a glob pattern that I want to verify. For instance:

gulp.task('clean-requirejs', function() {
    return gulp.src([
        './public/res-min/**/*.js'
    ])
        .pipe(clean());
});

I want to see how the glob ['./public/res-min/**/*.js'] is expanded. How do I print the arguments/filelist which is generated by gulp.src in this example?

UPDATE: Turns out there is a really simple gulp-print which can solve the job like so:

var print = require('gulp-print').default;


[....]

.pipe(print());
2

There are 2 best solutions below

0
On BEST ANSWER

Turns out Gulp-Debug is just right for situations like this.

Example:

$ npm install --save-dev gulp-debug

var debug = require('gulp-debug');


gulp.task('clean-requirejs', function() {
    return gulp.src([
        './public/res-min/**/*.js'
    ])
    .pipe(debug())
    .pipe(clean());
});
1
On

While there are certainly cleaner solutions, when I don't want to bother with npm installing any new packages, I use the following function:

var through2 = require('through2');

function logFile(msg, lines) {
  lines = lines || 5;

  return through2.obj(function(file, enc, done) {
    console.log('logFile ' + msg);
    console.log(file.path);
    console.log(file.contents.toString().split('\n').splice(0,lines).join('\n'))
    this.push(file);
    done();
  });
}

And then, in your task

return gulp.src('...').pipe(logFile('name-of-task',5)).pipe(...)

The important parts are that you call this.push(file) and done().

There are probably libraries out there that do the same thing.