From b961c0b12479dc4e02fad651ffac2bb84d9221e3 Mon Sep 17 00:00:00 2001 From: Masahiko Sakakibara Date: Sat, 25 Dec 2021 20:31:31 +0900 Subject: [PATCH 1/2] feat(): enable_extends from jsdoc --- src/parse.ts | 7 +++++++ src/test/fixtures/definitions.ts | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/parse.ts b/src/parse.ts index aa57170..6e8e264 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -78,6 +78,13 @@ function collectInterfaces( enums: DocsEnum[] ) { if (i.name !== data.api?.name && !data.interfaces.some((di) => di.name === i.name)) { + const tags = i.tags.filter(tag => tag.name === 'extends' && tag.text?.trim()).map(tag => tag.text?.trim()); + if (tags.length > 0) { + const extendsInterfaces = interfaces.filter(i => [...new Set(tags)].includes(i.name)).map(i => i.properties); + i.properties = i.properties.concat(extendsInterfaces.flat(1)).filter((elem, index, self) => { + return self.indexOf(elem) === index; + }); + } data.interfaces.push(i); } diff --git a/src/test/fixtures/definitions.ts b/src/test/fixtures/definitions.ts index 17bac0b..4687ee5 100644 --- a/src/test/fixtures/definitions.ts +++ b/src/test/fixtures/definitions.ts @@ -119,7 +119,10 @@ export interface HapticsImpact { value: number; } -export interface HapticsImpactOptions { +/** + * @extends addOption + */ +export interface HapticsImpactOptions extends addOption { /** * Impact Feedback Style * @@ -133,7 +136,9 @@ export interface HapticsImpactOptions { style: HapticsImpactStyle; value: boolean; +} +export interface addOption { recursive: HapticsImpactOptions; } From 9f0f60b653efa3afb04c44e6533b18bf5f6ee7c0 Mon Sep 17 00:00:00 2001 From: Masahiko Sakakibara Date: Sat, 25 Dec 2021 20:35:36 +0900 Subject: [PATCH 2/2] chore(): update readme --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index b66a0c6..f29ab07 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,37 @@ docs can also be linked to and shared. - [Example JSON Output](https://github.com/ionic-team/capacitor-docgen/blob/main/src/test/docs.json) +## Extension jsdoc + +If interface use `extends`, you should add jsdocs for reflect docgen. + +for example: + +```ts +/** + * @extends addOption + */ +export interface HapticsImpactOptions extends addOption { + /** + * Impact Feedback Style + * + * The mass of the objects in the collision simulated by a + * [`UIImpactFeedbackGenerator`](https://developer.apple.com/documentation/uikit/uiimpactfeedbackstyle) object. + * Type is a `HapticsImpactStyle`. + * + * @default HapticsImpactStyle.Heavy + * @since 1.0.0 + */ + style: HapticsImpactStyle; + + value: boolean; +} + +export interface addOption { + recursive: HapticsImpactOptions; +} +``` + ## CLI The easiest way to run `docgen` is to install `@capacitor/docgen` as a dev dependency