Files
medusa-store/docs-util/packages/utils/src/get-project-child.ts
Shahed Nasser 892d737c1f docs: enhance how references are generated (#5805)
* adjusted configurations

* enhancements to tool and configurations

* change reference in docs

* fixed issue in workflows reference

* added project name

* more optimizations

* fix context error

* added a types reference

* resolved missing types

* fix reference reflection types not having children

* add an expand url parameter

* added new option to the README

* added details about new option
2023-12-05 15:29:41 +02:00

50 lines
1.1 KiB
TypeScript

import {
DeclarationReflection,
ProjectReflection,
ReflectionKind,
} from "typedoc"
const MAX_LEVEL = 3
export function getProjectChild(
project: ProjectReflection,
childName: string,
level = 1
): DeclarationReflection | undefined {
let reflection: DeclarationReflection | undefined = project.getChildByName(
childName
) as DeclarationReflection
const splitChildName = childName.split(".")
const canExpandFurther = level <= MAX_LEVEL
if (!reflection && splitChildName.length > 1 && canExpandFurther) {
reflection = getProjectChild(
project,
splitChildName[splitChildName.length - 1],
level + 1
)
}
if (
!reflection &&
project.parent &&
project.parent instanceof ProjectReflection &&
canExpandFurther
) {
reflection = getProjectChild(project.parent, childName, level + 1)
}
if (!reflection) {
const modules = project.getChildrenByKind(ReflectionKind.Module)
for (const module of modules) {
reflection = module.getChildByName(childName) as DeclarationReflection
if (reflection) {
break
}
}
}
return reflection
}