Jelajahi Sumber

feat(docs): Implement @internal tag to exclude member from docs

Relates to #89
Michael Bromley 6 tahun lalu
induk
melakukan
2295a3a726
2 mengubah file dengan 19 tambahan dan 0 penghapusan
  1. 14 0
      docs/README.md
  2. 5 0
      scripts/docs/typescript-docs-parser.ts

+ 14 - 0
docs/README.md

@@ -60,6 +60,12 @@ This is optional and when present, sets the "weight" of the markdown file in the
 
 This is used to specify the default value of a property, e.g. when documenting an optional configuration option.
 
+##### `@internal`
+
+This is used to exlude members from appearing in the docs. For example, a class may need a particular
+public method for internal use, but this method is not intended to be used by external consumers of that
+class.
+
 ##### Example
 
 ````ts
@@ -87,6 +93,14 @@ export class Greeter {
     greet(name: string): string {
       return `Hi, ${name}, good to see you!`;
     }
+    
+    /**
+     * Required as a work-around for issue #1234
+     * @internal
+     */
+    someMethodUsedOnlyByVendureCore() {
+        // ...
+    }
 }
 ````
 

+ 5 - 0
scripts/docs/typescript-docs-parser.ts

@@ -209,6 +209,7 @@ export class TypescriptDocsParser {
                 let defaultValue = '';
                 let parameters: MethodParameterInfo[] = [];
                 let fullText = '';
+                let isInternal = false;
                 if (ts.isConstructorDeclaration(member)) {
                     fullText = 'constructor';
                 } else if (ts.isMethodDeclaration(member)) {
@@ -220,7 +221,11 @@ export class TypescriptDocsParser {
                     description: tag => (description += tag.comment || ''),
                     example: tag => (description += this.formatExampleCode(tag.comment)),
                     default: tag => (defaultValue = tag.comment || ''),
+                    internal: tag => isInternal = true,
                 });
+                if (isInternal) {
+                    continue;
+                }
                 if (!ts.isEnumMember(member) && member.type) {
                     type = member.type.getText();
                 }