Skip to content

Commit

Permalink
fix: handle multiple export modules in readme updater
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Jan 17, 2024
1 parent af54374 commit 969f22a
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/docs/readme-updater-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ export function load (app) {
// pages of the current module or monorepo packages
app.renderer.on(td.RendererEvent.END, (/** @type {td.RendererEvent} */ evt) => {
const urlMappings = evt.urls?.filter(urlMapping => {
// skip anything without a model-level comment
if (urlMapping.model?.comment == null) {
return false
}

// single-module repo, single export
if (urlMapping.url === 'modules.html') {
return true
Expand All @@ -44,10 +39,6 @@ export function load (app) {

return false
}).map(urlMapping => {
if (urlMapping.model?.comment == null) {
throw new Error('Model comment was null')
}

if (isMonorepoParent) {
let project = urlMapping.model.name

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

let comment = urlMapping.model?.comment

if (comment == null && urlMapping.model instanceof td.DeclarationReflection && urlMapping.model.children != null && urlMapping.model.children.length > 0) {
// multi-export modules have a different structure
comment = urlMapping.model.children
.find(child => child.name === 'index')
?.comment
}

if (comment == null) {
return null
}

return {
comment: urlMapping.model.comment,
comment,
manifestPath: path.join(projects[project].dir, 'package.json'),
readmePath: path.join(projects[project].dir, 'README.md')
}
}

if (urlMapping.model?.comment == null) {
return null
}

return {
comment: urlMapping.model.comment,
manifestPath: path.join(process.cwd(), 'package.json'),
readmePath: path.join(process.cwd(), 'README.md')
}
})

urlMappings?.forEach(urlMapping => updateModule(urlMapping.comment, urlMapping.manifestPath, urlMapping.readmePath, app))
if (urlMappings == null) {
return
}

for (const urlMapping of urlMappings) {
if (urlMapping == null) {
continue
}

updateModule(urlMapping.comment, urlMapping.manifestPath, urlMapping.readmePath, app)
}
})
}

Expand Down

0 comments on commit 969f22a

Please sign in to comment.