forked from NekR/glob-loader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglob-array.js
37 lines (28 loc) · 847 Bytes
/
glob-array.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var glob = require('glob');
var minimatch = require('minimatch');
var filterNegative = function(negativeMatches, allMatches) {
negativeMatches.forEach(function(pattern) {
allMatches = allMatches.filter(function(file) {
return minimatch(file, pattern);
});
});
return allMatches;
};
var globArray = {};
globArray.sync = function(patterns, options) {
var fileMatches = [];
patterns = patterns || [];
options = options || {};
var negativeGlobs = [];
patterns.forEach(function(pattern) {
if (pattern.substr(0, 1) !== '!') {
var patternMatches = glob.sync(pattern, options);
fileMatches = fileMatches.concat(patternMatches);
} else {
negativeGlobs.push(pattern);
}
});
fileMatches = filterNegative(negativeGlobs, fileMatches);
return fileMatches;
};
module.exports = globArray;