Skip to content

Decouple converter for stand-alone use #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 78 additions & 3 deletions src/lib/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as FS from 'fs';
import * as typescript from 'typescript';
import {Minimatch, IMinimatch} from 'minimatch';

import {Converter} from './converter/index';
import {Converter, SourceFileMode} from './converter/index';
import {Renderer} from './output/renderer';
import {ProjectReflection} from './models/index';
import {Logger, ConsoleLogger, CallbackLogger, PluginHost, writeFile} from './utils/index';
Expand Down Expand Up @@ -77,6 +77,67 @@ export class Application extends ChildableComponent<Application, AbstractCompone
})
exclude: string;

/**
* The human readable name of the project. Used within the templates to set the title of the document.
*/
@Option({
name: 'name',
help: 'Set the name of the project that will be used in the header of the template.'
})
name: string;

@Option({
name: 'externalPattern',
help: 'Define a pattern for files that should be considered being external.'
})
externalPattern: string;

@Option({
name: 'includeDeclarations',
help: 'Turn on parsing of .d.ts declaration files.',
type: ParameterType.Boolean
})
includeDeclarations: boolean;

@Option({
name: 'excludeExternals',
help: 'Prevent externally resolved TypeScript files from being documented.',
type: ParameterType.Boolean
})
excludeExternals: boolean;

@Option({
name: 'excludeNotExported',
help: 'Prevent symbols that are not exported from being documented.',
type: ParameterType.Boolean
})
excludeNotExported: boolean;

@Option({
name: 'excludePrivate',
help: 'Ignores private variables and methods',
type: ParameterType.Boolean
})
excludePrivate: boolean;

@Option({
name: 'mode',
help: "Specifies the output mode the project is used to be compiled with: 'file' or 'modules'",
type: ParameterType.Map,
map: {
'file': SourceFileMode.File,
'modules': SourceFileMode.Modules
},
defaultValue: SourceFileMode.Modules
})
mode: SourceFileMode;

@Option({
name: 'readme',
help: 'Path to the readme file that should be displayed on the index page. Pass `none` to disable the index page and start the documentation on the globals page.'
})
readme: string;

/**
* The version number of TypeDoc.
*/
Expand All @@ -91,7 +152,6 @@ export class Application extends ChildableComponent<Application, AbstractCompone
super(null);

this.logger = new ConsoleLogger();
this.converter = this.addComponent('converter', Converter);
this.renderer = this.addComponent('renderer', Renderer);
this.plugins = this.addComponent('plugins', PluginHost);
this.options = this.addComponent('options', Options);
Expand All @@ -115,7 +175,22 @@ export class Application extends ChildableComponent<Application, AbstractCompone
}

this.plugins.load();
return this.options.read(options, OptionsReadMode.Fetch);

const readResult = this.options.read(options, OptionsReadMode.Fetch);

this.converter = new Converter({
compilerOptions: this.options.getCompilerOptions(),
name: this.name,
excludeExternals: this.excludeExternals,
excludeNotExported: this.excludeNotExported,
excludePrivate: this.excludePrivate,
externalPattern: this.externalPattern,
includeDeclarations: this.includeDeclarations,
mode: this.mode,
readme: this.readme
});

return readResult;
}

/**
Expand Down
55 changes: 0 additions & 55 deletions src/lib/converter/components.ts

This file was deleted.

18 changes: 9 additions & 9 deletions src/lib/converter/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ts from 'typescript';
import {Minimatch, IMinimatch} from 'minimatch';

import {Logger} from '../utils/loggers';
// import {Logger} from '../utils/loggers';
import {Reflection, ProjectReflection, ContainerReflection, Type} from '../models/index';
import {createTypeParameter} from './factories/type-parameter';
import {Converter} from './converter';
Expand Down Expand Up @@ -109,20 +109,20 @@ export class Context {
this.program = program;
this.visitStack = [];

const project = new ProjectReflection(converter.name);
const project = new ProjectReflection(converter.options.name);
this.project = project;
this.scope = project;

if (converter.externalPattern) {
this.externalPattern = new Minimatch(converter.externalPattern);
if (converter.options.externalPattern) {
this.externalPattern = new Minimatch(converter.options.externalPattern);
}
}

/**
* Return the compiler options.
*/
getCompilerOptions(): ts.CompilerOptions {
return this.converter.application.options.getCompilerOptions();
return this.converter.options.compilerOptions;
}

/**
Expand Down Expand Up @@ -154,9 +154,9 @@ export class Context {
*
* @returns The current logger instance.
*/
getLogger(): Logger {
/*getLogger(): Logger {
return this.converter.application.logger;
}
}*/

/**
* Return the symbol id of the given symbol.
Expand Down Expand Up @@ -222,15 +222,15 @@ export class Context {
isExternal = isExternal || externalPattern.match(node.fileName);
}

if (isExternal && this.converter.excludeExternals) {
if (isExternal && this.converter.options.excludeExternals) {
return;
}

let isDeclaration = node.isDeclarationFile;
if (isDeclaration) {
const lib = this.converter.getDefaultLib();
const isLib = node.fileName.substr(-lib.length) === lib;
if (!this.converter.includeDeclarations || isLib) {
if (!this.converter.options.includeDeclarations || isLib) {
return;
}
}
Expand Down
Loading