Skip to content

Instantly share code, notes, and snippets.

@prettycode
Last active August 29, 2015 14:17
Show Gist options
  • Save prettycode/e7381482fb91fb54471b to your computer and use it in GitHub Desktop.
Save prettycode/e7381482fb91fb54471b to your computer and use it in GitHub Desktop.
Get list of files using synchronous globbing
// 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