Skip to content

Commit

Permalink
fix!: Programatic usage should be able to use option readers
Browse files Browse the repository at this point in the history
Closes #1162
  • Loading branch information
Gerrit0 committed Jan 12, 2020
1 parent c6722d8 commit 7cf73da
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 12 deletions.
5 changes: 3 additions & 2 deletions bin/typedoc
@@ -1,4 +1,5 @@
#!/usr/bin/env node

var td = require('../dist/lib/cli.js');
new td.CliApplication();
const td = require('../dist/lib/cli.js');
const app = new td.CliApplication();
app.bootstrap();
3 changes: 2 additions & 1 deletion scripts/rebuild_specs.js
Expand Up @@ -6,7 +6,8 @@ const path = require('path');
const TypeDoc = require('..');
const ts = require('typescript');

const app = new TypeDoc.Application({
const app = new TypeDoc.Application();
app.bootstrap({
mode: 'Modules',
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS,
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Expand Up @@ -18,7 +18,11 @@ export {
ParameterHint,
ParameterScope,
ParameterType,
TypeDocOptions
TypeDocOptions,

TSConfigReader,
TypeDocReader,
ArgumentsReader
} from './lib/utils/options';

export { JSONOutput } from './lib/serialization';
8 changes: 4 additions & 4 deletions src/lib/application.ts
Expand Up @@ -127,7 +127,7 @@ export class Application extends ChildableComponent<
*
* @param options An object containing the options that should be used.
*/
constructor(options?: Partial<TypeDocAndTSOptions>) {
constructor() {
super(DUMMY_APPLICATION_OWNER);

this.logger = new ConsoleLogger();
Expand All @@ -137,24 +137,24 @@ export class Application extends ChildableComponent<
this.converter = this.addComponent<Converter>('converter', Converter);
this.renderer = this.addComponent<Renderer>('renderer', Renderer);
this.plugins = this.addComponent('plugins', PluginHost);

this.bootstrap(options);
}

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

const logger = this.loggerType;
if (typeof logger === 'function') {
this.logger = new CallbackLogger(<any> logger);
this.options.setLogger(this.logger);
} else if (logger === 'none') {
this.logger = new Logger();
this.options.setLogger(this.logger);
}

this.plugins.load();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/cli.ts
Expand Up @@ -49,7 +49,7 @@ export class CliApplication extends Application {
/**
* Run TypeDoc from the command line.
*/
protected bootstrap(options?: Partial<TypeDocAndTSOptions>) {
bootstrap(options?: Partial<TypeDocAndTSOptions>) {
this.options.addReader(new ArgumentsReader(0));
this.options.addReader(new TypeDocReader());
this.options.addReader(new TSConfigReader());
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils/options/index.ts
@@ -1,3 +1,4 @@
export { Options, OptionsReader } from './options';
export { Option } from './sources';
export { ArgumentsReader, TypeDocReader, TSConfigReader } from './readers';
export { TypeDocOptions, ParameterType, ParameterHint, ParameterScope } from './declaration';
8 changes: 8 additions & 0 deletions src/lib/utils/options/options.ts
Expand Up @@ -87,6 +87,14 @@ export class Options {
this._logger = logger;
}

/**
* Sets the logger used when an option declaration fails to be added.
* @param logger
*/
setLogger(logger: Logger) {
this._logger = logger;
}

/**
* Adds the option declarations declared by TypeDoc's `@Option` decorator
* and all supported TypeScript declarations.
Expand Down
3 changes: 2 additions & 1 deletion src/test/converter.test.ts
Expand Up @@ -7,7 +7,8 @@ import { ScriptTarget, ModuleKind, JsxEmit } from 'typescript';

describe('Converter', function() {
const base = Path.join(__dirname, 'converter');
const app = new Application({
const app = new Application();
app.bootstrap({
mode: SourceFileMode.Modules,
logger: 'none',
target: ScriptTarget.ES5,
Expand Down
3 changes: 2 additions & 1 deletion src/test/plugin-host.test.ts
Expand Up @@ -17,7 +17,8 @@ describe('PluginHost', function () {
});

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

Expand Down
3 changes: 2 additions & 1 deletion src/test/renderer.test.ts
Expand Up @@ -56,7 +56,8 @@ describe('Renderer', function() {
});

it('constructs', function() {
app = new Application({
app = new Application();
app.bootstrap({
mode: 'Modules',
logger: 'console',
target: ScriptTarget.ES5,
Expand Down

0 comments on commit 7cf73da

Please sign in to comment.