mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Added support for "include" and "exclude" of source files in the project configuration. Closes issue #56.
This commit is contained in:
parent
95bb744fee
commit
1f6f4a7ee7
10
jsdoc.js
10
jsdoc.js
@ -246,12 +246,14 @@ function main() {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
43
rhino_modules/jsdoc/src/filter.js
Normal file
43
rhino_modules/jsdoc/src/filter.js
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
@module jsdoc/src/filter
|
||||
|
||||
@author Michael Mathews <micmath@gmail.com>
|
||||
@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;
|
||||
}
|
||||
@ -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($) {
|
||||
|
||||
19
test/specs/jsdoc/src/filter.js
Normal file
19
test/specs/jsdoc/src/filter.js
Normal file
@ -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);
|
||||
});
|
||||
});
|
||||
@ -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, '');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user