UNPKG

680 BJavaScriptView Raw
1'use strict';
2
3var match = require('gulp-match');
4var ternaryStream = require('ternary-stream');
5var through2 = require('through2');
6
7module.exports = function (condition, trueChild, falseChild, minimatchOptions) {
8 if (!trueChild) {
9 throw new Error('gulp-if: child action is required');
10 }
11
12 if (typeof condition === 'boolean') {
13 // no need to evaluate the condition for each file
14 // other benefit is it never loads the other stream
15 return condition ? trueChild : (falseChild || through2.obj());
16 }
17
18 function classifier (file) {
19 return !!match(file, condition, minimatchOptions);
20 }
21
22 return ternaryStream(classifier, trueChild, falseChild);
23};