Skip to content

Commit 969f22a

Browse files
committed
fix: handle multiple export modules in readme updater
1 parent af54374 commit 969f22a

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

src/docs/readme-updater-plugin.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ export function load (app) {
2222
// pages of the current module or monorepo packages
2323
app.renderer.on(td.RendererEvent.END, (/** @type {td.RendererEvent} */ evt) => {
2424
const urlMappings = evt.urls?.filter(urlMapping => {
25-
// skip anything without a model-level comment
26-
if (urlMapping.model?.comment == null) {
27-
return false
28-
}
29-
3025
// single-module repo, single export
3126
if (urlMapping.url === 'modules.html') {
3227
return true
@@ -44,10 +39,6 @@ export function load (app) {
4439

4540
return false
4641
}).map(urlMapping => {
47-
if (urlMapping.model?.comment == null) {
48-
throw new Error('Model comment was null')
49-
}
50-
5142
if (isMonorepoParent) {
5243
let project = urlMapping.model.name
5344

@@ -59,21 +50,48 @@ export function load (app) {
5950
throw new Error(`Could not derive project name from url mapping model "${urlMapping.model.name}" with parent "${urlMapping.model.parent?.name}"`)
6051
}
6152

53+
let comment = urlMapping.model?.comment
54+
55+
if (comment == null && urlMapping.model instanceof td.DeclarationReflection && urlMapping.model.children != null && urlMapping.model.children.length > 0) {
56+
// multi-export modules have a different structure
57+
comment = urlMapping.model.children
58+
.find(child => child.name === 'index')
59+
?.comment
60+
}
61+
62+
if (comment == null) {
63+
return null
64+
}
65+
6266
return {
63-
comment: urlMapping.model.comment,
67+
comment,
6468
manifestPath: path.join(projects[project].dir, 'package.json'),
6569
readmePath: path.join(projects[project].dir, 'README.md')
6670
}
6771
}
6872

73+
if (urlMapping.model?.comment == null) {
74+
return null
75+
}
76+
6977
return {
7078
comment: urlMapping.model.comment,
7179
manifestPath: path.join(process.cwd(), 'package.json'),
7280
readmePath: path.join(process.cwd(), 'README.md')
7381
}
7482
})
7583

76-
urlMappings?.forEach(urlMapping => updateModule(urlMapping.comment, urlMapping.manifestPath, urlMapping.readmePath, app))
84+
if (urlMappings == null) {
85+
return
86+
}
87+
88+
for (const urlMapping of urlMappings) {
89+
if (urlMapping == null) {
90+
continue
91+
}
92+
93+
updateModule(urlMapping.comment, urlMapping.manifestPath, urlMapping.readmePath, app)
94+
}
7795
})
7896
}
7997

0 commit comments

Comments
 (0)