-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dgeni): render subpackages under root package (#3063)
- Loading branch information
Showing
6 changed files
with
54 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tools/dgeni/src/transforms/daffodil-api-package/processors/add-subpackage-exports.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Document } from 'dgeni'; | ||
|
||
import { FilterableProcessor } from '../../../utils/filterable-processor.type'; | ||
import { isSubpackage } from '../../../utils/package-path'; | ||
|
||
/** | ||
* Adds subpackage entry point docs to the containing package doc. | ||
*/ | ||
export class AddSubpackageExportsProcessor implements FilterableProcessor { | ||
readonly name = 'addSubpackageExports'; | ||
readonly $runAfter = ['docs-processed']; | ||
readonly $runBefore = ['rendering-docs']; | ||
|
||
docTypes = ['package']; | ||
|
||
$process(docs: Array<Document>): Array<Document> { | ||
return docs.map((doc) => { | ||
if (this.docTypes.includes(doc.docType)) { | ||
const subPackages = docs.filter((d) => | ||
d.docType === 'package' && isSubpackage(doc, d), | ||
); | ||
doc.exports.push(...subPackages); | ||
} | ||
return doc; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Document } from 'dgeni'; | ||
|
||
/** | ||
* Returns `true` if `possibleSub` is a direct subpackage of `root`. | ||
*/ | ||
export const isSubpackage = (root: Document, possibleSub: Document): boolean => { | ||
const rootSegs = root.id.split('/'); | ||
const subSegs = possibleSub.id.split('/'); | ||
return rootSegs.join() === subSegs.slice(0, subSegs.length - 1).join(); | ||
}; |