1
- const _fs = require ( 'fs' )
2
- const path = require ( 'path' )
3
- const TypeDoc = require ( 'typedoc' )
4
- const { PageEvent } = TypeDoc
1
+ // @ts -check
2
+ import fs from 'node:fs/promises'
3
+ import path from 'node:path'
4
+ import { Application , TSConfigReader , PageEvent } from 'typedoc'
5
5
6
- const fs = _fs . promises
6
+ const __dirname = path . dirname ( new URL ( import . meta . url ) . pathname )
7
7
8
8
const DEFAULT_OPTIONS = {
9
9
// disableOutputCheck: true,
@@ -12,33 +12,36 @@ const DEFAULT_OPTIONS = {
12
12
readme : 'none' ,
13
13
out : path . resolve ( __dirname , './api' ) ,
14
14
entryDocument : 'index.md' ,
15
- preserveAnchorCasing : true ,
16
15
hideBreadcrumbs : false ,
17
16
hideInPageTOC : true ,
17
+ preserveAnchorCasing : true ,
18
18
}
19
19
20
20
/**
21
21
*
22
22
* @param {Partial<import('typedoc').TypeDocOptions> } config
23
23
*/
24
- exports . createTypeDocApp = function createTypeDocApp ( config = { } ) {
24
+ export async function createTypeDocApp ( config = { } ) {
25
25
const options = {
26
26
...DEFAULT_OPTIONS ,
27
27
...config ,
28
28
}
29
29
30
- const app = new TypeDoc . Application ( )
30
+ const app = await Application . bootstrapWithPlugins ( options )
31
31
32
32
// If you want TypeDoc to load tsconfig.json / typedoc.json files
33
- app . options . addReader ( new TypeDoc . TSConfigReader ( ) )
33
+ app . options . addReader ( new TSConfigReader ( ) )
34
34
35
35
app . renderer . on (
36
36
PageEvent . END ,
37
37
/**
38
38
*
39
- * @param {import('typedoc/dist/lib/output/events ').PageEvent } page
39
+ * @param {import('typedoc').PageEvent } page
40
40
*/
41
41
page => {
42
+ if ( ! page . contents ) {
43
+ return
44
+ }
42
45
page . contents = prependYAML ( page . contents , {
43
46
// TODO: figure out a way to point to the source files?
44
47
editLink : false ,
@@ -47,7 +50,6 @@ exports.createTypeDocApp = function createTypeDocApp(config = {}) {
47
50
)
48
51
49
52
async function serve ( ) {
50
- await app . bootstrapWithPlugins ( options )
51
53
app . convertAndWatch ( handleProject )
52
54
}
53
55
@@ -58,14 +60,13 @@ exports.createTypeDocApp = function createTypeDocApp(config = {}) {
58
60
) {
59
61
await fs . rm ( options . out , { recursive : true } )
60
62
}
61
- await app . bootstrapWithPlugins ( options )
62
- const project = app . convert ( )
63
+ const project = await app . convert ( )
63
64
return handleProject ( project )
64
65
}
65
66
66
67
/**
67
68
*
68
- * @param {import('typedoc').ProjectReflection } project
69
+ * @param {import('typedoc').ProjectReflection | undefined } project
69
70
*/
70
71
async function handleProject ( project ) {
71
72
if ( project ) {
@@ -84,13 +85,6 @@ exports.createTypeDocApp = function createTypeDocApp(config = {}) {
84
85
return {
85
86
build,
86
87
serve,
87
- /**
88
- *
89
- * @param {'build' | 'serve' } command
90
- */
91
- setTargetMode ( command ) {
92
- targetMode = command
93
- } ,
94
88
}
95
89
}
96
90
@@ -102,6 +96,7 @@ async function exists(path) {
102
96
return false
103
97
}
104
98
}
99
+
105
100
/**
106
101
* @typedef {Record<string, string | number | boolean> } FrontMatterVars
107
102
*/
0 commit comments