-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
41 lines (32 loc) · 1.02 KB
/
index.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
'use strict';
var src = require('gulp').src;
var merge = require('merge-stream');
var unique = require('unique-stream');
var globManip = require('glob-manipulate');
module.exports = function(globs, options) {
if (!Array.isArray(globs)) throw new Error('`globs` argument must be an array');
var positives = [];
var negatives = [];
globs.forEach(function(glob, index) {
var globArray = globManip.isNegative(glob) ? negatives : positives;
globArray.push({
index: index,
glob: glob
});
});
if (!positives.length) throw new Error('Missing positive glob');
if (positives.length === 1) return createStream(positives[0]);
return merge.apply(undefined, positives.map(createStream)).pipe(unique('path'));
function createStream(positive) {
var negativeGlobs = negatives.filter(indexGreaterThan(positive.index)).map(toGlob);
return src([positive.glob].concat(negativeGlobs), options);
}
};
function indexGreaterThan(index) {
return function(obj) {
return obj.index > index;
};
}
function toGlob(obj) {
return obj.glob;
}