-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathexclude.js
45 lines (37 loc) · 1001 Bytes
/
exclude.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
44
45
'use strict';
var mm = require('micromatch');
var typeOf = require('kind-of');
var extend = require('extend-shallow');
var isWindows = require('is-windows');
function testPattern(pattern) {
return function (fp) {
return pattern.test(isWindows ? fp.split('\\').join('/') : fp);
}
}
module.exports = function (pattern, options) {
var opts = extend({}, options);
var type = typeOf(pattern);
var isMatch = type !== 'regexp'
? mm.matcher(pattern, opts)
: testPattern(pattern);
return function exclude(file) {
if (file.pattern.hasTrailingSlash && file.isFile()) {
return file;
}
if (isMatch(file.path)) {
file.exclude = true;
return file;
}
if (file.pattern.hasParent()) {
if (isMatch(file.relative)) {
file.exclude = true;
return file;
}
if (file.pattern.test(file.segment) || file.pattern.test(file.relative)) {
file.exclude = true;
return file;
}
}
return file;
};
};