Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/TypeStrong/typedoc
Browse files Browse the repository at this point in the history
  • Loading branch information
aciccarello committed Feb 1, 2018
2 parents db0cae5 + cd7bfab commit ebc1cf1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/lib/application.ts
Expand Up @@ -78,10 +78,10 @@ export class Application extends ChildableComponent<Application, AbstractCompone

@Option({
name: 'exclude',
help: 'Define a pattern for excluded files when specifying paths.',
type: ParameterType.String
help: 'Define patterns for excluded files when specifying paths.',
type: ParameterType.Array
})
exclude: string;
exclude: Array<string>;

/**
* The version number of TypeDoc.
Expand Down Expand Up @@ -247,9 +247,11 @@ export class Application extends ChildableComponent<Application, AbstractCompone
* @returns The list of input files with expanded directories.
*/
public expandInputFiles(inputFiles?: string[]): string[] {
let exclude: IMinimatch, files: string[] = [];
if (this.exclude) {
exclude = new Minimatch(this.exclude);
let files: string[] = [];
const exclude: Array<IMinimatch> = this.exclude ? this.exclude.map(pattern => new Minimatch(pattern)) : [];

function isExcluded(fileName: string): boolean {
return exclude.some(mm => mm.match(fileName));
}

function add(dirname: string) {
Expand All @@ -258,7 +260,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
if (FS.statSync(realpath).isDirectory()) {
add(realpath);
} else if (/\.tsx?$/.test(realpath)) {
if (exclude && exclude.match(realpath.replace(/\\/g, '/'))) {
if (isExcluded(realpath.replace(/\\/g, '/'))) {
return;
}

Expand All @@ -271,7 +273,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
file = Path.resolve(file);
if (FS.statSync(file).isDirectory()) {
add(file);
} else if (!exclude || !exclude.match(file)) {
} else if (!isExcluded(file)) {
files.push(file);
}
});
Expand Down
9 changes: 9 additions & 0 deletions src/test/typedoc.ts
Expand Up @@ -42,6 +42,15 @@ describe('TypeDoc', function() {
application.options.setValue('exclude', '**/+(class|access).ts');
const expanded = application.expandInputFiles([inputFiles]);

Assert.equal(expanded.indexOf(Path.join(inputFiles, 'class', 'class.ts')), -1);
Assert.equal(expanded.indexOf(Path.join(inputFiles, 'access', 'access.ts')), -1);
Assert.equal(expanded.indexOf(inputFiles), -1);
});
it('supports array of excludes', function() {
const inputFiles = Path.join(__dirname, 'converter');
application.options.setValue('exclude', [ '**/class.ts', '**/access.ts' ]);
const expanded = application.expandInputFiles([inputFiles]);

Assert.equal(expanded.indexOf(Path.join(inputFiles, 'class', 'class.ts')), -1);
Assert.equal(expanded.indexOf(Path.join(inputFiles, 'access', 'access.ts')), -1);
Assert.equal(expanded.indexOf(inputFiles), -1);
Expand Down

0 comments on commit ebc1cf1

Please sign in to comment.