瀏覽代碼

feat(docs): Add version info to side menu

Michael Bromley 6 年之前
父節點
當前提交
45e7e33b6f

+ 14 - 0
docs/assets/styles/_menu.scss

@@ -35,4 +35,18 @@
             }
         }
     }
+    .version {
+        text-transform: none;
+        font-size: 12px;
+        color: $gray-500;
+        border-top: 1px dotted $gray-300;
+        display: inline-block;
+        padding-top: 12px;
+        a {
+            color: $gray-500;
+        }
+        a:hover {
+            color: $gray-700;
+        }
+    }
 }

+ 41 - 0
docs/build.js

@@ -0,0 +1,41 @@
+/* tslint:disable:no-console */
+const fs = require('fs');
+const { exec } = require('child_process');
+
+getLastCommitHash()
+    .then(hash => writeBuildInfo(hash))
+    .then(() => {
+        console.log('Updated build info');
+        process.exit(0);
+    })
+    .catch(err => {
+        console.error(err);
+        process.exit(1);
+    });
+
+function writeBuildInfo(commitHash) {
+    const corePackageJson = require('../packages/core/package');
+    const content = {
+        version: corePackageJson.version,
+        commit: commitHash,
+    };
+    return new Promise((resolve, reject) => {
+        fs.writeFile('./data/build.json', JSON.stringify(content, null, 2), err => {
+            if (err) {
+                reject(err);
+            }
+            resolve();
+        });
+    });
+}
+
+function getLastCommitHash() {
+    return new Promise((resolve, reject) => {
+        exec(`git log --pretty=format:'%h' -n 1`, (err, out) => {
+            if (err) {
+                reject(err);
+            }
+            resolve(out.replace(/'/g, ''));
+        });
+    });
+}

+ 4 - 0
docs/data/build.json

@@ -0,0 +1,4 @@
+{
+  "version": "0.1.0-alpha.17",
+  "commit": "b3ad8c91"
+}

+ 7 - 0
docs/layouts/docs/baseof.html

@@ -17,6 +17,11 @@
             {{ else }}
             {{ partial "docs/menu-filetree" . }}
             {{ end }}
+            <div class="version">
+                <a href="https://github.com/vendure-ecommerce/vendure/releases/tag/{{ $.Site.Data.build.version }}">
+                    v{{ $.Site.Data.build.version }}</a>#<a href="https://github.com/vendure-ecommerce/vendure/commit/{{ $.Site.Data.build.commit }}">{{ $.Site.Data.build.commit }}
+                </a>
+            </div>
         </nav>
     </aside>
 
@@ -25,7 +30,9 @@
         {{ template "main" . }}
 
         <div class="book-footer">
+            {{ if gt (dateFormat "2006" $.Page.Lastmod) 2018 }}
             Generated on {{ dateFormat "Jan 2 2006 at 15:04" $.Page.Lastmod }}
+            {{ end }}
         </div>
     </div>
 

+ 1 - 1
package.json

@@ -5,7 +5,7 @@
   "scripts": {
     "bootstrap": "lerna bootstrap",
     "docs:watch": "concurrently -n docgen,hugo,webpack -c green,blue,cyan \"yarn generate-graphql-docs && yarn generate-typescript-docs -w\" \"cd docs && hugo server\" \"cd docs && yarn webpack -w\"",
-    "docs:build": "yarn generate-graphql-docs && yarn generate-typescript-docs && cd docs && yarn webpack --prod && hugo",
+    "docs:build": "yarn generate-graphql-docs && yarn generate-typescript-docs && cd docs && yarn webpack --prod && node build.js && hugo",
     "docs:deploy": "cd docs && yarn && cd .. && yarn docs:build",
     "codegen": "ts-node scripts/codegen/generate-graphql-types.ts",
     "generate-typescript-docs": "ts-node scripts/docs/generate-typescript-docs.ts",

+ 7 - 4
scripts/docs/generate-typescript-docs.ts

@@ -41,7 +41,8 @@ if (watchMode) {
         section.sourceDirs.forEach(dir => {
             fs.watch(dir, { recursive: true }, (eventType, file) => {
                 if (extname(file) === '.ts') {
-                    generateTypescriptDocs([section]);
+                    console.log(`Changes detected in ${dir}`);
+                    generateTypescriptDocs([section], true);
                 }
             });
         });
@@ -52,15 +53,17 @@ if (watchMode) {
  * Uses the TypeScript compiler API to parse the given files and extract out the documentation
  * into markdown files
  */
-function generateTypescriptDocs(config: DocsSectionConfig[]) {
+function generateTypescriptDocs(config: DocsSectionConfig[], isWatchMode: boolean = false) {
     const timeStart = +new Date();
 
     // This map is used to cache types and their corresponding Hugo path. It is used to enable
     // hyperlinking from a member's "type" to the definition of that type.
     const globalTypeMap: TypeMap = new Map();
 
-    for (const { outputPath, sourceDirs } of config) {
-        deleteGeneratedDocs(absOutputPath(outputPath));
+    if (!isWatchMode) {
+        for (const {outputPath, sourceDirs} of config) {
+            deleteGeneratedDocs(absOutputPath(outputPath));
+        }
     }
 
     for (const { outputPath, sourceDirs } of config) {

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

@@ -35,7 +35,7 @@ export class TypescriptDocsRenderer {
             const categoryDir = path.join(outputPath, info.category);
             const indexFile = path.join(categoryDir, '_index.md');
             if (!fs.existsSync(categoryDir)) {
-                fs.mkdirs(categoryDir);
+                fs.mkdirsSync(categoryDir);
             }
             if (!fs.existsSync(indexFile)) {
                 const indexFileContent = generateFrontMatter(info.category, 10, false) + `\n\n# ${info.category}`;

+ 2 - 1
tslint.json

@@ -5,7 +5,8 @@
   ],
   "jsRules": {
     "no-unused-expression": true,
-    "quotemark": [true, "single"]
+    "quotemark": [true, "single"],
+    "object-literal-sort-keys": false
   },
   "rules": {
     "interface-over-type-literal": false,