Ver código fonte

docs: Display package for TypeScript docs

Michael Bromley 6 anos atrás
pai
commit
6d2cae41a2

+ 6 - 0
docs/assets/styles/_shortcodes.scss

@@ -56,6 +56,12 @@
 .generation-info {
     font-size: $font-size-12;
     border-bottom: 1px dashed $gray-400;
+    .label {
+        color: $gray-600;
+    }
+    .file {
+        margin-left: 12px;
+    }
 }
 
 /**

+ 3 - 1
docs/assets/styles/main.scss

@@ -179,8 +179,10 @@ ul.contents-list {
 
 .book-footer {
     height: 200px;
-    // background-color: $gray-100;
+    text-align: center;
+    color: $gray-600;
     margin-top: 60px;
+    font-size: 12px;
 }
 
 .book-posts {

+ 2 - 1
docs/layouts/docs/baseof.html

@@ -23,8 +23,9 @@
     <div class="book-page">
         {{ partial "docs/mobile-header" . }}
         {{ template "main" . }}
-        <div class="book-footer">
 
+        <div class="book-footer">
+            Generated on {{ dateFormat "Jan 2 2006 at 15:04" $.Page.Lastmod }}
         </div>
     </div>
 

+ 2 - 1
docs/layouts/shortcodes/generation-info.html

@@ -1,3 +1,4 @@
 <div class="generation-info">
-    Documentation generated from <a href="https://github.com/vendure-ecommerce/vendure/blob/master/{{ .Get "sourceFile" }}#L{{ .Get "sourceLine" }}">{{  index (last 1 (split (.Get "sourceFile") "/")) 0 }}</a> on {{ dateFormat "Jan 2 2006 at 15:04" $.Page.Lastmod }}
+    <span class="label">Package:</span> <a href="https://www.npmjs.com/package/{{ .Get "packageName" }}">{{ .Get "packageName" }}</a>
+    <span class="label file">File:</span> <a href="https://github.com/vendure-ecommerce/vendure/blob/master/{{ .Get "sourceFile" }}#L{{ .Get "sourceLine" }}">{{  index (last 1 (split (.Get "sourceFile") "/")) 0 }}</a>
 </div>

+ 1 - 0
scripts/docs/typescript-docgen-types.ts

@@ -23,6 +23,7 @@ export interface MethodInfo extends MemberInfo {
 }
 
 export interface DeclarationInfo {
+    packageName: string;
     sourceFile: string;
     sourceLine: number;
     title: string;

+ 12 - 1
scripts/docs/typescript-docs-parser.ts

@@ -87,8 +87,10 @@ export class TypescriptDocsParser {
         const description = this.getDeclarationDescription(statement);
         const normalizedTitle = this.kebabCase(title);
         const fileName = normalizedTitle === category ? '_index' : normalizedTitle;
+        const packageName = this.getPackageName(sourceFile);
 
         const info = {
+            packageName,
             sourceFile,
             sourceLine,
             fullText,
@@ -154,6 +156,15 @@ export class TypescriptDocsParser {
         return name + typeParams;
     }
 
+    private getPackageName(sourceFile: string): string {
+        const matches = sourceFile.match(/\/packages\/([^/]+)\//);
+        if (matches) {
+            return `@vendure/${matches[1]}`;
+        } else {
+            return '';
+        }
+    }
+
     /**
      * Parses an array of inteface members into a simple object which can be rendered into markdown.
      */
@@ -259,7 +270,7 @@ export class TypescriptDocsParser {
             docsCategory: tag => (category = tag.comment || ''),
         });
         return this.kebabCase(category);
-    };
+    }
 
     /**
      * Type guard for the types of statement which can ge processed by the doc generator.

+ 1 - 1
scripts/docs/typescript-docs-renderer.ts

@@ -187,7 +187,7 @@ export class TypescriptDocsRenderer {
     }
 
     private renderGenerationInfoShortcode(info: DeclarationInfo): string {
-        return `{{< generation-info sourceFile="${info.sourceFile}" sourceLine="${info.sourceLine}">}}\n\n`;
+        return `{{< generation-info sourceFile="${info.sourceFile}" sourceLine="${info.sourceLine}" packageName="${info.packageName}">}}\n\n`;
     }
 
     /**