-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglob.js
43 lines (37 loc) · 1.06 KB
/
glob.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
38
39
40
41
42
43
var Rx = require('rx');
var Glob = require('glob').Glob;
var Minimatch = require('minimatch').Minimatch;
function rxGlob(pattern, options) {
return Rx.Observable.create(function (observer) {
var glob =
new Glob(pattern, options)
.on('match', observer.onNext.bind(observer))
.on('error', observer.onError.bind(observer))
.on('end', observer.onCompleted.bind(observer));
return glob.removeAllListeners.bind(glob);
});
}
module.exports = function (patterns, options) {
if (typeof patterns === 'string') {
patterns = patterns.split(',');
}
if (options.noglob) {
return Rx.Observable.fromArray(patterns);
}
var notBad =
patterns
.filter(function (pattern) { return pattern[0] === '!' })
.map(function (pattern) {
return new Minimatch(pattern, options);
});
return Rx.Observable.fromArray(patterns)
.filter(function (pattern) { return pattern[0] !== '!' })
.flatMap(function (pattern) {
return rxGlob(pattern, options);
})
.filter(function (file) {
return notBad.every(function (mm) {
return mm.match(file);
});
});
};