From acf90c103dcb340dd5d718ef669e5205d6d977bd Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 26 Apr 2024 10:43:15 +0800 Subject: [PATCH] feat(docs): add clear script, adjust docs structure (#5681) * feat(site): add script that clear generated docs * chore: adjust docs structure * style(docs): config style of summary tag --- packages/site/.dumi/global.less | 5 ++++ packages/site/.dumirc.ts | 44 ++++++++++++++++++++---------- packages/site/.gitignore | 2 +- packages/site/package.json | 3 ++ packages/site/scripts/clear-doc.ts | 39 ++++++++++++++++++++++++++ packages/site/src/setting.ts | 2 +- 6 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 packages/site/scripts/clear-doc.ts diff --git a/packages/site/.dumi/global.less b/packages/site/.dumi/global.less index d078a2f5a19..76418748d5e 100644 --- a/packages/site/.dumi/global.less +++ b/packages/site/.dumi/global.less @@ -2,3 +2,8 @@ height: 100%; overflow-y: auto; } + +summary { + color: #873bf4; + cursor: pointer; +} diff --git a/packages/site/.dumirc.ts b/packages/site/.dumirc.ts index 9d2a760bc49..c2ac709f7cd 100644 --- a/packages/site/.dumirc.ts +++ b/packages/site/.dumirc.ts @@ -57,7 +57,7 @@ export default defineConfig({ }, }, { - slug: 'docs/apis', + slug: 'docs/api', title: { zh: 'API', en: 'API', @@ -95,6 +95,22 @@ export default defineConfig({ ], docs: [ // Docs folder + { + slug: 'manual/getting-started', + title: { + zh: '开始使用', + en: 'Getting Started', + }, + order: 2, + }, + { + slug: 'manual/getting-started/integration', + title: { + zh: '前端框架集成', + en: 'Integration', + }, + order: 2, + }, { slug: 'manual/core-concept', title: { @@ -111,86 +127,86 @@ export default defineConfig({ }, order: 4, }, - // APIs folder + // API folder { - slug: 'apis/graph', + slug: 'api/graph', title: { zh: 'Graph - 图', en: 'Graph', }, }, { - slug: 'apis/data', + slug: 'api/data', title: { zh: 'Data - 数据', en: 'Data', }, }, { - slug: 'apis/element', + slug: 'api/element', title: { zh: 'Element - 元素', en: 'Element', }, }, { - slug: 'apis/element/node', + slug: 'api/element/node', title: { zh: 'Node - 节点', en: 'Node', }, }, { - slug: 'apis/element/edge', + slug: 'api/element/edge', title: { zh: 'Edge - 边', en: 'Edge', }, }, { - slug: 'apis/element/combo', + slug: 'api/element/combo', title: { zh: 'Combo - 组合', en: 'Combo', }, }, { - slug: 'apis/layouts', + slug: 'api/layouts', title: { zh: 'Layout - 布局', en: 'Layout', }, }, { - slug: 'apis/behaviors', + slug: 'api/behaviors', title: { zh: 'Behavior - 交互', en: 'Behavior', }, }, { - slug: 'apis/plugins', + slug: 'api/plugins', title: { zh: 'Plugin - 插件', en: 'Plugin', }, }, { - slug: 'apis/extension', + slug: 'api/extension', title: { zh: 'Extension - 扩展', en: 'Extension', }, }, { - slug: 'apis/function', + slug: 'api/function', title: { zh: 'Function - 函数', en: 'Function', }, }, { - slug: 'apis/export', + slug: 'api/reference', title: { zh: 'Export - 导出', en: 'Export', diff --git a/packages/site/.gitignore b/packages/site/.gitignore index b1a462d304c..77701ed16b5 100644 --- a/packages/site/.gitignore +++ b/packages/site/.gitignore @@ -4,4 +4,4 @@ /support ## api doc -docs/apis/.gitignore +docs/api/.gitignore diff --git a/packages/site/package.json b/packages/site/package.json index a1d99b10aef..86733515d3b 100644 --- a/packages/site/package.json +++ b/packages/site/package.json @@ -29,6 +29,7 @@ "deploy": "npm run build && gh-pages -d dist", "dev": "dumi dev", "doc": " ts-node ./scripts/generate-api.ts && ts-node ./scripts/generate-doc.ts", + "doc:clear": "ts-node ./scripts/clear-doc.ts", "find-unused-demos": "node ./scripts/find-unused-demos.js", "lint": "eslint ./src --quiet && prettier ./src --check", "preview": "dumi preview" @@ -47,6 +48,7 @@ "antd": "^5.10.2", "dumi": "^2.2.14", "insert-css": "^2.0.0", + "react": "^18.2.0", "stats.js": "^0.17.0" }, "devDependencies": { @@ -58,6 +60,7 @@ "@rushstack/node-core-library": "^4.1.0", "@types/fs-extra": "^11.0.4", "@types/lodash": "^4.17.0", + "@types/react": "^18.2.75", "@types/resolve": "^1.20.6", "fs-extra": "^11.2.0", "prettier": "^3.1.1", diff --git a/packages/site/scripts/clear-doc.ts b/packages/site/scripts/clear-doc.ts new file mode 100644 index 00000000000..24870f4e4b3 --- /dev/null +++ b/packages/site/scripts/clear-doc.ts @@ -0,0 +1,39 @@ +import fs from 'fs'; +import path from 'path'; + +/** + * + */ +function clear() { + const baseDir = path.resolve(__dirname, '../docs/api'); + + // read gitignore + const gitignore = fs.readFileSync(path.resolve(baseDir, '.gitignore'), 'utf-8'); + + // clear all files list in .gitignore + const lines = gitignore.split('\n'); + + lines.forEach((line) => { + if (line.startsWith('#')) return; + + const file = line.trim(); + if (file) { + const filepath = path.resolve(baseDir, file); + + if (fs.existsSync(filepath)) { + if (fs.lstatSync(filepath).isDirectory()) { + console.log('Clearing folder: ', filepath); + fs.rmdirSync(filepath, { recursive: true }); + } else { + console.log('Clearing file: ', filepath); + fs.unlinkSync(filepath); + } + } + } + }); + + // remove .gitignore + fs.unlinkSync('docs/api/.gitignore'); +} + +clear(); diff --git a/packages/site/src/setting.ts b/packages/site/src/setting.ts index 94c14905a60..f8f353a5911 100644 --- a/packages/site/src/setting.ts +++ b/packages/site/src/setting.ts @@ -1,3 +1,3 @@ export const inputFolder = 'support/api'; -export const outputFolder = 'docs/apis'; +export const outputFolder = 'docs/api'; export const referenceFoldername = 'reference';