forked from jsdoc/jsdoc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for "include" and "exclude" of source files in the proj…
…ect configuration. Closes issue jsdoc#56.
- Loading branch information
Showing
5 changed files
with
76 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
@module jsdoc/src/filter | ||
@author Michael Mathews <[email protected]> | ||
@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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters