Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp glob to ignore file types and not copy empty folders

I have created a glob for gulp which ignores javascript and coffeescript files within a set of directories. I'd like it to copy all other files into a directory which works fine. The only problem is that when there are only javascript or coffeescript files it copies an empty folder. Any ideas how this glob could be amended to not copy empty folders?

gulp.task('copyfiles', function(){
    gulp.src('apps/*/static_src/**/!(*.js|*.coffee)')
        .pipe(gulp.dest('dest'));
});

Example source files:

apps/appname/static_src/images/image.jpg
apps/appname/static_src/js/script.js

Expected output:

dest/static_src/images/image.jpg

Current output:

dest/static_src/images/image.jpg
dest/static_src/js/
like image 564
Adam Avatar asked Feb 26 '16 14:02

Adam


1 Answers

Since gulp.src accepts almost the same options as node-glob, you can add nodir: trueas an option:

gulp.src('apps/*/static_src/**/!(*.js|*.coffee)', { nodir: true })

This will preserve the dir structure from src, but omit empty ones.

like image 121
Andreas Ågren Avatar answered Oct 18 '22 08:10

Andreas Ågren