Folder exclusion with grunt (minimatch / glob)

I have a situation where I try to use grunt to use code excluding certain folders.

grunt uses the minimal (similar to bsdglob) under the hood to match files, but I can't figure out how to make the .gitignore style exclude the folder.

I would like to swallow this:

ignoreme

and map them:

 /folder/path/here/to/something/ok.js /another/folder/path.js /test.js 

but do not match these:

 /folder/ignoreme/something.js /folder/path/here/to/ignoreme/metoo/file.js 

This will match everyone, including ignoreme:

 /**/*.js 

So, I decided that I could do something like:

 /**/!(ignoreme)/**/*.js 

but this corresponds to the files in the ignoreme folder.

I'm used to regular expressions, but can't figure out how to repeat a pattern or anything like that. I also tried things like:

 /(!(ignoreme)|*)*/*.js 

I hope that the container will be repeated, but this will not work, it just does not match everyone.

Any way to pass regex to grunt file paths or do it for me?

Update:

Here's how I deal with this problem right now:

 var pattern = /\/ignoreme\// var files = grunt.file.expandFiles(arrayOfFilesPassedToMinimatch).filter(function(f){ return !pattern.test(f) }) 

I will still be interested if the exclusion of the folder is excluded during the minimization process.

+73
javascript regex gruntjs glob
Sep 28 2018-12-12T00: 00Z
source share
1 answer

In the current version of version 0.4.0a, the grunt.file.expand method now supports exceptions, and does this in perhaps a less complicated way than the base library corresponding to the minimization method. This is possible because grunt.file.expand accepts multiple patterns (while minimizing only one).

From the grunt.file.expand documentation :

This method accepts comma-separated wildcards or an array of wildcard patterns. Paths matching patterns that start with! will be excluded from the returned array. Templates are processed in order, so the order of inclusion and exclusion is significant.

This means that you can specify ['/**/*.js', '!**/ignoreme/**'] , and while the first template will add all .js files to the result set, the second template will then delete all /ignoreme/ files from the result set.

Take a look at the grunt.file.match tests if you are really interested.

Please note that the version of grunt that offers this functionality has not been officially released, but if you are interested in using it in a project, see When can I use the built-in "X" function? FAQ

+148
Sep 28 '12 at 3:12
source share



All Articles