Skip to content

Commit

Permalink
docs: refactor docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhe421 committed Nov 2, 2024
1 parent e50718a commit 6ff4ffa
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 42 deletions.
18 changes: 9 additions & 9 deletions .docs/.vitepress/cache/deps/_metadata.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
{
"hash": "7a1f0efc",
"hash": "9f9f4bbd",
"configHash": "650ed03b",
"lockfileHash": "1605bbaf",
"browserHash": "c3d4af77",
"lockfileHash": "28b10113",
"browserHash": "9bff3b1b",
"optimized": {
"vue": {
"src": "../../../../node_modules/vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js",
"fileHash": "ac5f5171",
"fileHash": "04687c21",
"needsInterop": false
},
"vitepress > @vue/devtools-api": {
"src": "../../../../node_modules/@vue/devtools-api/dist/index.js",
"file": "vitepress___@vue_devtools-api.js",
"fileHash": "cf6777d8",
"fileHash": "6f1fff47",
"needsInterop": false
},
"vitepress > @vueuse/core": {
"src": "../../../../node_modules/@vueuse/core/index.mjs",
"file": "vitepress___@vueuse_core.js",
"fileHash": "68bff042",
"fileHash": "79dbdbb7",
"needsInterop": false
},
"vitepress > @vueuse/integrations/useFocusTrap": {
"src": "../../../../node_modules/@vueuse/integrations/useFocusTrap.mjs",
"file": "vitepress___@vueuse_integrations_useFocusTrap.js",
"fileHash": "db69e302",
"fileHash": "d79d933d",
"needsInterop": false
},
"vitepress > mark.js/src/vanilla.js": {
"src": "../../../../node_modules/mark.js/src/vanilla.js",
"file": "vitepress___mark__js_src_vanilla__js.js",
"fileHash": "c58bc9e8",
"fileHash": "7365f851",
"needsInterop": false
},
"vitepress > minisearch": {
"src": "../../../../node_modules/minisearch/dist/es/index.js",
"file": "vitepress___minisearch.js",
"fileHash": "68cd52da",
"fileHash": "fa341363",
"needsInterop": false
}
},
Expand Down
29 changes: 1 addition & 28 deletions .docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
import { defineConfig } from 'vitepress';
import { readdirSync, copyFileSync, cpSync, mkdirSync, existsSync, rm } from 'fs';
import * as path from 'node:path';

const workflowDirs = readdirSync(path.join(__dirname, '../..'), { withFileTypes: true })
.filter(item => item.isDirectory() && item.name.match(/^(?!\.)/) && !item.name.includes('node_modules'));

function initWorkflows() {
if (existsSync(path.join(__dirname, '../../.docs/workflows'))) {
rm(path.join(__dirname, '../../.docs/workflows/'), { recursive: true, force: true });
} else {
mkdirSync(path.join(__dirname, '../../.docs/workflows'));
}
}

function createWorkflowDocs(dirs) {
dirs.forEach(item => {
mkdirSync(path.join(__dirname, `../../.docs/workflows/${item.name}`));
copyFileSync(path.join(__dirname, `../../${item.name}/README.md`),
path.join(__dirname, `../../.docs/workflows/${item.name}/${item.name}.md`));
if (existsSync(path.join(__dirname, `../../${item.name}/screenshots`))) {
cpSync(path.join(__dirname, `../../${item.name}/screenshots`),
path.join(__dirname, `../../.docs/workflows/${item.name}/screenshots`), { recursive: true });
}
});
}

initWorkflows();
createWorkflowDocs(workflowDirs);
import { workflowDirs } from '../init-md.mjs';

// https://vitepress.dev/reference/site-config
export default defineConfig({
Expand Down
41 changes: 41 additions & 0 deletions .docs/init-md.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { copyFileSync, cpSync, existsSync, mkdirSync, readdirSync, rm } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'url';

const __dirname = path.join(path.dirname(fileURLToPath(import.meta.url)), '../');

console.log('__dirname', __dirname);

const workflowDirs = readdirSync(path.join(__dirname), {withFileTypes: true})
.filter(item => item.isDirectory() && item.name.match(/^(?!\.)/) && !item.name.includes('node_modules'));

console.log('workflowDirs', workflowDirs);


function initWorkflows() {
if (existsSync(path.join(__dirname, '.docs/workflows'))) {
rm(path.join(__dirname, '.docs/workflows/'), () => {

});
} else {
mkdirSync(path.join(__dirname, '.docs/workflows'));
}
}

function createWorkflowDocs(dirs) {
dirs.forEach(item => {
if (!existsSync(path.join(__dirname, `.docs/workflows/${item.name}`))) {
mkdirSync(path.join(__dirname, `.docs/workflows/${item.name}`));
}
copyFileSync(path.join(__dirname, `${item.name}/README.md`), path.join(__dirname, `.docs/workflows/${item.name}/${item.name}.md`));

if (existsSync(path.join(__dirname, `${item.name}/screenshots`))) {
cpSync(path.join(__dirname, `${item.name}/screenshots`), path.join(__dirname, `.docs/workflows/${item.name}/screenshots`), {recursive: true});
}
});
}

initWorkflows();
createWorkflowDocs(workflowDirs);

export { workflowDirs };
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: build docs
name: Build docs

on:
push:
Expand Down Expand Up @@ -31,8 +31,8 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: |
npm install
npm run docs:dev
npm install
npm run docs:initmd
npm run docs:build
- name: Build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: main
name: Update Workflow Version

on:
push:
Expand Down
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"vitepress": "^1.4.3"
},
"scripts": {
"docs:initmd": "node .docs/init-md.mjs",
"docs:dev": "vitepress dev .docs",
"docs:build": "vitepress build .docs",
"docs:preview": "vitepress preview .docs"
}
}
}

0 comments on commit 6ff4ffa

Please sign in to comment.