Code coverage report for istanbul/lib/util/file-matcher.js

Statements: 94.59% (35 / 37)      Branches: 92.86% (26 / 28)      Functions: 100% (7 / 7)      Lines: 100% (32 / 32)      Ignored: none     

All files » istanbul/lib/util/ » file-matcher.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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65          1       1 7 1 1   7   7           7 7 7   7 7 7 7 7 7 478   7       1   4 1 1   4 4   4 4   4 320   10 4 4       1          
/*
 Copyright (c) 2012, Yahoo! Inc.  All rights reserved.
 Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
 */
 
var fileset = require('fileset'),
    path = require('path'),
    seq = 0;
 
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) {
        Iif (err) { return callback(err); }
        if (!relative) {
            files = files.map(function (file) { return path.resolve(root, file); });
        }
        callback(err, files);
    });
}
 
function matcherFor(options, callback) {
 
    if (!callback && typeof options === 'function') {
        callback = options;
        options = null;
    }
    options = options || {};
    options.relative = false; //force absolute paths
 
    filesFor(options, function (err, files) {
        var fileMap = {},
            matchFn;
        Iif (err) { return callback(err); }
        files.forEach(function (file) { fileMap[file] = true; });
 
        matchFn = function (file) { return fileMap[file]; };
        matchFn.files = Object.keys(fileMap);
        return callback(null, matchFn);
    });
}
 
module.exports = {
    filesFor: filesFor,
    matcherFor: matcherFor
};