Skip to content

Commit

Permalink
feat(docs): add clear script, adjust docs structure (#5681)
Browse files Browse the repository at this point in the history
* feat(site): add script that clear generated docs

* chore: adjust docs structure

* style(docs): config style of summary tag
  • Loading branch information
Aarebecca authored Apr 26, 2024
1 parent 6326125 commit acf90c1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 16 deletions.
5 changes: 5 additions & 0 deletions packages/site/.dumi/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
height: 100%;
overflow-y: auto;
}

summary {
color: #873bf4;
cursor: pointer;
}
44 changes: 30 additions & 14 deletions packages/site/.dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default defineConfig({
},
},
{
slug: 'docs/apis',
slug: 'docs/api',
title: {
zh: 'API',
en: 'API',
Expand Down Expand Up @@ -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: {
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/site/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
/support

## api doc
docs/apis/.gitignore
docs/api/.gitignore
3 changes: 3 additions & 0 deletions packages/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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": {
Expand All @@ -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",
Expand Down
39 changes: 39 additions & 0 deletions packages/site/scripts/clear-doc.ts
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion packages/site/src/setting.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const inputFolder = 'support/api';
export const outputFolder = 'docs/apis';
export const outputFolder = 'docs/api';
export const referenceFoldername = 'reference';

0 comments on commit acf90c1

Please sign in to comment.