Last active
August 29, 2015 14:17
-
-
Save prettycode/e7381482fb91fb54471b to your computer and use it in GitHub Desktop.
Get list of files using synchronous globbing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// problem: the order of the files it finds can be different each time glob searches the exact same path | |
// solution: use synchronous globbing instead | |
var _ = require('lodash'), | |
glob = require('glob') | |
; | |
function deglob() { | |
var syncGlob = glob.sync, | |
patterns = _.flatten(arguments, true); | |
return _.flatten(patterns.map(function (pattern) { | |
return syncGlob(pattern).map(function (file) { | |
return pattern.charAt(0) === '!' ? ('!' + file) : file; | |
}); | |
}), true); | |
} | |
var files = deglob( | |
['scripts/app/**.js'], | |
['scripts/lib/**.js'] | |
); | |
// `files` will now be an expanded list of individual files that's in the exact same order every time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment