grunt (minimatch/glob) folder exclusion

In the currently-in-development version 0.4.0a, the grunt.file.expand method now supports exclusions, and does so in an arguably less complex way than the underlying minimatch matching library. This is possible because grunt.file.expand accepts multiple patterns (whereas minimatch only accepts one).

From the grunt.file.expand documentation:

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

That means you could specify ['/**/*.js', '!**/ignoreme/**'] and while the first pattern would add all .js files to the result set, the second pattern would then remove all /ignoreme/ files from the result set.

Take a look at the grunt.file.match unit tests if you're really curious.

Note that the version of grunt offering this functionality hasn't officially been released, but if you're interested in using it in a project, see the When will I be able to use in-development feature 'X'? FAQ entry.