diff --git a/scripts/rebuild_specs.js b/scripts/rebuild_specs.js index 4bb90ea64..2848d1cc7 100644 --- a/scripts/rebuild_specs.js +++ b/scripts/rebuild_specs.js @@ -42,6 +42,10 @@ const conversions = [ () => app.options.setValue('categorizeByGroup', false), () => app.options.setValue('categorizeByGroup', true) ], + ['specs.lib', + () => app.options.setValue('mode', 'library'), + () => app.options.setValue('mode', 'modules'), + ] ]; /** diff --git a/src/lib/converter/converter.ts b/src/lib/converter/converter.ts index e65ca05c2..a248e7fe7 100644 --- a/src/lib/converter/converter.ts +++ b/src/lib/converter/converter.ts @@ -7,7 +7,7 @@ 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 { BindOption } from '../utils'; +import { BindOption, SourceFileMode } from '../utils'; import { normalizePath } from '../utils/fs'; import { createMinimatch } from '../utils/paths'; @@ -366,9 +366,20 @@ export class Converter extends ChildableComponent !isExcluded(file)); const isRelevantError = ({ file }: ts.Diagnostic) => !file || includedSourceFiles.includes(file); - includedSourceFiles.forEach((sourceFile) => { - this.convertNode(context, sourceFile); - }); + if (this.application.options.getValue('mode') === SourceFileMode.Library) { + for (const fileName of context.fileNames) { + const sourceFile = includedSourceFiles.find(file => fileName === file.fileName); + if (sourceFile) { + this.convertNode(context, sourceFile); + } else { + this.application.logger.warn(`Failed to find source file of entry point ${fileName}`); + } + } + } else { + includedSourceFiles.forEach((sourceFile) => { + this.convertNode(context, sourceFile); + }); + } if (this.application.ignoreCompilerErrors) { return []; diff --git a/src/lib/converter/factories/declaration.ts b/src/lib/converter/factories/declaration.ts index 5ec62f8e4..008a39537 100644 --- a/src/lib/converter/factories/declaration.ts +++ b/src/lib/converter/factories/declaration.ts @@ -11,7 +11,7 @@ import { createReferenceType } from './reference'; const nonStaticKinds = [ ReflectionKind.Class, ReflectionKind.Interface, - ReflectionKind.Module + ReflectionKind.Namespace ]; /** @@ -71,12 +71,12 @@ export function createDeclaration(context: Context, node: ts.Declaration, kind: // Test whether the node is exported let isExported: boolean; - if (kind === ReflectionKind.ExternalModule || kind === ReflectionKind.Global) { + if (kind === ReflectionKind.Module || kind === ReflectionKind.Global) { isExported = true; } else if (container.kind === ReflectionKind.Global) { // In file mode, everything is exported. isExported = true; - } else if (container.kindOf([ReflectionKind.Module, ReflectionKind.ExternalModule])) { + } else if (container.kindOf([ReflectionKind.Namespace, ReflectionKind.Module])) { const symbol = context.getSymbolAtLocation(node); if (!symbol) { isExported = false; @@ -213,7 +213,7 @@ function canMergeReflectionsByKind(kind1: ReflectionKind, kind2: ReflectionKind) */ function mergeDeclarations(context: Context, reflection: DeclarationReflection, node: ts.Node, kind: ReflectionKind) { if (reflection.kind !== kind) { - const weights = [ReflectionKind.Module, ReflectionKind.Enum, ReflectionKind.Class]; + const weights = [ReflectionKind.Namespace, ReflectionKind.Enum, ReflectionKind.Class]; const kindWeight = weights.indexOf(kind); const childKindWeight = weights.indexOf(reflection.kind); if (kindWeight > childKindWeight) { diff --git a/src/lib/converter/nodes/block.ts b/src/lib/converter/nodes/block.ts index bd3581b75..c744ce2e7 100644 --- a/src/lib/converter/nodes/block.ts +++ b/src/lib/converter/nodes/block.ts @@ -55,11 +55,17 @@ export class BlockConverter extends ConverterNodeComponent { if (this.mode === SourceFileMode.Modules) { - result = createDeclaration(context, node, ReflectionKind.ExternalModule, node.fileName); + result = createDeclaration(context, node, ReflectionKind.Module, node.fileName); context.withScope(result, () => { this.convertStatements(context, node); result!.setFlag(ReflectionFlag.Exported); }); + } else if (this.mode === SourceFileMode.Library) { + result = createDeclaration(context, node, ReflectionKind.Module, node.fileName); + context.withScope(result, () => { + this.convertVisibleDeclarations(context, node); + result!.setFlag(ReflectionFlag.Exported); + }); } else { this.convertStatements(context, node); } @@ -85,4 +91,18 @@ export class BlockConverter extends ConverterNodeComponent context.scope - : createDeclaration(context, node, ReflectionKind.Module); + : createDeclaration(context, node, ReflectionKind.Namespace); context.withScope(reflection, () => { if (node.body) { this.owner.convertNode(context, node.body); diff --git a/src/lib/converter/plugins/CommentPlugin.ts b/src/lib/converter/plugins/CommentPlugin.ts index 1e86d2435..c77af3eb9 100644 --- a/src/lib/converter/plugins/CommentPlugin.ts +++ b/src/lib/converter/plugins/CommentPlugin.ts @@ -111,7 +111,7 @@ export class CommentPlugin extends ConverterComponent { CommentPlugin.removeTags(comment, 'event'); } - if (reflection.kindOf(ReflectionKind.ExternalModule)) { + if (reflection.kindOf(ReflectionKind.Module)) { CommentPlugin.removeTags(comment, 'packagedocumentation'); } } @@ -172,7 +172,7 @@ export class CommentPlugin extends ConverterComponent { if (reflection.kindOf(ReflectionKind.FunctionOrMethod) || (reflection.kindOf(ReflectionKind.Event) && reflection['signatures'])) { const comment = parseComment(rawComment, reflection.comment); this.applyModifiers(reflection, comment); - } else if (reflection.kindOf(ReflectionKind.Module)) { + } else if (reflection.kindOf(ReflectionKind.Namespace)) { this.storeModuleComment(rawComment, reflection); } else { const comment = parseComment(rawComment, reflection.comment); diff --git a/src/lib/converter/plugins/DynamicModulePlugin.ts b/src/lib/converter/plugins/DynamicModulePlugin.ts index d89080aaa..07a3ca8b6 100644 --- a/src/lib/converter/plugins/DynamicModulePlugin.ts +++ b/src/lib/converter/plugins/DynamicModulePlugin.ts @@ -52,7 +52,7 @@ export class DynamicModulePlugin extends ConverterComponent { * @param node The node that is currently processed if available. */ private onDeclaration(context: Context, reflection: Reflection, node?: ts.Node) { - if (reflection.kindOf(ReflectionKind.ExternalModule)) { + if (reflection.kindOf(ReflectionKind.Module)) { let name = reflection.name; if (!name.includes('/')) { return; diff --git a/src/lib/converter/plugins/GroupPlugin.ts b/src/lib/converter/plugins/GroupPlugin.ts index 80e634d36..97e21e2e3 100644 --- a/src/lib/converter/plugins/GroupPlugin.ts +++ b/src/lib/converter/plugins/GroupPlugin.ts @@ -17,8 +17,8 @@ export class GroupPlugin extends ConverterComponent { */ static WEIGHTS = [ ReflectionKind.Global, - ReflectionKind.ExternalModule, ReflectionKind.Module, + ReflectionKind.Namespace, ReflectionKind.Enum, ReflectionKind.EnumMember, ReflectionKind.Class, diff --git a/src/lib/models/reflections/abstract.ts b/src/lib/models/reflections/abstract.ts index 162097aa9..0aff71480 100644 --- a/src/lib/models/reflections/abstract.ts +++ b/src/lib/models/reflections/abstract.ts @@ -36,8 +36,8 @@ export function resetReflectionID() { */ export enum ReflectionKind { Global = 0, - ExternalModule = 1 << 0, - Module = 1 << 1, + Module = 1 << 0, + Namespace = 1 << 1, Enum = 1 << 2, EnumMember = 1 << 4, Variable = 1 << 5, @@ -66,7 +66,7 @@ export enum ReflectionKind { FunctionOrMethod = ReflectionKind.Function | Method, ClassMember = Accessor | Constructor | Method | Property | Event, SomeSignature = CallSignature | IndexSignature | ConstructorSignature | GetSignature | SetSignature, - SomeModule = Module | ExternalModule, + SomeModule = Namespace | Module, SomeType = Interface | TypeLiteral | TypeParameter | TypeAlias, SomeValue = Variable | Function | ObjectLiteral } diff --git a/src/lib/output/themes/DefaultTheme.ts b/src/lib/output/themes/DefaultTheme.ts index e79ff3cf5..e9703ce2e 100644 --- a/src/lib/output/themes/DefaultTheme.ts +++ b/src/lib/output/themes/DefaultTheme.ts @@ -61,7 +61,7 @@ export class DefaultTheme extends Theme { directory: 'enums', template: 'reflection.hbs' }, { - kind: [ReflectionKind.Module, ReflectionKind.ExternalModule], + kind: [ReflectionKind.Namespace, ReflectionKind.Module], isLeaf: false, directory: 'modules', template: 'reflection.hbs' @@ -375,7 +375,7 @@ export class NavigationBuilder { let target = someModule.parent; let inScope = (someModule === this.entryPoint); while (target) { - if (target.kindOf(ReflectionKind.ExternalModule)) { + if (target.kindOf(ReflectionKind.Module)) { return; } if (this.entryPoint === target) { diff --git a/src/lib/utils/options/declaration.ts b/src/lib/utils/options/declaration.ts index 54bd493f4..0cad9dd1d 100644 --- a/src/lib/utils/options/declaration.ts +++ b/src/lib/utils/options/declaration.ts @@ -31,7 +31,7 @@ export type TypeDocAndTSOptions = TypeDocOptions & Pick, IgnoredTsOptionKeys>>; export enum SourceFileMode { - File, Modules + File, Modules, Library } /** @@ -43,7 +43,7 @@ export interface TypeDocOptionMap { tsconfig: string; inputFiles: string[]; - mode: { file: SourceFileMode.File, modules: SourceFileMode.Modules }; + mode: { file: SourceFileMode.File, modules: SourceFileMode.Modules, library: SourceFileMode.Library }; includeDeclarations: boolean; entryPoint: string; exclude: string[]; diff --git a/src/lib/utils/options/sources/typedoc.ts b/src/lib/utils/options/sources/typedoc.ts index 175b209be..1d74a86b3 100644 --- a/src/lib/utils/options/sources/typedoc.ts +++ b/src/lib/utils/options/sources/typedoc.ts @@ -26,8 +26,9 @@ export function addTypeDocOptions(options: Options) { 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 + file: SourceFileMode.File, + modules: SourceFileMode.Modules, + library: SourceFileMode.Library }, defaultValue: SourceFileMode.Modules }); diff --git a/src/test/converter.test.ts b/src/test/converter.test.ts index dac3ecd62..c368ed655 100644 --- a/src/test/converter.test.ts +++ b/src/test/converter.test.ts @@ -35,6 +35,10 @@ describe('Converter', function() { ['specs-with-lump-categories', () => app.options.setValue('categorizeByGroup', false), () => app.options.setValue('categorizeByGroup', true) + ], + ['specs.lib', + () => app.options.setValue('mode', 'library'), + () => app.options.setValue('mode', 'modules') ] ];