ソースを参照

feat: sync doc

suzigang 3 年 前
コミット
970ee3311e
6 ファイル変更214 行追加40 行削除
  1. 30 0
      .github/workflows/sync-h5.yml
  2. 30 0
      .github/workflows/sync-taro.yml
  3. 0 39
      jd/copyComponentMd.js
  4. 78 0
      jd/copyh5.js
  5. 73 0
      jd/copytaro.js
  6. 3 1
      package.json

+ 30 - 0
.github/workflows/sync-h5.yml

@@ -0,0 +1,30 @@
+name: sync to docs-h5
+
+on:
+  push:
+    branches:
+      - v4 # default branch
+    paths:
+      - '.github/workflows/**'
+      - 'src/**'
+
+jobs:
+  copy:
+    runs-on: ubuntu-latest  
+    steps:
+      - uses: actions/checkout@v2 
+      - run: yarn install
+      - run: yarn copy:h5
+      - name : Sync 
+        uses : JamesIves/github-pages-deploy-action@4.1.7 
+        with :
+          branch : new-site # action 应该部署到的分支 。
+          folder : site_docs #操作应该部署的文件夹 。
+          clean: false
+          repository-name: jdf2e/nutui-docs
+          token: ${{ secrets.GIT_ACTION }}
+          target-folder: src/docs_vue
+
+     
+
+          

+ 30 - 0
.github/workflows/sync-taro.yml

@@ -0,0 +1,30 @@
+name: sync to docs-taro
+
+on:
+  push:
+    branches:
+      - v4 # default branch
+    paths:
+      - '.github/workflows/**'
+      - 'src/**'
+
+jobs:
+  copy:
+    runs-on: ubuntu-latest  
+    steps:
+      - uses: actions/checkout@v2 
+      - run: yarn install
+      - run: yarn copy:taro
+      - name : Sync 
+        uses : JamesIves/github-pages-deploy-action@4.1.7 
+        with :
+          branch : new-site # action 应该部署到的分支 。
+          folder : site_docs #操作应该部署的文件夹 。
+          clean: false
+          repository-name: jdf2e/nutui-docs
+          token: ${{ secrets.GIT_ACTION }}
+          target-folder: src/docs_vue_taro
+
+     
+
+          

+ 0 - 39
jd/copyComponentMd.js

@@ -1,39 +0,0 @@
-import fse from 'fs-extra';
-import fs from 'fs';
-const copyFile = (from, to) => {
-  fse
-    .copy(from, to)
-    .then(() => {
-      console.log('success!>', to);
-    })
-    .catch((err) => {
-      console.error(err);
-    });
-};
-
-const copy = async () => {
-  let configPath = `src/config.json`;
-
-  // 复制所有组件
-  const fromConfig = await fse.readJson(configPath);
-  fromConfig.nav.forEach(({ packages }) => {
-    packages.forEach((item) => {
-      if (item.show) {
-        let cmpName = item.name.toLowerCase();
-        let docpath = `src/packages/__VUE/${cmpName}/doc.md`;
-        let doctaropath = `src/packages/__VUE/${cmpName}/doc.taro.md`;
-        fs.access(doctaropath, fs.constants.F_OK, (err) => {
-          if (err) {
-            fse.readFile(docpath, (err, data) => {
-              if (!err) {
-                copyFile(docpath, doctaropath);
-              }
-            });
-          }
-        });
-      }
-    });
-  });
-};
-
-copy();

+ 78 - 0
jd/copyh5.js

@@ -0,0 +1,78 @@
+const targetBaseUrl = `${process.cwd()}/site_docs`;
+const fse = require('fs-extra');
+const copyFile = (from, to) => {
+  fse
+    .copy(from, to)
+    .then(() => {
+      console.log('success!>', to);
+    })
+    .catch((err) => {
+      console.error(err);
+    });
+};
+const removeFile = async (url) => {
+  return new Promise((res, rej) => {
+    fse.remove(url, (err) => {
+      if (err) {
+        throw err;
+      }
+      res(true);
+    });
+  });
+};
+
+const copy = async () => {
+  let configPath = `src/config.json`;
+  let configPkgPath = `package.json`;
+  let nutuiDocsConfigPath = `${targetBaseUrl}/config.json`;
+
+  // 判断 site_docs 文件是否存在根路径中
+  const existsRoot = await fse.pathExists(targetBaseUrl);
+
+  if (existsRoot) await removeFile(targetBaseUrl);
+  // 复制所有组件
+  const fromConfig = await fse.readJson(configPath);
+  fromConfig.nav.forEach(({ packages }) => {
+    packages.forEach((item) => {
+      if (item.show) {
+        let cmpName = item.name.toLowerCase();
+        let docpath = `src/packages/__VUE/${cmpName}/doc.md`;
+        let docEnPath = `src/packages/__VUE/${cmpName}/doc.en-US.md`;
+        fse.readFile(docpath, (err, data) => {
+          if (!err) {
+            copyFile(docpath, `${targetBaseUrl}/docs/${cmpName}/doc.md`);
+          }
+        });
+        fse.readFile(docEnPath, (err, data) => {
+          if (!err) {
+            copyFile(docEnPath, `${targetBaseUrl}/docs/${cmpName}/doc.en-US.md`);
+          }
+        });
+      }
+    });
+  });
+
+  // 复制 config.json
+  const fromPkgConfig = await fse.readJson(configPkgPath);
+
+  const obj = {
+    version: '',
+    nav: [],
+    docs: []
+  };
+  fse.outputJSON(nutuiDocsConfigPath, obj, () => {
+    const docsConfig = fse.readJson(nutuiDocsConfigPath);
+    docsConfig.version = fromPkgConfig.version;
+    docsConfig.nav = fromConfig.nav;
+    docsConfig.docs = fromConfig.docs;
+    docsConfig.demoUrl = 'https://nutui.jd.com/3x/demo.html#';
+    fse
+      .writeJson(nutuiDocsConfigPath, docsConfig, {
+        spaces: 2
+      })
+      .then(() => {
+        console.log(`${fromPkgConfig.version} success!`);
+      });
+  });
+};
+copy();

+ 73 - 0
jd/copytaro.js

@@ -0,0 +1,73 @@
+const targetBaseUrl = `${process.cwd()}/site_docs`;
+const fse = require('fs-extra');
+const copyFile = (from, to) => {
+  fse
+    .copy(from, to)
+    .then(() => {
+      console.log('success!>', to);
+    })
+    .catch((err) => {
+      console.error(err);
+    });
+};
+const removeFile = async (url) => {
+  return new Promise((res, rej) => {
+    fse.remove(url, (err) => {
+      if (err) {
+        throw err;
+      }
+      res(true);
+    });
+  });
+};
+
+const copy = async () => {
+  let configPath = `src/config.json`;
+  let configPkgPath = `package.json`;
+  let nutuiDocsConfigPath = `${targetBaseUrl}/config.json`;
+
+  // 判断 site_docs 文件是否存在根路径中
+  const existsRoot = await fse.pathExists(targetBaseUrl);
+
+  if (existsRoot) await removeFile(targetBaseUrl);
+  // 复制所有组件
+  const fromConfig = await fse.readJson(configPath);
+  fromConfig.nav.forEach(({ packages }) => {
+    packages.forEach((item) => {
+      if (item.show) {
+        let cmpName = item.name.toLowerCase();
+        let doctaropath = `src/packages/__VUE/${cmpName}/doc.taro.md`;
+        fse.readFile(doctaropath, (err, data) => {
+          if (!err) {
+            copyFile(doctaropath, `${targetBaseUrl}/docs/${cmpName}/doc.taro.md`);
+          }
+        });
+      }
+    });
+  });
+
+  // 复制 config.json
+  const fromPkgConfig = await fse.readJson(configPkgPath);
+
+  const obj = {
+    version: '',
+    nav: [],
+    docs: []
+  };
+  fse.outputJSON(nutuiDocsConfigPath, obj, () => {
+    const docsConfig = fse.readJson(nutuiDocsConfigPath);
+    docsConfig.version = fromPkgConfig.version;
+    docsConfig.nav = fromConfig.nav;
+    docsConfig.docs = fromConfig.docs;
+    docsConfig.demoUrl = 'https://nutui.jd.com/3x/demo.html#';
+    fse
+      .writeJson(nutuiDocsConfigPath, docsConfig, {
+        spaces: 2
+      })
+      .then(() => {
+        console.log(`${fromPkgConfig.version} success!`);
+      });
+  });
+};
+// copy(reactBaseUrl, 'react');
+copy();

+ 3 - 1
package.json

@@ -69,7 +69,9 @@
     "createTaroConfig": "node ./jd/generate-taro-route.cjs",
     "attrs": "node ./jd/createAttributes.cjs",
     "dts": "rm -rf ./tsc/type && vue-tsc --declaration --emitDeclarationOnly -p ./tsconfig.declaration.json && npm run generate:types",
-    "dts:taro": "rm -rf ./tsc/type && vue-tsc --declaration --emitDeclarationOnly -p ./tsconfig.declaration.taro.json && npm run generate:types:taro"
+    "dts:taro": "rm -rf ./tsc/type && vue-tsc --declaration --emitDeclarationOnly -p ./tsconfig.declaration.taro.json && npm run generate:types:taro",
+    "copy:h5": "node ./jd/copyh5.js",
+    "copy:taro": "node ./jd/copytaro.js"
   },
   "standard-version": {
     "scripts": {