Skip to content

Commit

Permalink
feat: 增加演示Demo展示入口,优化配置文件 (#173)
Browse files Browse the repository at this point in the history
* feat: 支持示例项目的显示

* feat: 支持示例项目的显示

* feat: 增加演示Demo展示入口,优化配置文件

* chore: update
  • Loading branch information
mmdapl authored Oct 18, 2024
1 parent 0b2ac8e commit 36b56e3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 16 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# 代码检查
name: CI

# 触发条件
on:
# 提PR到next分支触发CI
pull_request:
branches:
- next
Expand Down Expand Up @@ -55,9 +53,9 @@ jobs:
./scripts/ci
# Eslint 检测
# - name: Code LintFix By ESLint
# run: |
# npx eslint .
- name: Code LintFix By ESLint
run: |
pnpm lint
# 编辑模块代码
- name: Build Package Code
Expand Down
3 changes: 3 additions & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ export default defineConfig({
rewrites: {
':packages/:pkg/README.md': ':packages/:pkg/index.md',
':packages/:pkg/CHANGELOG.md': 'changelogs/:pkg/changelog.md',
':apps/:pkg/README.md': ':apps/:pkg/index.md',
':apps/:pkg/CHANGELOG.md': 'changelogs/:pkg/changelog.md',
'CHANGELOG.md': 'changelogs/core-x/changelog.md',
'README.md': 'index.md',
},
Expand All @@ -148,6 +150,7 @@ export default defineConfig({
resolve: {
alias: {
'@packages': path.resolve(__dirname, '../packages'),
'@apps': path.resolve(__dirname, '../apps'),
},
},
plugins: [
Expand Down
48 changes: 47 additions & 1 deletion .vitepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum ProjectId {
Nest = 'Nest.js框架',
Blog = '博客工具',
Infra = '工程化',
Demo = '演示Demo',
}

/**
Expand Down Expand Up @@ -61,24 +62,47 @@ export const sidebarConfig: DefaultTheme.SidebarItem[] = [
{ text: '@142vip/vuepress', link: '/packages/vuepress/index.md' },
],
},
{
text: `🎮 ${ProjectId.Demo}`,
items: [
{ text: 'vitepress-demo', link: '/apps/vitepress-demo/index.md' },
{ text: 'vuepress-demo', link: '/apps/vuepress-demo/index.md' },
],
},
]

/**
* 获取基本包信息
* - 注意目录格式,例如:@packages/utils
*/
async function getBasePkgJSON(pkgDirName: string) {
// 参考格式:@packages/xxx @apps/xxx

const pkgJSON = await import(`@packages/${pkgDirName}/package.json`)
return pick(pkgJSON, ['name', 'description', 'version', 'private'])
}

/**
* 获取apps目录下的模块
* - @apps/vitepress-demo
*/
async function getAppsPkgJSON(pkgDirName: string) {
// 参考格式:@packages/xxx @apps/xxx
const pkgJSON = await import(`@apps/${pkgDirName}/package.json`)
return pick(pkgJSON, ['name', 'description', 'version', 'private'])
}

/**
* 动态获取模块信息
* - 注意:遍历侧边栏
*/
export async function getCoreProjectData(): Promise<VipProject[]> {
const coreProjects: VipProject[] = []
for (const { items, text } of sidebarConfig) {
// 过滤掉apps下的模块
if (text?.includes(ProjectId.Demo)) {
continue
}
for (const { text: pkgName } of items) {
const pkgDirName = pkgName.split('@142vip/')[1]
const basePkg = await getBasePkgJSON(`${pkgDirName}`)
Expand All @@ -95,14 +119,36 @@ export async function getCoreProjectData(): Promise<VipProject[]> {
return coreProjects
}

/**
* demo项目
*/
export async function getExampleDemoTableData() {
const pkgNames = ['vuepress-demo', 'vitepress-demo']

const exampleDemos = []
for (const pkgDirName of pkgNames) {
const pkg = await getAppsPkgJSON(`${pkgDirName}`)
exampleDemos.push({
...pkg,
private: true,
id: '🤡',
changelog: `../apps/${pkgDirName}/changelog.html`,
readme: `../apps/${pkgDirName}/index.html`,
sourceCode: `https://github.com/142vip/core-x/tree/main/apps/${pkgDirName}/`,
})
}
return exampleDemos
}

/**
* 根据侧边栏获取变更日志侧边栏
*/
export function getChangelogsSidebar() {
const changelogsSidebar: DefaultTheme.SidebarItem[] = []
for (const { items } of sidebarConfig) {
for (const { text: pkgName } of items) {
const pkgDirName = pkgName.split('@142vip/')[1]
// 兼容apps目录
const pkgDirName = pkgName?.includes('@142vip') ? pkgName.split('@142vip/')[1] : pkgName
changelogsSidebar.push({
text: pkgName,
link: `/changelogs/${pkgDirName}/changelog.md`,
Expand Down
11 changes: 7 additions & 4 deletions .vitepress/theme/components/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {
} from '@142vip/vitepress/components'
import { useData } from 'vitepress'
import { ElImage } from 'element-plus'
import { getCoreProjectData } from '../../sidebar'
import { getCoreProjectData, getExampleDemoTableData } from '../../sidebar'
const { isDark } = useData()
const tableData = ref<any[]>([])
const coreProjectTableData = ref<any[]>([])
const exampleDemoTableData = ref()
defineComponent({
components: {
Expand All @@ -23,14 +24,16 @@ defineComponent({
* 异步加载表格数据
*/
onMounted(async () => {
tableData.value = await getCoreProjectData()
coreProjectTableData.value = await getCoreProjectData()
exampleDemoTableData.value = await getExampleDemoTableData()
})
</script>

<!-- 首页 -->
<template>
<section id="version-table">
<VipProjectTable :data="tableData" title="开源" />
<VipProjectTable :data="exampleDemoTableData" title="演示Demo" />
<VipProjectTable :data="coreProjectTableData" title="开源模块" />
</section>

<VipTeam />
Expand Down
8 changes: 3 additions & 5 deletions apps/vitepress-demo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ All notable changes to this project will be documented in this file. See [commit

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



<!-- #endregion recent-alpha -->

## v0.0.1-alpha.1 (2024-10-17)

### ✨ Features

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

**Release New Version v0.0.1-alpha.1 [👉 View New Package On NPM](https://www.npmjs.com/package/vitepress-demo)**
**Release New Version v0.0.1-alpha.1 [👉 View New Package On NPM](https://www.npmjs.com/package/vitepress-demo)**

<!-- #endregion recent-alpha -->
1 change: 0 additions & 1 deletion apps/vuepress-demo/vuepress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default defineUserConfig({
return str
},
},
// md doc formatter headerDepth
headers: {
level: [2, 3, 4],
},
Expand Down

0 comments on commit 36b56e3

Please sign in to comment.