Skip to content

Commit 36b56e3

Browse files
authored
feat: 增加演示Demo展示入口,优化配置文件 (#173)
* feat: 支持示例项目的显示 * feat: 支持示例项目的显示 * feat: 增加演示Demo展示入口,优化配置文件 * chore: update
1 parent 0b2ac8e commit 36b56e3

File tree

6 files changed

+63
-16
lines changed

6 files changed

+63
-16
lines changed

.github/workflows/CI.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# 代码检查
21
name: CI
32

43
# 触发条件
54
on:
6-
# 提PR到next分支触发CI
75
pull_request:
86
branches:
97
- next
@@ -55,9 +53,9 @@ jobs:
5553
./scripts/ci
5654
5755
# Eslint 检测
58-
# - name: Code LintFix By ESLint
59-
# run: |
60-
# npx eslint .
56+
- name: Code LintFix By ESLint
57+
run: |
58+
pnpm lint
6159
6260
# 编辑模块代码
6361
- name: Build Package Code

.vitepress/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ export default defineConfig({
140140
rewrites: {
141141
':packages/:pkg/README.md': ':packages/:pkg/index.md',
142142
':packages/:pkg/CHANGELOG.md': 'changelogs/:pkg/changelog.md',
143+
':apps/:pkg/README.md': ':apps/:pkg/index.md',
144+
':apps/:pkg/CHANGELOG.md': 'changelogs/:pkg/changelog.md',
143145
'CHANGELOG.md': 'changelogs/core-x/changelog.md',
144146
'README.md': 'index.md',
145147
},
@@ -148,6 +150,7 @@ export default defineConfig({
148150
resolve: {
149151
alias: {
150152
'@packages': path.resolve(__dirname, '../packages'),
153+
'@apps': path.resolve(__dirname, '../apps'),
151154
},
152155
},
153156
plugins: [

.vitepress/sidebar.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum ProjectId {
88
Nest = 'Nest.js框架',
99
Blog = '博客工具',
1010
Infra = '工程化',
11+
Demo = '演示Demo',
1112
}
1213

1314
/**
@@ -61,24 +62,47 @@ export const sidebarConfig: DefaultTheme.SidebarItem[] = [
6162
{ text: '@142vip/vuepress', link: '/packages/vuepress/index.md' },
6263
],
6364
},
65+
{
66+
text: `🎮 ${ProjectId.Demo}`,
67+
items: [
68+
{ text: 'vitepress-demo', link: '/apps/vitepress-demo/index.md' },
69+
{ text: 'vuepress-demo', link: '/apps/vuepress-demo/index.md' },
70+
],
71+
},
6472
]
6573

6674
/**
6775
* 获取基本包信息
6876
* - 注意目录格式,例如:@packages/utils
6977
*/
7078
async function getBasePkgJSON(pkgDirName: string) {
79+
// 参考格式:@packages/xxx @apps/xxx
80+
7181
const pkgJSON = await import(`@packages/${pkgDirName}/package.json`)
7282
return pick(pkgJSON, ['name', 'description', 'version', 'private'])
7383
}
7484

85+
/**
86+
* 获取apps目录下的模块
87+
* - @apps/vitepress-demo
88+
*/
89+
async function getAppsPkgJSON(pkgDirName: string) {
90+
// 参考格式:@packages/xxx @apps/xxx
91+
const pkgJSON = await import(`@apps/${pkgDirName}/package.json`)
92+
return pick(pkgJSON, ['name', 'description', 'version', 'private'])
93+
}
94+
7595
/**
7696
* 动态获取模块信息
7797
* - 注意:遍历侧边栏
7898
*/
7999
export async function getCoreProjectData(): Promise<VipProject[]> {
80100
const coreProjects: VipProject[] = []
81101
for (const { items, text } of sidebarConfig) {
102+
// 过滤掉apps下的模块
103+
if (text?.includes(ProjectId.Demo)) {
104+
continue
105+
}
82106
for (const { text: pkgName } of items) {
83107
const pkgDirName = pkgName.split('@142vip/')[1]
84108
const basePkg = await getBasePkgJSON(`${pkgDirName}`)
@@ -95,14 +119,36 @@ export async function getCoreProjectData(): Promise<VipProject[]> {
95119
return coreProjects
96120
}
97121

122+
/**
123+
* demo项目
124+
*/
125+
export async function getExampleDemoTableData() {
126+
const pkgNames = ['vuepress-demo', 'vitepress-demo']
127+
128+
const exampleDemos = []
129+
for (const pkgDirName of pkgNames) {
130+
const pkg = await getAppsPkgJSON(`${pkgDirName}`)
131+
exampleDemos.push({
132+
...pkg,
133+
private: true,
134+
id: '🤡',
135+
changelog: `../apps/${pkgDirName}/changelog.html`,
136+
readme: `../apps/${pkgDirName}/index.html`,
137+
sourceCode: `https://github.com/142vip/core-x/tree/main/apps/${pkgDirName}/`,
138+
})
139+
}
140+
return exampleDemos
141+
}
142+
98143
/**
99144
* 根据侧边栏获取变更日志侧边栏
100145
*/
101146
export function getChangelogsSidebar() {
102147
const changelogsSidebar: DefaultTheme.SidebarItem[] = []
103148
for (const { items } of sidebarConfig) {
104149
for (const { text: pkgName } of items) {
105-
const pkgDirName = pkgName.split('@142vip/')[1]
150+
// 兼容apps目录
151+
const pkgDirName = pkgName?.includes('@142vip') ? pkgName.split('@142vip/')[1] : pkgName
106152
changelogsSidebar.push({
107153
text: pkgName,
108154
link: `/changelogs/${pkgDirName}/changelog.md`,

.vitepress/theme/components/HomePage.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import {
88
} from '@142vip/vitepress/components'
99
import { useData } from 'vitepress'
1010
import { ElImage } from 'element-plus'
11-
import { getCoreProjectData } from '../../sidebar'
11+
import { getCoreProjectData, getExampleDemoTableData } from '../../sidebar'
1212
1313
const { isDark } = useData()
14-
const tableData = ref<any[]>([])
14+
const coreProjectTableData = ref<any[]>([])
15+
const exampleDemoTableData = ref()
1516
1617
defineComponent({
1718
components: {
@@ -23,14 +24,16 @@ defineComponent({
2324
* 异步加载表格数据
2425
*/
2526
onMounted(async () => {
26-
tableData.value = await getCoreProjectData()
27+
coreProjectTableData.value = await getCoreProjectData()
28+
exampleDemoTableData.value = await getExampleDemoTableData()
2729
})
2830
</script>
2931

3032
<!-- 首页 -->
3133
<template>
3234
<section id="version-table">
33-
<VipProjectTable :data="tableData" title="开源" />
35+
<VipProjectTable :data="exampleDemoTableData" title="演示Demo" />
36+
<VipProjectTable :data="coreProjectTableData" title="开源模块" />
3437
</section>
3538

3639
<VipTeam />

apps/vitepress-demo/CHANGELOG.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ All notable changes to this project will be documented in this file. See [commit
44

55
<!-- #region recent-alpha -->
66

7-
8-
9-
<!-- #endregion recent-alpha -->
10-
117
## v0.0.1-alpha.1 (2024-10-17)
128

139
### ✨ Features
1410

1511
- 增加`vitepress-demo`演示模块,简化`@142vip/vitepress`模块使用配置 &nbsp;-&nbsp; by **chufan** [<samp>(f6797)</samp>](https://github.com/142vip/core-x/commit/f679759)
1612

17-
**Release New Version v0.0.1-alpha.1 [👉 View New Package On NPM](https://www.npmjs.com/package/vitepress-demo)**
13+
**Release New Version v0.0.1-alpha.1 [👉 View New Package On NPM](https://www.npmjs.com/package/vitepress-demo)**
14+
15+
<!-- #endregion recent-alpha -->

apps/vuepress-demo/vuepress.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export default defineUserConfig({
3838
return str
3939
},
4040
},
41-
// md doc formatter headerDepth
4241
headers: {
4342
level: [2, 3, 4],
4443
},

0 commit comments

Comments
 (0)