Skip to content

Commit

Permalink
Merge pull request #37 from evilmartians/25-fix-folder-structure
Browse files Browse the repository at this point in the history
Fix generated folder structure
  • Loading branch information
tatarianBarbarian authored Sep 13, 2023
2 parents 4e6187e + 1d038c1 commit 69daf0b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
28 changes: 25 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { writeFile } from 'node:fs/promises'
import { dirname, resolve, sep } from 'node:path'
import { fileURLToPath } from 'node:url'
import { Application, PageEvent, TSConfigReader } from 'typedoc'
import {
Application,
Converter,
PageEvent,
ReflectionKind,
TSConfigReader
} from 'typedoc'

const __dirname = dirname(fileURLToPath(import.meta.url))
const objectToFrontmatter = (object = {}) =>
Expand Down Expand Up @@ -67,6 +73,18 @@ const buildNavigationFromProjectReflection = (baseUrl = '', project) => {
return navFromReflectionGroups(project.groups, result)
}

const onDeclaration =
(entryPoints = []) =>
(context, reflection) => {
if (reflection.kind === ReflectionKind.Module) {
let matchingEntryPoint = entryPoints.find(
entryPoint => entryPoint.path === reflection.sources[0].fullFileName
)

reflection.name = matchingEntryPoint?.name ?? reflection.name
}
}

const typedocConfig = {
excludeExternals: true,
excludeInternal: true,
Expand All @@ -92,21 +110,25 @@ export const initAstroTypedoc = async ({ baseUrl = '/docs/', entryPoints }) => {
await writeFile(
resolve(__dirname, './tsconfig.generic.json'),
JSON.stringify({
include: entryPoints
include: entryPoints.map(e => e.path)
})
)
let app = await Application.bootstrapWithPlugins({
...typedocConfig,
...markdownPluginConfig,
basePath: baseUrl,
entryPoints,
entryPoints: entryPoints.map(e => e.path),
plugin: ['typedoc-plugin-markdown', resolve(__dirname, './theme.js')],
readme: 'none',
theme: 'custom-markdown-theme',
tsconfig: resolve(__dirname, './tsconfig.generic.json')
})

app.options.addReader(new TSConfigReader())
app.converter.on(
Converter.EVENT_CREATE_DECLARATION,
onDeclaration(entryPoints)
)

let getReflections = async () => await app.convert()
let generateDocs = async ({
Expand Down
10 changes: 8 additions & 2 deletions test/website-nanostores-multiple-ep/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ const __dirname = dirname(fileURLToPath(import.meta.url))
const astroTypedoc = await initAstroTypedoc({
baseUrl: '/docs/',
entryPoints: [
resolve(__dirname, '../../../nanostores/index.d.ts'),
resolve(__dirname, '../../../router/index.d.ts')
{
name: 'nanostores',
path: resolve(__dirname, '../../../nanostores/index.d.ts')
},
{
name: '@nanostores/router',
path: resolve(__dirname, '../../../router/index.d.ts')
}
]
})

Expand Down
2 changes: 1 addition & 1 deletion test/website-nanostores/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url))

const astroTypedoc = await initAstroTypedoc({
baseUrl: '/docs/',
entryPoints: [resolve(__dirname, '../../../nanostores/index.d.ts')],
entryPoints: [{ path: resolve(__dirname, '../../../nanostores/index.d.ts') }],
tsconfig: resolve(__dirname, '../../../nanostores/tsconfig.json')
})

Expand Down

0 comments on commit 69daf0b

Please sign in to comment.