Remove `grunt.file.expandFiles` and `grunt.file.expandDirs` in favor of filtering methods? #531

Closed
cowboy opened this Issue Nov 15, 2012 · 6 comments

Comments

Projects
None yet
4 participants
Owner

cowboy commented Nov 15, 2012

We have grunt.file.expand and on top of that, two additional methods (grunt.file.expandFiles and grunt.file.expandDirs) that filter the result file set.

What if those were separate filtering methods?

Instead of this:

var filesOnly = grunt.file.expandFiles('*.*');

A user could do something like this:

var filesAndDirs = grunt.file.expand('*.*');
var filesOnly = grunt.file.files(filesAndDirs);

Comments?

Member

sindresorhus commented Nov 16, 2012

Hmm, it will still be the same method count though: .expand, .files and .dirs. Question is, will there ever be any need for more filters? I would prefer to stick with convenience methods if there aren't any good reason for splitting them.

Owner

cowboy commented Nov 16, 2012

The problem I'm running into here is that if I auto-expand wildcard globs in #532, that can only use one of these 3 methods. And it makes sense to use expand there because its results can then be filtered by files or dirs.

I just had an idea:

What if I added an option into the options object for grunt.file.expand called filter whose value could be one of: 'isFile', 'isDirectory', 'isBlockDevice', 'isCharacterDevice', 'isSymbolicLink', 'isFIFO', 'isSocket' (see this)... or a function which was passed a filepath that could return true or false.

Then we could just have one .expand method, and filter results via an option!

Owner

tkellen commented Nov 16, 2012

This all sounds handy, but shouldn't this wait for 0.5? Lord knows we don't need more features to document right now!

Owner

cowboy commented Nov 16, 2012

Sure, this one can wait.

Member

sindresorhus commented Nov 18, 2012

I like it! How about both, either a filter string or a method?

Owner

shama commented May 24, 2013

Turns out this didn't wait for 0.5 and was implemented. So closing ;)

@shama shama closed this May 24, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment