From 1598a9bbb1e15c58de04cc50ed24f3ee449d0395 Mon Sep 17 00:00:00 2001 From: "Alex.V" Date: Wed, 1 Jul 2020 11:28:14 +0200 Subject: [PATCH] fix(docs-gen): generation fixes --- .../src/resources/helpers/declaration-title.ts | 17 +++++++++++------ docs-gen/src/resources/helpers/member-title.ts | 8 ++++++-- .../src/resources/helpers/parameter-table.ts | 2 +- .../src/resources/helpers/signature-title.ts | 6 +++--- docs-gen/src/resources/helpers/type.ts | 7 ++++--- docs-gen/src/resources/partials/member.hbs | 2 ++ packages/cubejs-client-core/index.d.ts | 2 +- 7 files changed, 28 insertions(+), 16 deletions(-) diff --git a/docs-gen/src/resources/helpers/declaration-title.ts b/docs-gen/src/resources/helpers/declaration-title.ts index ca37d6aa6d894..7b859caa22b30 100644 --- a/docs-gen/src/resources/helpers/declaration-title.ts +++ b/docs-gen/src/resources/helpers/declaration-title.ts @@ -3,15 +3,20 @@ import { heading } from './heading'; import { memberSymbol } from './member-symbol'; import { type } from './type'; -export function declarationTitle(this: DeclarationReflection, showSymbol: boolean) { - if (this.type?.type !== 'union') { +export function declarationTitle(this: DeclarationReflection, showSymbol: boolean) { + if (this.type?.type !== 'union' && this.type?.type !== 'tuple' && this.kind !== ReflectionKind.EnumMember) { return ''; } const md = []; - const isOptional = this.flags.map(flag => flag).includes('Optional'); - - if (this.parent && this.parent.kind !== ReflectionKind.ObjectLiteral) { + const isOptional = this.flags.map((flag) => flag).includes('Optional'); + + if ( + this.parent && + this.parent.kind !== ReflectionKind.ObjectLiteral && + this.parent.kind !== ReflectionKind.Enum && + this.kind !== ReflectionKind.TypeAlias + ) { md.push(heading(3)); } @@ -27,6 +32,6 @@ export function declarationTitle(this: DeclarationReflection, showSymbol: boolea if (this.defaultValue) { md.push(`= ${this.defaultValue}`); } - + return md.join(' '); } diff --git a/docs-gen/src/resources/helpers/member-title.ts b/docs-gen/src/resources/helpers/member-title.ts index c03e09e9a91e5..56e8ab273695a 100644 --- a/docs-gen/src/resources/helpers/member-title.ts +++ b/docs-gen/src/resources/helpers/member-title.ts @@ -1,10 +1,14 @@ -import { DeclarationReflection } from 'typedoc'; +import { DeclarationReflection, ReflectionKind } from 'typedoc'; export function memberTitle(this: DeclarationReflection) { + if (this.parent?.kind === ReflectionKind.Enum) { + return ''; + } + const md = []; if (this.flags) { - md.push(this.flags.map(flag => `\`${flag}\``).join(' ')); + md.push(this.flags.map((flag) => `\`${flag}\``).join(' ')); } md.push(this.name); return md.join(' '); diff --git a/docs-gen/src/resources/helpers/parameter-table.ts b/docs-gen/src/resources/helpers/parameter-table.ts index 345f462db4600..2a8cc80210c96 100644 --- a/docs-gen/src/resources/helpers/parameter-table.ts +++ b/docs-gen/src/resources/helpers/parameter-table.ts @@ -28,7 +28,7 @@ export function parameterTable(this: ParameterReflection[]) { const typeOut = type.call(parameter.type); const row = [ - `\`${parameter.flags.isRest ? '...' : ''}${parameter.name}${isOptional ? '?' : ''}\``, + `${parameter.flags.isRest ? '...' : ''}${parameter.name}${isOptional ? '?' : ''}`, typeOut ? typeOut.toString().replace(/\|/g, '|') : '', ]; if (hasDefaultValues) { diff --git a/docs-gen/src/resources/helpers/signature-title.ts b/docs-gen/src/resources/helpers/signature-title.ts index 548d03700d030..1f725f54321fb 100644 --- a/docs-gen/src/resources/helpers/signature-title.ts +++ b/docs-gen/src/resources/helpers/signature-title.ts @@ -1,4 +1,4 @@ -import { SignatureReflection, ReflectionKind } from 'typedoc'; +import { SignatureReflection } from 'typedoc'; import { memberSymbol } from './member-symbol'; import { type } from './type'; @@ -27,11 +27,11 @@ export function signatureTitle(this: SignatureReflection, showSymbol: boolean) { if (param.flags.isRest) { paramsmd.push('...'); } - paramsmd.push(`\`${param.name}`); + paramsmd.push(`**${param.name}`); if (param.flags.isOptional) { paramsmd.push('?'); } - paramsmd.push(`\`: ${type.call(param.type)}`); + paramsmd.push(`**: ${type.call(param.type)}`); return paramsmd.join(''); }) .join(', ') diff --git a/docs-gen/src/resources/helpers/type.ts b/docs-gen/src/resources/helpers/type.ts index 5744761cbedf7..c571bc053411c 100644 --- a/docs-gen/src/resources/helpers/type.ts +++ b/docs-gen/src/resources/helpers/type.ts @@ -9,7 +9,7 @@ import { TypeOperatorType, UnionType, } from 'typedoc/dist/lib/models/types'; -import { dasherize, underscore } from 'inflection'; +import { dasherize, underscore, camelize } from 'inflection'; import MarkdownTheme from '../../theme'; @@ -59,9 +59,10 @@ export function type( return this; } - function anchorName(link) { - return '#' + dasherize(underscore(link.replace(/#/g, '-'))); + return ( + '#' + dasherize(underscore(link.replace(/[A-Z]{2,}(?=[A-Z])/, (v) => camelize(v.toLowerCase())).replace(/#/g, '-'))) + ); } function getReferenceType(model: ReferenceType) { diff --git a/docs-gen/src/resources/partials/member.hbs b/docs-gen/src/resources/partials/member.hbs index aa03b3381855b..575b6dea6ca97 100644 --- a/docs-gen/src/resources/partials/member.hbs +++ b/docs-gen/src/resources/partials/member.hbs @@ -7,7 +7,9 @@ {{else}} +{{#if memberTitle}} {{heading 3}} {{{ memberTitle }}} +{{/if}} {{/ifParentIsModule}} diff --git a/packages/cubejs-client-core/index.d.ts b/packages/cubejs-client-core/index.d.ts index a3af6e92e91f0..411e3cd45f522 100644 --- a/packages/cubejs-client-core/index.d.ts +++ b/packages/cubejs-client-core/index.d.ts @@ -218,7 +218,7 @@ declare module '@cubejs-client/core' { static getNormalizedPivotConfig(query: Query, pivotConfig?: Partial): PivotConfig; /** - * Creates new instance of ResultSet based on [LoadResponse](#load-response) data. + * Creates a new instance of ResultSet based on [LoadResponse](#load-response) data. * * ```js * import cubejs, { ResultSet } from '@cubejs-client/core';