Skip to content

Commit 7cf73da

Browse files
committed
fix!: Programatic usage should be able to use option readers
Closes #1162
1 parent c6722d8 commit 7cf73da

File tree

10 files changed

+30
-12
lines changed

10 files changed

+30
-12
lines changed

bin/typedoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
22

3-
var td = require('../dist/lib/cli.js');
4-
new td.CliApplication();
3+
const td = require('../dist/lib/cli.js');
4+
const app = new td.CliApplication();
5+
app.bootstrap();

scripts/rebuild_specs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const path = require('path');
66
const TypeDoc = require('..');
77
const ts = require('typescript');
88

9-
const app = new TypeDoc.Application({
9+
const app = new TypeDoc.Application();
10+
app.bootstrap({
1011
mode: 'Modules',
1112
target: ts.ScriptTarget.ES5,
1213
module: ts.ModuleKind.CommonJS,

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export {
1818
ParameterHint,
1919
ParameterScope,
2020
ParameterType,
21-
TypeDocOptions
21+
TypeDocOptions,
22+
23+
TSConfigReader,
24+
TypeDocReader,
25+
ArgumentsReader
2226
} from './lib/utils/options';
2327

2428
export { JSONOutput } from './lib/serialization';

src/lib/application.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class Application extends ChildableComponent<
127127
*
128128
* @param options An object containing the options that should be used.
129129
*/
130-
constructor(options?: Partial<TypeDocAndTSOptions>) {
130+
constructor() {
131131
super(DUMMY_APPLICATION_OWNER);
132132

133133
this.logger = new ConsoleLogger();
@@ -137,24 +137,24 @@ export class Application extends ChildableComponent<
137137
this.converter = this.addComponent<Converter>('converter', Converter);
138138
this.renderer = this.addComponent<Renderer>('renderer', Renderer);
139139
this.plugins = this.addComponent('plugins', PluginHost);
140-
141-
this.bootstrap(options);
142140
}
143141

144142
/**
145143
* Initialize TypeDoc with the given options object.
146144
*
147145
* @param options The desired options to set.
148146
*/
149-
protected bootstrap(options: Partial<TypeDocAndTSOptions> = {}): { hasErrors: boolean, inputFiles: string[] } {
147+
bootstrap(options: Partial<TypeDocAndTSOptions> = {}): { hasErrors: boolean, inputFiles: string[] } {
150148
this.options.setValues(options); // Ignore result, plugins might declare an option
151149
this.options.read(new Logger());
152150

153151
const logger = this.loggerType;
154152
if (typeof logger === 'function') {
155153
this.logger = new CallbackLogger(<any> logger);
154+
this.options.setLogger(this.logger);
156155
} else if (logger === 'none') {
157156
this.logger = new Logger();
157+
this.options.setLogger(this.logger);
158158
}
159159

160160
this.plugins.load();

src/lib/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class CliApplication extends Application {
4949
/**
5050
* Run TypeDoc from the command line.
5151
*/
52-
protected bootstrap(options?: Partial<TypeDocAndTSOptions>) {
52+
bootstrap(options?: Partial<TypeDocAndTSOptions>) {
5353
this.options.addReader(new ArgumentsReader(0));
5454
this.options.addReader(new TypeDocReader());
5555
this.options.addReader(new TSConfigReader());

src/lib/utils/options/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { Options, OptionsReader } from './options';
22
export { Option } from './sources';
3+
export { ArgumentsReader, TypeDocReader, TSConfigReader } from './readers';
34
export { TypeDocOptions, ParameterType, ParameterHint, ParameterScope } from './declaration';

src/lib/utils/options/options.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ export class Options {
8787
this._logger = logger;
8888
}
8989

90+
/**
91+
* Sets the logger used when an option declaration fails to be added.
92+
* @param logger
93+
*/
94+
setLogger(logger: Logger) {
95+
this._logger = logger;
96+
}
97+
9098
/**
9199
* Adds the option declarations declared by TypeDoc's `@Option` decorator
92100
* and all supported TypeScript declarations.

src/test/converter.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { ScriptTarget, ModuleKind, JsxEmit } from 'typescript';
77

88
describe('Converter', function() {
99
const base = Path.join(__dirname, 'converter');
10-
const app = new Application({
10+
const app = new Application();
11+
app.bootstrap({
1112
mode: SourceFileMode.Modules,
1213
logger: 'none',
1314
target: ScriptTarget.ES5,

src/test/plugin-host.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ describe('PluginHost', function () {
1717
});
1818

1919
it('parses plugins correctly', function () {
20-
let app = new Application({
20+
const app = new Application();
21+
app.bootstrap({
2122
plugin: ['typedoc-plugin-1', 'typedoc-plugin-2']
2223
});
2324

src/test/renderer.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ describe('Renderer', function() {
5656
});
5757

5858
it('constructs', function() {
59-
app = new Application({
59+
app = new Application();
60+
app.bootstrap({
6061
mode: 'Modules',
6162
logger: 'console',
6263
target: ScriptTarget.ES5,

0 commit comments

Comments
 (0)