Code coverage report for master/lib/jsdoc/src/scanner.js

Statements: 89.66% (26 / 29)      Branches: 50% (3 / 6)      Functions: 100% (5 / 5)      Lines: 89.66% (26 / 29)      Ignored: none     

All files » master/lib/jsdoc/src/ » scanner.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 66 67 68 69                  1 1 1 1           1 1               1 1 1 1 1   1 1   1 1   1 1             1       1       1 6     1 3 3   3     1    
/**
    @module jsdoc/src/scanner
    @requires module:fs
 
    @author Michael Mathews <micmath@gmail.com>
    @license Apache License 2.0 - See file 'LICENSE.md' in this project.
 */
'use strict';
 
var env = require('jsdoc/env');
var fs = require('jsdoc/fs');
var logger = require('jsdoc/util/logger');
var path = require('jsdoc/path');
 
/**
    @constructor
    @mixes module:events
 */
exports.Scanner = function() {};
exports.Scanner.prototype = Object.create( require('events').EventEmitter.prototype );
 
/**
    Recursively searches the given searchPaths for js files.
    @param {Array.<string>} searchPaths
    @param {number} [depth=1]
    @fires sourceFileFound
 */
exports.Scanner.prototype.scan = function(searchPaths, depth, filter) {
    var currentFile;
    var filePaths = [];
    var isFile;
    var self = this;
 
    searchPaths = searchPaths || [];
    depth = depth || 1;
 
    searchPaths.forEach(function($) {
        var filepath = path.resolve( env.pwd, decodeURIComponent($) );
 
        try {
            currentFile = fs.statSync(filepath);
        }
        catch (e) {
            logger.error('Unable to find the source file or directory %s', filepath);
            return;
        }
 
        Iif ( currentFile.isFile() ) {
            filePaths.push(filepath);
        }
        else {
            filePaths = filePaths.concat( fs.ls(filepath, depth) );
        }
    });
 
    filePaths = filePaths.filter(function($) {
        return filter.isIncluded($);
    });
 
    filePaths = filePaths.filter(function($) {
        var e = { fileName: $ };
        self.emit('sourceFileFound', e);
 
        return !e.defaultPrevented;
    });
 
    return filePaths;
};