Skip to content

Commit

Permalink
Support negations in directory excludes
Browse files Browse the repository at this point in the history
  • Loading branch information
stoically authored and Gerrit0 committed Jul 26, 2019
1 parent b328537 commit 92f0f25
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/lib/application.ts
Expand Up @@ -266,22 +266,27 @@ export class Application extends ChildableComponent<Application, AbstractCompone
}

const supportedFileRegex = this.options.getCompilerOptions().allowJs ? /\.[tj]sx?$/ : /\.tsx?$/;
function add(file: string) {
if (isExcluded(file.replace(/\\/g, '/'))) {
function add(file: string, entryPoint: boolean) {
const fileIsDir = FS.statSync(file).isDirectory();
if (fileIsDir && file.slice(-1) !== '/') {
file = `${file}/`;
}

if ((!fileIsDir || !entryPoint) && isExcluded(file.replace(/\\/g, '/'))) {
return;
}

if (FS.statSync(file).isDirectory()) {
if (fileIsDir) {
FS.readdirSync(file).forEach(next => {
add(Path.join(file, next));
add(Path.join(file, next), false);
});
} else if (supportedFileRegex.test(file)) {
files.push(file);
}
}

inputFiles.forEach(file => {
add(Path.resolve(file));
add(Path.resolve(file), true);
});

return files;
Expand Down
10 changes: 10 additions & 0 deletions src/test/typedoc.test.ts
Expand Up @@ -87,5 +87,15 @@ describe('TypeDoc', function() {
Assert.strictEqual(expanded.includes(Path.join(inputFiles, 'access', 'access.ts')), false);
Assert.strictEqual(expanded.includes(inputFiles), false);
});

it('supports negations in directory excludes', function() {
const inputFiles = Path.join(__dirname, 'converter');
application.options.setValue('exclude', [ '**/!(access)/' ]);
const expanded = application.expandInputFiles([inputFiles]);

Assert.strictEqual(expanded.includes(Path.join(inputFiles, 'class', 'class.ts')), false);
Assert.strictEqual(expanded.includes(Path.join(inputFiles, 'access', 'access.ts')), true);
Assert.strictEqual(expanded.includes(inputFiles), false);
});
});
});

0 comments on commit 92f0f25

Please sign in to comment.