function filesFor(options, callback) { if (!callback && typeof options === 'function') { callback = options; options = null; } options = options || {}; var root = options.root, includes = options.includes, excludes = options.excludes, relative = options.relative, opts; root = root || process.cwd(); includes = includes && Array.isArray(includes) ? includes : [ '**/*.js' ]; excludes = excludes && Array.isArray(excludes) ? excludes : [ '**/node_modules/**' ]; opts = { cwd: root }; seq += 1; opts['x' + seq + new Date().getTime()] = true; //cache buster for minimatch cache bug fileset(includes.join(' '), excludes.join(' '), opts, function (err, files) { if (err) { return callback(err); } if (!relative) { files = files.map(function (file) { return path.resolve(root, file); }); } callback(err, files); }); }
Gaze.prototype.add = function(files, done) { var _this = this; if (typeof files === 'string') { files = [files]; } this._patterns = unique.apply(null, [this._patterns, files]); var include = [], exclude = []; this._patterns.forEach(function(p) { if (p.slice(0, 1) === '!') { exclude.push(p.slice(1)); } else { include.push(p); } }); fileset(include, exclude, _this.options, function(err, files) { if (err) { _this.emit('error', err); return done(err); } _this._addToWatched(files); _this.close(false); _this._initWatched(done); }); };
exports.compile = function (include, options, exclude) { var exclude = exclude || ""; if (!options.dir) { log("no dir", "error"); exit(1); } DEBUG = options.DEBUG || false; log("starting"); fileset(include, exclude) .on('include', function (file) { var abs_path = path.resolve(file); ed(abs_path, options); }) .on('exclude', function (file) { log(file, "debug"); }) .on("end", function () { log("done!"); }); };
this.setupPreprocessors = function(){ fileset( paths.preprocessors +'/**/*.js', '', function( err, preprocessor_paths ){ async.each( preprocessor_paths, solidus_server.addPreprocessor ); }); };
this.setupViews = function(){ fileset( paths.views +'/**/*.'+ DEFAULT_VIEW_EXTENSION, '', function( err, view_paths ){ async.each( view_paths, solidus_server.addView, function( err ){ solidus_server.emit('ready'); }); }); };
setUp: function (cb) { if (!allFiles) { fileset('**/*.js', '', { cwd: root}, function (err, files) { allFiles = files.map(function (file) { return path.resolve(root, file); }); cb(); }); } else { cb(); } },
async.reduce(want, [], function(allThatIWant, patternEntry, next){ var pattern = isa(patternEntry, String) ? patternEntry : patternEntry.src var attrs = patternEntry.attrs || [] fileset([self.resolvePath(pattern)], dontWant, function(err, files){ if (err) return next(err, allThatIWant) next(null, allThatIWant.concat(files.map(function(f){ f = self.reverseResolvePath(f) return {src: f, attrs: attrs} }))) }) }, function(err, fileEntries){
IstanbulReporter.prototype.exportReport = function () { var self = this; fileset(this.options.coverageFiles, function (err, files) { if (err) { grunt.log.error(err); self.options.doneCallback(false); } self.addEachFile(files); process.chdir(process.cwd() + '/' + self.options.baseDir); self.reporter.writeReport(self.collector, true); process.chdir(self.originalWorkingDirectory); self.options.doneCallback(); }); };
async.reduce(want, [], function(allThatIWant, patternEntry, next){ var pattern = isa(patternEntry, String) ? patternEntry : patternEntry.src var attrs = patternEntry.attrs || [] var patternUrl = url.parse(pattern) if (patternUrl.protocol == 'file:'){ pattern = patternUrl.hostname+patternUrl.path } else if (patternUrl.protocol){ return next(null, allThatIWant.concat({src: pattern, attrs: attrs})) } fileset([self.resolvePath(pattern)], dontWant, function(err, files){ if (err) return next(err, allThatIWant) next(null, allThatIWant.concat(files.map(function(f){ f = self.reverseResolvePath(f) return {src: f, attrs: attrs} }))) }) }, function(err, fileEntries){
instrumentFiles: function (includes, excludes, callback) { var that = this, fileMap = {}, sCount = 0, eCount = 0, skipCount = 0, opts = { cwd: this.inputDir }; cacheBuster += 1; opts['x' + cacheBuster] = true; //workaround minimatch cache bug https://github.com/isaacs/minimatch/issues/9 fileset(includes.join(' '), excludes.join(' '), opts, function (err, files) { if (err) { console.error('Error finding files for fileset'); return callback(err); } async.forEachSeries(files, function (file, cb) { var filePath = path.join(that.inputDir, file); that.instrumentFile(file, function (err, outFile, skipped) { if (err) { eCount += 1; console.error(err); } else { sCount += 1; skipCount += skipped ? 1 : 0; fileMap[filePath] = outFile; } cb(null); //always success from async's viewpoint }); }, function (err) { if (!err && skipCount > 0) { //emit a message, even in non-verbose mode, that some files skipped instrumentation console.log(String(skipCount) + ' file(s) not instrumented, since they already exist from a previous run'); } return callback(err, { successCount: sCount, failureCount: eCount, skipCount: skipCount, fileMap: fileMap }); }); }); },
function filesFor(options, callback) { if (!callback && typeof options === 'function') { callback = options; options = null; } options = options || {}; var root = options.root, includes = options.includes, excludes = options.excludes, realpath = options.realpath, relative = options.relative, opts; root = root || process.cwd(); includes = includes && Array.isArray(includes) ? includes : [ '**/*.js' ]; excludes = excludes && Array.isArray(excludes) ? excludes : [ '**/node_modules/**' ]; opts = { cwd: root, nodir: true, ignore: excludes }; seq += 1; opts['x' + seq + new Date().getTime()] = true; //cache buster for minimatch cache bug fileset(includes.join(' '), excludes.join(' '), opts, function (err, files) { /* istanbul ignore if - untestable */ if (err) { return callback(err); } if (relative) { return callback(err, files); } if (!realpath) { files = files.map(function (file) { return path.resolve(root, file); }); return callback(err, files); } var realPathCache = module.constructor._realpathCache || /* istanbul ignore next */ {}; async.map(files, function (file, done) { fs.realpath(path.resolve(root, file), realPathCache, done); }, callback); }); }
/** * callback(Error, builtFiles, sourceFiles, rootSourceFiles) */ function builder (config, configPath, callback) { var inc = new Include(config) inc .on('drain', function () { // All files and their dependencies loaded, root files (files with no parent file) built inc.build(function () { var output = path.resolve( configPath, config.output.path ) var outputFiles = [] debug('Include DONE: %d roots found output=%s', inc.roots.length, output) async.forEach( inc.roots , function (file, cb) { var relfile = path.join( output, path.relative(configPath, file.id) ) outputFiles.push(relfile) debug('Include WRITING: file=%s', relfile) var w = fstream .Writer({ path: relfile , mode: config.output.mode }) w .on('close', cb) if (file.content) w.end(file.content) else fs.createReadStream(file.id).pipe(w) } , function (err) { if (err) return callback(err) debug('%d files written out to %s', inc.roots.length, output) callback( null , outputFiles , inc.sourceFiles , inc.roots.map(function(root) { return root.id }) ) } ) }) }) debug( path.resolve( configPath, config.input.include || '*.js' ) ) debug( config.input.include || '*.js' ) debug( config.input.exclude || '' ) fileset( config.input.include || '*.js' , config.input.exclude || '' , { cwd: configPath } , function (err, files) { if (err) throw err debug('files', files) files .forEach(function (file) { inc.add( path.resolve( configPath, file) ) }) } ) }