Skip to content

Commit

Permalink
feat: Add @BindOption
Browse files Browse the repository at this point in the history
Closes #1165
  • Loading branch information
Gerrit0 committed Jan 14, 2020
1 parent d613616 commit ef0c17e
Show file tree
Hide file tree
Showing 23 changed files with 320 additions and 261 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Expand Up @@ -17,7 +17,8 @@ export {
} from './lib/converter';

export {
Option,
Option, // deprecated
BindOption,
Options,
OptionsReader,
ParameterHint,
Expand Down
44 changes: 7 additions & 37 deletions src/lib/application.ts
Expand Up @@ -23,8 +23,7 @@ import {
Component,
DUMMY_APPLICATION_OWNER
} from './utils/component';
import { Option, Options, ParameterType } from './utils';
import { ParameterHint } from './utils/options';
import { Options, BindOption } from './utils';
import { TypeDocAndTSOptions } from './utils/options/declaration';
import { addDecoratedOptions } from './utils/options/sources';

Expand Down Expand Up @@ -71,51 +70,22 @@ export class Application extends ChildableComponent<

plugins: PluginHost;

@Option({
name: 'logger',
help: "Specify the logger that should be used, 'none' or 'console'",
defaultValue: 'console',
type: ParameterType.Mixed
})
@BindOption('logger')
loggerType!: string | Function;

@Option({
name: 'ignoreCompilerErrors',
help: 'Should TypeDoc generate documentation pages even after the compiler has returned errors?',
type: ParameterType.Boolean
})
@BindOption('ignoreCompilerErrors')
ignoreCompilerErrors!: boolean;

@Option({
name: 'exclude',
help: 'Define patterns for excluded files when specifying paths.',
type: ParameterType.Array
})
@BindOption('exclude')
exclude!: Array<string>;

@Option({
name: 'inputFiles',
help: 'The initial input files to expand and then pass to TS.',
type: ParameterType.Array
})
@BindOption('inputFiles')
inputFiles!: string[];

@Option({
name: 'options',
help: "Specify a json option file that should be loaded. If not specified TypeDoc will look for 'typedoc.json' in the current directory.",
type: ParameterType.String,
hint: ParameterHint.File,
defaultValue: process.cwd()
})
@BindOption('options')
optionsFile!: string;

@Option({
name: 'tsconfig',
help: "Specify a typescript config file that should be loaded. If not specified TypeDoc will look for 'tsconfig.json' in the current directory.",
type: ParameterType.String,
hint: ParameterHint.File,
defaultValue: process.cwd()
})
@BindOption('tsconfig')
project!: string;

/**
Expand Down
28 changes: 5 additions & 23 deletions src/lib/cli.ts
@@ -1,7 +1,7 @@
import * as typescript from 'typescript';

import { Application } from './application';
import { Option, ParameterHint, ParameterType } from './utils/options';
import { BindOption } from './utils/options';
import { getOptionsHelp } from './utils/options/help';
import { ArgumentsReader, TypeDocReader } from './utils/options/readers';
import { TSConfigReader } from './utils/options/readers/tsconfig';
Expand All @@ -16,34 +16,16 @@ export const enum ExitCode {
}

export class CliApplication extends Application {
@Option({
name: 'out',
help: 'Specifies the location the documentation should be written to.',
hint: ParameterHint.Directory
})
@BindOption('out')
out!: string;

@Option({
name: 'json',
help: 'Specifies the location and file name a json file describing the project is written to.',
hint: ParameterHint.File
})
@BindOption('json')
json!: string;

@Option({
name: 'version',
short: 'v',
help: 'Print the TypeDoc\'s version.',
type: ParameterType.Boolean
})
@BindOption('version')
version!: boolean;

@Option({
name: 'help',
short: 'h',
help: 'Print this message.',
type: ParameterType.Boolean
})
@BindOption('help')
help!: boolean;

/**
Expand Down
44 changes: 8 additions & 36 deletions src/lib/converter/converter.ts
Expand Up @@ -3,12 +3,11 @@ import * as _ts from '../ts-internal';
import * as _ from 'lodash';

import { Application } from '../application';
import { ParameterType } from '../utils/options/declaration';
import { Reflection, Type, ProjectReflection } from '../models/index';
import { Context } from './context';
import { ConverterComponent, ConverterNodeComponent, ConverterTypeComponent, TypeTypeConverter, TypeNodeConverter } from './components';
import { Component, ChildableComponent, ComponentClass } from '../utils/component';
import { Option } from '../utils';
import { BindOption } from '../utils';
import { normalizePath } from '../utils/fs';
import { createMinimatch } from '../utils/paths';

Expand All @@ -35,52 +34,25 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
/**
* 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.'
})
@BindOption('name')
name!: string;

@Option({
name: 'externalPattern',
help: 'Define patterns for files that should be considered being external.',
type: ParameterType.Array
})
@BindOption('externalPattern')
externalPattern!: Array<string>;

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

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

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

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

@Option({
name: 'excludeProtected',
help: 'Ignores protected variables and methods',
type: ParameterType.Boolean
})
@BindOption('excludeProtected')
excludeProtected!: boolean;

/**
Expand Down
13 changes: 2 additions & 11 deletions src/lib/converter/nodes/block.ts
Expand Up @@ -4,7 +4,7 @@ import { Reflection, ReflectionKind, ReflectionFlag } from '../../models/index';
import { createDeclaration } from '../factories/index';
import { Context } from '../context';
import { Component, ConverterNodeComponent } from '../components';
import { Option, ParameterType } from '../../utils';
import { BindOption } from '../../utils';

const preferred: ts.SyntaxKind[] = [
ts.SyntaxKind.ClassDeclaration,
Expand All @@ -18,16 +18,7 @@ export enum SourceFileMode {

@Component({name: 'node:block'})
export class BlockConverter extends ConverterNodeComponent<ts.SourceFile|ts.Block|ts.ModuleBlock> {
@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
})
@BindOption('mode')
mode!: SourceFileMode;

/**
Expand Down
22 changes: 4 additions & 18 deletions src/lib/converter/plugins/CategoryPlugin.ts
Expand Up @@ -3,7 +3,7 @@ import { ReflectionCategory } from '../../models/ReflectionCategory';
import { Component, ConverterComponent } from '../components';
import { Converter } from '../converter';
import { Context } from '../context';
import { ParameterType, Option } from '../../utils';
import { BindOption } from '../../utils';
import { Comment } from '../../models/comments/index';

/**
Expand All @@ -13,27 +13,13 @@ import { Comment } from '../../models/comments/index';
*/
@Component({name: 'category'})
export class CategoryPlugin extends ConverterComponent {
@Option({
name: 'defaultCategory',
help: 'Specifies the default category for reflections without a category.',
type: ParameterType.String,
defaultValue: 'Other'
})
@BindOption('defaultCategory')
defaultCategory!: string;

@Option({
name: 'categoryOrder',
help: 'Specifies the order in which categories appear. * indicates the relative order for categories not in the list.',
type: ParameterType.Array
})
@BindOption('categoryOrder')
categoryOrder!: string[];

@Option({
name: 'categorizeByGroup',
help: 'Specifies whether categorization will be done at the group level.',
type: ParameterType.Boolean,
defaultValue: true
})
@BindOption('categorizeByGroup')
categorizeByGroup!: boolean;

// For use in static methods
Expand Down
10 changes: 3 additions & 7 deletions src/lib/converter/plugins/GitHubPlugin.ts
Expand Up @@ -6,7 +6,7 @@ import { Component, ConverterComponent } from '../components';
import { BasePath } from '../utils/base-path';
import { Converter } from '../converter';
import { Context } from '../context';
import { Option, ParameterType } from '../../utils';
import { BindOption } from '../../utils';

/**
* Stores data of a repository.
Expand All @@ -28,7 +28,7 @@ export class Repository {
files: string[] = [];

/**
* The user/organisation name of this repository on GitHub.
* The user/organization name of this repository on GitHub.
*/
gitHubUser?: string;

Expand Down Expand Up @@ -162,11 +162,7 @@ export class GitHubPlugin extends ConverterComponent {
*/
private ignoredPaths: string[] = [];

@Option({
name: 'gitRevision',
help: 'Use specified revision instead of the last revision for linking to GitHub source files.',
type: ParameterType.String
})
@BindOption('gitRevision')
gitRevision!: string;

/**
Expand Down
7 changes: 2 additions & 5 deletions src/lib/converter/plugins/PackagePlugin.ts
Expand Up @@ -6,7 +6,7 @@ import { Reflection } from '../../models/reflections/abstract';
import { Component, ConverterComponent } from '../components';
import { Converter } from '../converter';
import { Context } from '../context';
import { Option } from '../../utils';
import { BindOption } from '../../utils';

/**
* A handler that tries to find the package.json and readme.md files of the
Expand All @@ -18,10 +18,7 @@ import { Option } from '../../utils';
*/
@Component({name: 'package'})
export class PackagePlugin extends ConverterComponent {
@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.'
})
@BindOption('readme')
readme!: string;

/**
Expand Down
8 changes: 2 additions & 6 deletions src/lib/output/plugins/MarkedLinksPlugin.ts
Expand Up @@ -3,7 +3,7 @@ import * as Util from 'util';
import { Reflection } from '../../models/reflections/abstract';
import { Component, ContextAwareRendererComponent } from '../components';
import { MarkdownEvent, RendererEvent } from '../events';
import { ParameterType, Option } from '../../utils';
import { BindOption } from '../../utils';

/**
* A plugin that builds links in markdown texts.
Expand All @@ -20,11 +20,7 @@ export class MarkedLinksPlugin extends ContextAwareRendererComponent {
*/
private inlineTag: RegExp = /(?:\[(.+?)\])?\{@(link|linkcode|linkplain)\s+((?:.|\n)+?)\}/gi;

@Option({
name: 'listInvalidSymbolLinks',
help: 'Emits a list of broken symbol [[navigation]] links after documentation generation',
type: ParameterType.Boolean
})
@BindOption('listInvalidSymbolLinks')
listInvalidSymbolLinks!: boolean;

private warnings: string[] = [];
Expand Down
18 changes: 5 additions & 13 deletions src/lib/output/plugins/MarkedPlugin.ts
Expand Up @@ -6,7 +6,7 @@ import * as Handlebars from 'handlebars';

import { Component, ContextAwareRendererComponent } from '../components';
import { RendererEvent, MarkdownEvent } from '../events';
import { Option, ParameterHint } from '../../utils';
import { BindOption } from '../../utils';

const customMarkedRenderer = new Marked.Renderer();

Expand Down Expand Up @@ -52,18 +52,10 @@ customMarkedRenderer.heading = (text, level, _, slugger) => {
*/
@Component({name: 'marked'})
export class MarkedPlugin extends ContextAwareRendererComponent {
@Option({
name: 'includes',
help: 'Specifies the location to look for included documents (use [[include:FILENAME]] in comments).',
hint: ParameterHint.Directory
})
@BindOption('includes')
includeSource!: string;

@Option({
name: 'media',
help: 'Specifies the location with media files that should be copied to the output directory.',
hint: ParameterHint.Directory
})
@BindOption('media')
mediaSource!: string;

/**
Expand Down Expand Up @@ -104,9 +96,9 @@ export class MarkedPlugin extends ContextAwareRendererComponent {
}

/**
* Highlight the synatx of the given text using HighlightJS.
* Highlight the syntax of the given text using HighlightJS.
*
* @param text The text taht should be highlightes.
* @param text The text that should be highlighted.
* @param lang The language that should be used to highlight the string.
* @return A html string with syntax highlighting.
*/
Expand Down

0 comments on commit ef0c17e

Please sign in to comment.