index.js 657 B

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