react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / fileset / lib / fileset.js
80684 viewsvar util = require('util'),1minimatch = require('minimatch'),2Glob = require('glob').Glob,3EventEmitter = require('events').EventEmitter;45module.exports = fileset;67function fileset(include, exclude, options, cb) {8if (typeof exclude === 'function') cb = exclude, exclude = '';9else if (typeof options === 'function') cb = options, options = {};1011var includes = (typeof include === 'string') ? include.split(' ') : include;12var excludes = (typeof exclude === 'string') ? exclude.split(' ') : exclude;1314var em = new EventEmitter,15remaining = includes.length,16results = [];1718if(!includes.length) return cb(new Error('Must provide an include pattern'));1920em.includes = includes.map(function(pattern) {21return new fileset.Fileset(pattern, options)22.on('error', cb ? cb : em.emit.bind(em, 'error'))23.on('match', em.emit.bind(em, 'match'))24.on('match', em.emit.bind(em, 'include'))25.on('end', next.bind({}, pattern))26});2728function next(pattern, matches) {29results = results.concat(matches);3031if(!(--remaining)) {32results = results.filter(function(file) {33return !excludes.filter(function(glob) {34var match = minimatch(file, glob, { matchBase: true });35if(match) em.emit('exclude', file);36return match;37}).length;38});3940if(cb) cb(null, results);41em.emit('end', results);42}43}4445return em;46}4748fileset.Fileset = function Fileset(pattern, options, cb) {4950if (typeof options === 'function') cb = options, options = {};51if (!options) options = {};5253Glob.call(this, pattern, options);5455if(typeof cb === 'function') {56this.on('error', cb);57this.on('end', function(matches) { cb(null, matches); });58}59};6061util.inherits(fileset.Fileset, Glob);6263646566