Skip to content

Commit 0ace37b

Browse files
committed
Upgrade to typedoc@0.16.4
1 parent d9f71dd commit 0ace37b

12 files changed

+176
-81
lines changed

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
module.exports = {
22
roots: [
3+
'<rootDir>/bin',
34
'<rootDir>/src',
45
'<rootDir>/tests'
56
],
67
testMatch: [
78
'**/__tests__/**/*.+(ts|tsx|js)',
89
'**/?(*.)+(spec|test).+(ts|tsx|js)',
9-
'**/dynamic-tests.ts'
10+
'**/*-tests.ts'
1011
],
1112
transform: {
1213
'^.+\\.(ts|tsx)?$': 'ts-jest'

package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@
4747
},
4848
"dependencies": {
4949
"make-dir": "^3.0.0",
50-
"typedoc": "^0.16.2"
50+
"typedoc": "^0.16.4"
5151
}
5252
}

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const externalDependencies = [
44
'fs',
55
'make-dir',
66
'path',
7+
'typedoc',
78
'typedoc/dist/lib/converter',
89
'typedoc/dist/lib/converter/components',
910
'typedoc/dist/lib/converter/nodes/block',

src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@ import { KeyOfPlugin } from './keyof-plugin';
33
import { OmitTagsPlugin } from './omit-tags-plugin';
44
import { TypeScriptDeclarationPlugin } from './typescript-declaration-plugin';
55
import { VersionFilterPlugin } from './version-filter-plugin';
6-
import { addDecoratedOptions } from 'typedoc/dist/lib/utils/options/sources';
6+
7+
const options = [
8+
...VersionFilterPlugin.options,
9+
...KeyOfPlugin.options,
10+
...OmitTagsPlugin.options,
11+
...TypeScriptDeclarationPlugin.options,
12+
];
713

814
module.exports = (PluginHost: Application) => {
915
const app = PluginHost.owner;
1016

17+
app.options.addDeclarations(options);
18+
1119
app.converter.addComponent('version-filter', new VersionFilterPlugin(app.converter));
1220
app.converter.addComponent('keyof-comment', new KeyOfPlugin(app.converter));
1321
app.converter.addComponent('omit-tags', new OmitTagsPlugin(app.converter));
1422

1523
const declarationPlugin = app.renderer.addComponent('typescript-declaration', new TypeScriptDeclarationPlugin(app.renderer));
1624

17-
// work-around for typedoc options not being read: https://github.com/TypeStrong/typedoc/issues/1165
18-
addDecoratedOptions(app.options);
19-
2025
declarationPlugin.applyConfiguration();
2126
}
27+
28+
module.exports.options = options;

src/keyof-plugin.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Context, Converter } from 'typedoc/dist/lib/converter';
2-
import { Component } from 'typedoc/dist/lib/output/components';
2+
import { DeclarationOption, ParameterType } from 'typedoc/dist/lib/utils/options/declaration';
33
import { ConverterComponent } from 'typedoc/dist/lib/converter/components';
44
import KeyOfCommentResolver from './convert/keyof-comment-resolver';
5-
import { Option } from 'typedoc/dist/lib/utils';
6-
import { ParameterType } from 'typedoc/dist/lib/utils/options/declaration';
5+
import { bind } from './util/options';
76

87
export enum AddKeysTagOption {
98
off = 0,
@@ -17,16 +16,21 @@ export const addKeysOptionMapping: { [key: string]: AddKeysTagOption } = {
1716
update: AddKeysTagOption.update,
1817
};
1918

20-
@Component({ name: 'keyof' })
19+
const keyofCommentsOption = {
20+
name: 'keyofComments',
21+
type: ParameterType.Map,
22+
help: 'Expands the values of the keyof operator and adds a tag, default is set to off',
23+
defaultValue: AddKeysTagOption.off,
24+
map: addKeysOptionMapping,
25+
} as DeclarationOption;
26+
2127
export class KeyOfPlugin extends ConverterComponent {
22-
@Option({
23-
name: 'keyofComments',
24-
type: ParameterType.Map,
25-
help: 'Expands the values of the keyof operator and adds a tag, default is set to off',
26-
defaultValue: AddKeysTagOption.off,
27-
map: addKeysOptionMapping,
28-
})
29-
private _mode!: AddKeysTagOption;
28+
static options = [
29+
keyofCommentsOption,
30+
];
31+
32+
@bind(keyofCommentsOption)
33+
_mode!: AddKeysTagOption;
3034

3135
protected initialize() {
3236
this.listenTo(this.owner, {

src/omit-tags-plugin.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import { Context, Converter } from 'typedoc/dist/lib/converter';
2-
import { Component } from 'typedoc/dist/lib/output/components';
2+
import { DeclarationOption, ParameterType } from 'typedoc/dist/lib/utils/options/declaration';
33
import { ConverterComponent } from 'typedoc/dist/lib/converter/components';
4-
import { Option } from 'typedoc/dist/lib/utils';
5-
import { ParameterType } from 'typedoc/dist/lib/utils/options/declaration';
64
import { Reflection } from 'typedoc/dist/lib/models';
5+
import { bind } from './util/options';
6+
7+
const omitTagOption = {
8+
name: 'omitTag',
9+
type: ParameterType.Array,
10+
help: 'A list of tags to remove from the generated output',
11+
} as DeclarationOption;
712

8-
@Component({ name: 'omit-tags' })
913
export class OmitTagsPlugin extends ConverterComponent {
10-
@Option({
11-
name: 'omitTag',
12-
type: ParameterType.Array,
13-
help: 'A list of tags to remove from the generated output',
14-
})
15-
private _omitTags?: string[];
14+
static options = [
15+
omitTagOption,
16+
];
17+
18+
@bind(omitTagOption)
19+
_omitTags: string[] | undefined;
1620

1721
protected initialize() {
1822
this.listenTo(this.owner, {

src/typescript-declaration-plugin.ts

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,51 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3-
import { Component, RendererComponent } from 'typedoc/dist/lib/output/components';
4-
import { ParameterHint, ParameterType, TypeDocOptions } from 'typedoc/dist/lib/utils/options/declaration';
3+
import { DeclarationOption, ParameterHint, ParameterType, TypeDocOptions } from 'typedoc/dist/lib/utils/options/declaration';
54
import ReflectionFormatter, { ReflectionSortFlags, sortMapping } from './render/reflection-formatter';
6-
import { Option } from 'typedoc/dist/lib/utils';
75
import { ProjectReflection } from 'typedoc/dist/lib/models';
86
import { Renderer } from 'typedoc/dist/lib/output/renderer';
7+
import { RendererComponent } from 'typedoc/dist/lib/output/components';
98
import { RendererEvent } from 'typedoc/dist/lib/output/events';
10-
import { SourceFileMode } from 'typedoc/dist/lib/converter/nodes/block';
9+
import { SourceFileMode } from 'typedoc/dist/lib/utils';
10+
import { bind } from './util/options';
1111
import mkdir from 'make-dir';
1212

13-
@Component({ name: 'typescript-declaration' })
13+
const declarationFileOption = {
14+
name: 'declarationFile',
15+
hint: ParameterHint.File,
16+
type: ParameterType.String,
17+
help: 'The output file location to write the declaration to',
18+
} as DeclarationOption;
19+
20+
const declarationOnlyOption = {
21+
name: 'declarationOnly',
22+
type: ParameterType.Boolean,
23+
help: 'Render the type declaration file only, other renderers will be removed (must be used with --declarationFile option)',
24+
} as DeclarationOption;
25+
26+
const sortOptionOption = {
27+
name: 'sortOption',
28+
type: ParameterType.Map,
29+
help: 'Sort types in declaration file by name instead of the typedoc default',
30+
defaultValue: ReflectionSortFlags.none,
31+
map: sortMapping,
32+
} as DeclarationOption;
33+
1434
export class TypeScriptDeclarationPlugin extends RendererComponent {
15-
@Option({
16-
name: 'declarationFile',
17-
hint: ParameterHint.File,
18-
type: ParameterType.String,
19-
help: 'The output file location to write the declaration to',
20-
})
21-
private _declarationFile?: string;
22-
23-
@Option({
24-
name: 'declarationOnly',
25-
type: ParameterType.Boolean,
26-
help: 'Render the type declaration file only, other renderers will be removed (must be used with --declarationFile option)',
27-
})
28-
private _declarationOnly?: boolean;
29-
30-
@Option({
31-
name: 'sortOption',
32-
type: ParameterType.Map,
33-
help: 'Sort types in declaration file by name instead of the typedoc default',
34-
defaultValue: ReflectionSortFlags.none,
35-
map: sortMapping,
36-
})
37-
private _sortOption!: ReflectionSortFlags;
35+
static options = [
36+
declarationFileOption,
37+
declarationOnlyOption,
38+
sortOptionOption,
39+
];
40+
41+
@bind(declarationFileOption)
42+
_declarationFile: string | undefined;
43+
44+
@bind(declarationOnlyOption)
45+
_declarationOnly: boolean | undefined;
46+
47+
@bind(sortOptionOption)
48+
_sortOption!: ReflectionSortFlags;
3849

3950
protected initialize() {
4051
this.listenTo(this.owner, {

src/util/options.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Application, BindOption, DeclarationOption, Options } from 'typedoc';
2+
3+
export function bind<K>(name: string):
4+
<IK extends PropertyKey>(target: ({ application: Application } | { options: Options }) & { [K2 in IK]: K }, key: IK) => void;
5+
export function bind<K>(name: DeclarationOption):
6+
<IK extends PropertyKey>(target: ({ application: Application } | { options: Options }) & { [K2 in IK]: K }, key: IK) => void;
7+
8+
export function bind<K>(option: string | DeclarationOption):
9+
<IK extends PropertyKey>(target: ({ application: Application } | { options: Options }) & { [K2 in IK]: K }, key: IK) => void {
10+
11+
if (typeof option === 'string') {
12+
return BindOption(option);
13+
}
14+
return BindOption(option.name);
15+
}

src/version-filter-plugin.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import { Context, Converter } from 'typedoc/dist/lib/converter';
2-
import { Component } from 'typedoc/dist/lib/output/components';
2+
import { DeclarationOption, ParameterType } from 'typedoc/dist/lib/utils/options/declaration';
33
import { ConverterComponent } from 'typedoc/dist/lib/converter/components';
4-
import { Option } from 'typedoc/dist/lib/utils';
5-
import { ParameterType } from 'typedoc/dist/lib/utils/options/declaration';
64
import { Reflection } from 'typedoc/dist/lib/models';
75
import Version from './util/version';
86
import VersionFilter from './convert/version-filter';
7+
import { bind } from './util/options';
8+
9+
const maxVersionOption = {
10+
name: 'maxVersion',
11+
type: ParameterType.String,
12+
help: 'The maxminum version number to include in the filter (compares against the `@since` tag)',
13+
} as DeclarationOption;
914

10-
@Component({ name: 'version-filter' })
1115
export class VersionFilterPlugin extends ConverterComponent {
12-
@Option({
13-
name: 'maxVersion',
14-
type: ParameterType.String,
15-
help: 'The maxminum version number to include in the filter (compares against the `@since` tag)',
16-
})
17-
private _maxVersion?: string;
16+
static options = [
17+
maxVersionOption,
18+
];
19+
20+
@bind(maxVersionOption)
21+
_maxVersion: string | undefined;
1822

1923
private _version?: Version;
2024
private _excluded?: Reflection[];

tests/cli-tests.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as path from 'path';
2+
import { DeclarationOption } from 'typedoc';
3+
import { execFile } from 'child_process';
4+
5+
const binFile = path.resolve(__dirname, '../bin/typedoc-declare');
6+
7+
function handleError(errorCode: number | undefined, stdout: string, stderr: string) {
8+
console.log(`exit code: ${errorCode}`);
9+
if (stdout) {
10+
console.log(`stdout: ${stdout}`);
11+
}
12+
if (stdout) {
13+
console.log(`stderr: ${stderr}`);
14+
}
15+
}
16+
17+
it('should render version information without error', (done) => {
18+
execFile(binFile, ['--version'], (err, stdout, stderr) => {
19+
if (err) {
20+
handleError(err.code, stdout, stderr);
21+
}
22+
expect(err).toBeNull();
23+
done();
24+
});
25+
});
26+
27+
it('should render options with help text', (done) => {
28+
execFile(binFile, ['--help'], (err, stdout, stderr) => {
29+
if (err) {
30+
handleError(err.code, stdout, stderr);
31+
}
32+
expect(err).toBeNull();
33+
34+
const plugin = require('../src/index');
35+
const options = plugin.options as DeclarationOption[];
36+
options.forEach(option => {
37+
expect(stdout).toContain(`--${option.name}`);
38+
});
39+
40+
done();
41+
});
42+
});
43+
44+
it('should fail with an unknown option', (done) => {
45+
execFile(binFile, ['--unkownoptionthatshouldntbedefined'], (err) => {
46+
expect(err).toBeTruthy();
47+
done();
48+
});
49+
});

tests/dynamic-tests.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3+
import { CallbackLogger, SourceFileMode } from 'typedoc/dist/lib/utils';
34
import ReflectionFormatter, { ReflectionSortFlags } from '../src/render/reflection-formatter';
45
import { Application } from 'typedoc/dist/lib/application';
5-
import { CallbackLogger } from 'typedoc/dist/lib/utils';
66
import KeyOfCommentResolver from '../src/convert/keyof-comment-resolver';
7-
import { SourceFileMode } from 'typedoc/dist/lib/converter/nodes/block';
7+
import { OmitTagsPlugin } from '../src/omit-tags-plugin';
88
import { TSConfigReader } from 'typedoc/dist/lib/utils/options/readers';
99
import { TypeDocAndTSOptions } from 'typedoc/dist/lib/utils/options/declaration';
1010
import Version from '../src/util/version';
1111
import VersionFilter from '../src/convert/version-filter';
1212
import glob from 'glob';
1313
import mkdir from 'make-dir';
14-
import { OmitTagsPlugin } from '../src/omit-tags-plugin';
1514

1615
const writeOutput = process.env['DEBUG_MODE'] !== 'none';
1716

@@ -32,7 +31,7 @@ function createApplication(logOutput: string[]) {
3231
const app = new Application();
3332
app.logger = new CallbackLogger((message: string) => { logOutput.push(message) });
3433

35-
app.options.addReader(new TSConfigReader())
34+
app.options.addReader(new TSConfigReader());
3635

3736
app.bootstrap(options);
3837

0 commit comments

Comments
 (0)