diff --git a/jsdoc.js b/jsdoc.js index bac8f91a..02f28d14 100644 --- a/jsdoc.js +++ b/jsdoc.js @@ -245,13 +245,15 @@ function main() { env.opts._.splice(i--, 1); } } - + + if (env.opts.source.include) { + env.opts._ = (env.opts._ || []).concat(env.opts.source.include); + } + if (env.opts._.length > 0) { // are there any files to scan and parse? + var filter = new (require('jsdoc/src/filter').Filter)(env.conf.source); - var includeMatch = (env.conf.source && env.conf.source.includePattern)? new RegExp(env.conf.source.includePattern) : null, - excludeMatch = (env.conf.source && env.conf.source.excludePattern)? new RegExp(env.conf.source.excludePattern) : null; - - sourceFiles = app.jsdoc.scanner.scan(env.opts._, (env.opts.recurse? 10 : undefined), includeMatch, excludeMatch); + sourceFiles = app.jsdoc.scanner.scan(env.opts._, (env.opts.recurse? 10 : undefined), filter); require('jsdoc/src/handlers').attachTo(app.jsdoc.parser); diff --git a/rhino_modules/jsdoc/src/filter.js b/rhino_modules/jsdoc/src/filter.js new file mode 100644 index 00000000..a2664305 --- /dev/null +++ b/rhino_modules/jsdoc/src/filter.js @@ -0,0 +1,43 @@ +/** + @module jsdoc/src/filter + + @author Michael Mathews + @license Apache License 2.0 - See file 'LICENSE.md' in this project. + */ + +/** + @constructor + @param {object} opts + @param {string[]} opts.exclude - Specific files to exclude. + @param {string|RegExp} opts.includePattern + @param {string|RegExp} opts.excludePattern + */ +exports.Filter = function(opts) { + this.exclude = opts.exclude || null; + this.includePattern = opts.includePattern? + typeof opts.includePattern === 'string'? new RegExp(opts.includePattern) : opts.includePattern + : null; + this.excludePattern = opts.excludePattern? + typeof opts.excludePattern === 'string'? new RegExp(opts.excludePattern) : opts.excludePattern + : null; +} + +/** + @param {string} filepath - The filepath to check. + @returns {boolean} Should the given file be included? + */ +exports.Filter.prototype.isIncluded = function(filepath) { + if ( this.includePattern && !this.includePattern.test(filepath) ) { + return false; + } + + if ( this.excludePattern && this.excludePattern.test(filepath) ) { + return false; + } + + if ( this.exclude && this.exclude.indexOf(filepath) > -1 ) { + return false; + } + + return true; +} \ No newline at end of file diff --git a/rhino_modules/jsdoc/src/scanner.js b/rhino_modules/jsdoc/src/scanner.js index 9b8ff7e6..2c5ad30a 100644 --- a/rhino_modules/jsdoc/src/scanner.js +++ b/rhino_modules/jsdoc/src/scanner.js @@ -28,7 +28,7 @@ common.mixin(exports.Scanner.prototype, common.events); @param {number} [depth=1] @fires sourceFileFound */ -exports.Scanner.prototype.scan = function(searchPaths, depth, includeMatch, excludeMatch) { +exports.Scanner.prototype.scan = function(searchPaths, depth, filter) { var filePaths = [], that = this; @@ -45,15 +45,7 @@ exports.Scanner.prototype.scan = function(searchPaths, depth, includeMatch, excl }); filePaths = filePaths.filter(function($) { - if (includeMatch && !includeMatch.test($)) { - return false - } - - if (excludeMatch && excludeMatch.test($)) { - return false - } - - return true; + return filter.isIncluded($); }); filePaths = filePaths.filter(function($) { diff --git a/test/specs/jsdoc/src/filter.js b/test/specs/jsdoc/src/filter.js new file mode 100644 index 00000000..9d744271 --- /dev/null +++ b/test/specs/jsdoc/src/filter.js @@ -0,0 +1,19 @@ +describe("jsdoc/src/filter", function() { + var filter = new (require('jsdoc/src/filter').Filter)({ + includePattern: new RegExp(".+\\.js(doc)?$"), + excludePattern: new RegExp("(^|\\/)_"), + exclude: ['.ignore', 'scratch/conf.js'] + }); + + var files = ['yes.js', '/yes.jsdoc', '/_nope.js', '.ignore']; + + files = files.filter(function($) { + return filter.isIncluded($); + }); + + it("should return the correct source files", function() { + expect(files.length).toEqual(2); + expect(files.indexOf("yes.js")).toBeGreaterThan(-1); + expect(files.indexOf("/yes.jsdoc")).toBeGreaterThan(-1); + }); +}); \ No newline at end of file diff --git a/test/specs/jsdoc/src/scanner.js b/test/specs/jsdoc/src/scanner.js index 5b82dffd..e9f127e7 100644 --- a/test/specs/jsdoc/src/scanner.js +++ b/test/specs/jsdoc/src/scanner.js @@ -1,8 +1,10 @@ describe("jsdoc/src/scanner", function() { var scanner = new (require('jsdoc/src/scanner').Scanner)(), - includeMatch = new RegExp(".+\\.js(doc)?$"), - excludeMatch = new RegExp("(^|\\/)_"), - sourceFiles = scanner.scan([__dirname+'/test/fixtures/src/'], 3, includeMatch, excludeMatch); + filter = new (require('jsdoc/src/filter').Filter)({ + includePattern: new RegExp(".+\\.js(doc)?$"), + excludePattern: new RegExp("(^|\\/)_") + }), + sourceFiles = scanner.scan([__dirname+'/test/fixtures/src/'], 3, filter); sourceFiles = sourceFiles.map(function($) { return $.replace(__dirname, '');