Search code examples
node.jsgulp

gulp.src() or it's alternative outside the gulp task


Let me to start from the problem. In my gulpfile.js, I need to get some files in multiple paths, collect some info about this files (e. g. file names) and write this info to file (suppose, to info.json). Then, info.json will be used in the gulp tasks.

This question about first step - getting files in multiple watchable directories. It is simple via gulp.src([/* paths array */]), but I can not do whatever I what inside pipeline as below:

gulp.task('parse files collection', callback =>{
    return gulp.src([/* array of the paths */]).
        .pipe// Now I need to do collect some info about this files, e. g. file names
        // and write this info to file
})

So I need to do above actions inside some function, not inside gulp task. But I if so, I can not use gulp.src() inside this function to collect the files.

Any suggestions?


Solution

  • Use node-glob

    Actually this is underlying of gulp.src()