Skip to content

Commit

Permalink
docs: ng19 typedoc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
droshev committed Dec 29, 2024
1 parent d5ed28f commit c752ea3
Show file tree
Hide file tree
Showing 19 changed files with 1,362 additions and 766 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@
"types": "prefer-import"
}
],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unified-signatures": "error",
"arrow-body-style": "error",
"arrow-parens": ["off", "always"],
Expand Down
3 changes: 2 additions & 1 deletion libs/core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"compile-typedoc": {
"executor": "@fundamental-ngx/nx-plugin:compile-typedoc",
"options": {
"outputPath": "libs/docs/typedoc/core"
"outputPath": "libs/docs/typedoc/core",
"tsConfig": "libs/core/tsconfig.typedoc.json"
},
"outputs": ["{options.outputPath}"]
},
Expand Down
3 changes: 3 additions & 0 deletions libs/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.typedoc.json"
},
{
"path": "./tsconfig.lib.json"
},
Expand Down
21 changes: 21 additions & 0 deletions libs/core/tsconfig.typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"target": "ES2022",
"declaration": true,
"declarationMap": true,
"types": [],
"lib": ["dom", "es2018"],
"useDefineForClassFields": false,
"jsx": "react",
"jsxFactory": "JSX.createElement",
"jsxFragmentFactory": "JSX.Fragment"
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"files": ["./index.ts"]
}
3 changes: 2 additions & 1 deletion libs/cx/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"compile-typedoc": {
"executor": "@fundamental-ngx/nx-plugin:compile-typedoc",
"options": {
"outputPath": "libs/docs/typedoc/cx"
"outputPath": "libs/docs/typedoc/cx",
"tsConfig": "libs/cx/tsconfig.typedoc.json"
},
"outputs": ["{options.outputPath}"]
},
Expand Down
3 changes: 3 additions & 0 deletions libs/cx/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.typedoc.json"
},
{
"path": "./tsconfig.lib.json"
},
Expand Down
21 changes: 21 additions & 0 deletions libs/cx/tsconfig.typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"target": "ES2022",
"declaration": true,
"declarationMap": true,
"types": [],
"lib": ["dom", "es2018"],
"useDefineForClassFields": false,
"jsx": "react",
"jsxFactory": "JSX.createElement",
"jsxFragmentFactory": "JSX.Fragment"
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"files": ["./index.ts"]
}
9 changes: 3 additions & 6 deletions libs/nx-plugin/src/executors/compile-typedoc/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export default async function compileTypedocs(_options: CompileTypedocExecutorSc
},
context
);
const { tsConfig } = readTargetOptions({ project: context.projectName as string, target: 'build' }, context);
const tsConfig: string =
_options.tsConfig ||
readTargetOptions({ project: context.projectName as string, target: 'build' }, context).tsConfig;
const ngPackageJsonFiles = fastGlobSync(projectPath + '/**/*/ng-package.json');
const entryPoints = ngPackageJsonFiles.map((f) => {
const json = JSON.parse(readFileSync(f, 'utf-8'));
Expand All @@ -44,11 +46,6 @@ export default async function compileTypedocs(_options: CompileTypedocExecutorSc
plugin: ['typedoc-plugin-merge-modules'],
mergeModulesRenameDefaults: true,
mergeModulesMergeMode: 'project',
compilerOptions: {
jsx: 'react',
jsxFactory: 'JSX.createElement',
jsxFragmentFactory: 'JSX.Fragment'
},
theme: 'fd-typedoc'
} as unknown as Partial<TypeDocOptions>);
app.options.addReader(new TSConfigReader());
Expand Down
1 change: 1 addition & 0 deletions libs/nx-plugin/src/executors/compile-typedoc/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export interface CompileTypedocExecutorSchema {
outputPath: string;
tsConfig?: string;
}
4 changes: 4 additions & 0 deletions libs/nx-plugin/src/executors/compile-typedoc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"outputPath": {
"type": "string",
"description": "Path to the output directory"
},
"tsConfig": {
"type": "string",
"description": "Path to the tsconfig file. If not provided, the executor will pick the 'build' target's tsConfig"
}
},
"required": []
Expand Down
14 changes: 4 additions & 10 deletions libs/nx-plugin/src/executors/compile-typedoc/theme/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import {
DeclarationHierarchy,
DeclarationReflection,
DefaultThemeRenderContext,
DocumentReflection,
JSX,
PageEvent,
Reflection,
RenderTemplate,
SignatureReflection,
SomeType
Type
} from 'typedoc';
import { index } from './partials';
import { comment } from './partials/comment';
Expand All @@ -26,18 +25,13 @@ import { reflectionTemplate } from './partials/reflection';
import { type } from './partials/type';

export class FdThemeContext extends DefaultThemeRenderContext {
override analytics = () => <></>;
override footer = () => <></>;
override header = () => <></>;
override sidebar = () => <></>;
override pageSidebar = () => <></>;
override toolbar = () => <></>;
override member = (props: DeclarationReflection | DocumentReflection) => {
if (props instanceof DeclarationReflection || props instanceof SignatureReflection) {
return member(this, props);
}
// Handle DocumentReflection accordingly, if needed
return <>{JSON.stringify(props)}</>; // Example placeholder for handling DocumentReflection
};
override member = (props: DeclarationReflection) => member(this, props);
override memberSignatures = (props: DeclarationReflection) => memberSignatures(this, props);
comment = (props: Reflection) => comment(props);
override commentTags = (props: Reflection) => commentTags(this, props);
Expand All @@ -53,7 +47,7 @@ export class FdThemeContext extends DefaultThemeRenderContext {

override memberGetterSetter = (props: DeclarationReflection) => memberGetterSetter(this, props);

override type = (tp: SomeType | undefined) => type(this, tp);
override type = (tp: Type | undefined) => type(this, tp);

override reflectionTemplate = (props: PageEvent<ContainerReflection>) => reflectionTemplate(this, props);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { DeclarationReflection, DefaultThemeRenderContext, JSX } from 'typedoc';
import { DeclarationReflection, DefaultThemeRenderContext, JSX, ReflectionType } from 'typedoc';
import { getKindClass, hasTypeParameters, renderTypeParametersSignature, wbr } from '../utils';

export function memberDeclaration(context: DefaultThemeRenderContext, props: DeclarationReflection) {
function renderTypeDeclaration(type: ReflectionType) {
return (
<div class="tsd-type-declaration">
<h4>Type declaration</h4>
{context.parameter(type.declaration)}
</div>
);
}

const visitor = { reflection: renderTypeDeclaration };

return (
<>
<div class="tsd-signature tsd-kind-icon">
Expand All @@ -27,7 +38,14 @@ export function memberDeclaration(context: DefaultThemeRenderContext, props: Dec

{hasTypeParameters(props) && context.typeParameters(props.typeParameters)}

{props.type && context.typeDeclaration(props.type)}
{props.type?.visit<JSX.Children>({
reflection: renderTypeDeclaration,
array: (arr) => arr.elementType.visit(visitor),
intersection: (int) => int.types.map((t) => t.visit(visitor)),
union: (union) => union.types.map((t) => t.visit(visitor)),
reference: (ref) => ref.typeArguments?.map((t) => t.visit(visitor)),
tuple: (ref) => ref.elements.map((t) => t.visit(visitor))
})}

{context.commentTags(props)}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeclarationReflection, DefaultThemeRenderContext, JSX } from 'typedoc';
import { DeclarationReflection, DefaultThemeRenderContext, JSX, ReferenceReflection } from 'typedoc';
import { classNames, getDisplayName, reflectionFlags, wbr } from '../utils';

export function member(context: DefaultThemeRenderContext, props: DeclarationReflection) {
Expand Down Expand Up @@ -26,7 +26,9 @@ export function member(context: DefaultThemeRenderContext, props: DeclarationRef
? context.memberSignatures(props)
: props.hasGetterOrSetter()
? context.memberGetterSetter(props)
: context.memberDeclaration(props)}
: props instanceof ReferenceReflection
? context.memberReference(props)
: context.memberDeclaration(props)}

{props.groups?.map((item) => item.children.map((item) => !item.hasOwnDocument && context.member(item)))}
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
JSX,
PageEvent,
ReflectionKind,
SignatureReflection
ReflectionType
} from 'typedoc';
import { classNames, fixedMarkdown, getKindClass, hasTypeParameters } from '../utils';
import { classNames, fixedMarkdown, hasTypeParameters } from '../utils';

export function reflectionTemplate(context: DefaultThemeRenderContext, props: PageEvent<ContainerReflection>) {
if (
Expand Down Expand Up @@ -62,12 +62,23 @@ export function reflectionTemplate(context: DefaultThemeRenderContext, props: Pa
{!!props.model.signatures && (
<section class="tsd-panel">{context.memberSignatures(props.model)}</section>
)}
{!!props.model.indexSignatures?.length && (
{!!props.model.indexSignature && (
<section class={classNames({ 'tsd-panel': true }, context.getReflectionClasses(props.model))}>
<h4 class="tsd-before-signature">{context.i18n.theme_indexable()}</h4>
<ul class="tsd-signatures">
{props.model.indexSignatures.map((index) => renderIndexSignature(context, index))}
</ul>
<h4 class="tsd-before-signature">Indexable</h4>
<div class="tsd-signature">
<span class="tsd-signature-symbol">[</span>
{props.model.indexSignature.parameters!.map((item) => (
<>
{item.name}: {context.type(item.type)}
</>
))}
<span class="tsd-signature-symbol">]: </span>
{context.type(props.model.indexSignature.type)}
</div>
{context.commentSummary(props.model.indexSignature)}
{context.commentTags(props.model.indexSignature)}
{props.model.indexSignature?.type instanceof ReflectionType &&
context.parameter(props.model.indexSignature.type.declaration)}
</section>
)}
{/* {!props.model.signatures && context.memberSources(props.model)} */}
Expand All @@ -78,24 +89,3 @@ export function reflectionTemplate(context: DefaultThemeRenderContext, props: Pa
</>
);
}

function renderIndexSignature(context: DefaultThemeRenderContext, index: SignatureReflection) {
return (
<li class="tsd-index-signature">
<div class="tsd-signature">
{index.flags.isReadonly && <span class="tsd-signature-keyword">readonly </span>}
<span class="tsd-signature-symbol">[</span>
{index.parameters!.map((item) => (
<>
<span class={getKindClass(item)}>{item.name}</span>: {context.type(item.type)}
</>
))}
<span class="tsd-signature-symbol">]: </span>
{context.type(index.type)}
</div>
{context.commentSummary(index)}
{context.commentTags(index)}
{context.typeDetailsIfUseful(index.type)}
</li>
);
}
Loading

0 comments on commit c752ea3

Please sign in to comment.