Skip to content

Commit ebae8a4

Browse files
Azir-11honghuangdc
authored andcommitted
feat(projects): add Soybean UI development guide and Nuxt.js document… (#74)
…ation website construction plan. 目前已迁移完soy-ui的源码和demos,目前留着example是因为vitepress里有引用文件,在official-site完善后会删除
1 parent d6bcaf6 commit ebae8a4

File tree

500 files changed

+2214
-902
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

500 files changed

+2214
-902
lines changed

DEVELOPMENT_GUIDE.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# Soybean UI 开发指南
2+
3+
本文档旨在为 Soybean UI 项目提供一套从组件研发到文档生成的最佳实践,借鉴了业界优秀组件库 (如 Ant Design, Naive UI) 的经验,并力求简化开发流程、提高开发效率。
4+
5+
## 1. 核心理念
6+
7+
* **组件、示例、文档一体化**: 每个组件相关的源代码、使用示例 (demos) 和 Markdown API 文档应集中管理在其各自的目录中,方便开发、维护和查阅。
8+
* **专用开发预览**: 提供一个独立的开发预览环境,使开发者能快速、便捷地查看和调试正在开发的组件及其所有示例。
9+
* **文档驱动**: 组件的 `demos``API 文档` 直接作为最终用户文档的来源,由文档站点 (如 Nuxt) 解析和渲染。
10+
11+
## 2. 推荐项目结构
12+
13+
```
14+
soybean-ui/
15+
├── packages/
16+
│ ├── soy-ui/ # 核心 UI 组件库 (可发布为 npm 包)
17+
│ │ ├── src/
18+
│ │ │ ├── components/ # 所有 UI 组件
19+
│ │ │ │ ├── Alert/ # Alert 组件示例目录
20+
│ │ │ │ │ ├── source/ # 源码文件夹
21+
│ │ │ │ │ │ ├── Alert.vue # Alert 组件源文件
22+
│ │ │ │ │ ├── demos/ # Alert 组件的示例
23+
│ │ │ │ │ │ ├── basic.vue
24+
│ │ │ │ │ │ ├── with-icon.vue
25+
│ │ │ │ │ │ └── index.ts # 导出此目录下所有 demo 组件
26+
│ │ │ │ │ ├── index.md # Alert 组件的 Markdown 文档 (API, 用法说明)
27+
│ │ │ │ │ └── types.ts # Alert 组件的类型定义 (可选)
28+
│ │ │ │ ├── Button/
29+
│ │ │ │ │ ├── source/ # 源码文件夹
30+
│ │ │ │ │ │ └── Button.vue
31+
│ │ │ │ │ ├── demos/
32+
│ │ │ │ │ │ └── basic.vue
33+
│ │ │ │ │ └── index.md
34+
│ │ │ │ └── ... (其他组件)
35+
│ │ │ ├── index.ts # 组件库入口,导出所有组件
36+
│ │ │ └── theme/ # 全局主题、样式等
37+
│ │ ├── package.json
38+
│ │ └── vite.config.ts
39+
│ ├── primitives/ # 基础工具/原子组件 (如果需要)
40+
│ └── unocss-preset/ # UnoCSS 预设
41+
├── apps/ # 应用/示例项目
42+
│ ├── playground/ # 组件开发预览环境 (Vite + Vue)
43+
│ │ ├── src/
44+
│ │ │ ├── App.vue
45+
│ │ │ ├── main.ts
46+
│ │ │ ├── pages/ # 动态加载 soy-ui 组件 demos 的页面
47+
│ │ │ └── router.ts
48+
│ │ ├── package.json
49+
│ │ └── vite.config.ts
50+
│ └── official-site/ (原Nuxt 文档站)
51+
│ ├── components/ # 文档站自身的组件
52+
│ ├── layouts/
53+
│ ├── pages/ # Nuxt 页面,包括动态路由用于渲染组件文档
54+
│ │ └── components/
55+
│ │ └── [...slug].vue # 捕获组件名并渲染对应文档和 demos
56+
│ ├── nuxt.config.ts
57+
│ └── package.json
58+
├── scripts/ # 构建、生成等脚本
59+
├── package.json # Monorepo 根 package.json
60+
├── tsconfig.json
61+
└── DEVELOPMENT_GUIDE.md # 本开发指南
62+
└── NUXT_DOCS_SETUP_PLAN.md # Nuxt 文档站搭建计划
63+
```
64+
65+
**说明:**
66+
67+
* **`packages/soy-ui`**: 这是核心组件库。
68+
* 每个组件 (如 `Alert`, `Button`) 都有自己的文件夹。
69+
* `demos/` 文件夹存放该组件的 `.vue` 格式使用示例,并通过一个 `index.ts` 文件导出所有这些示例。
70+
* `index.md` 是该组件的文档,用于描述 API、props、events、slots 以及如何使用。它可以直接引用或内嵌 `demos/` 中的示例。
71+
* **`apps/playground`**: 一个独立的 Vite/Vue3 应用。
72+
* 其主要目的是在开发 `soy-ui` 组件时,提供一个实时预览和调试的环境。
73+
* 它可以动态扫描 `packages/soy-ui/src/components/**/demos/index.ts` 文件,并提供一个界面来选择和展示这些 demos 模块中导出的所有组件。
74+
* 这将取代当前 `src/views/ui/index.vue``examples/` 目录的部分功能,使组件开发与主项目/其他示例项目解耦。
75+
* **`apps/official-site` (原 `docs_v2`)**: 基于 Nuxt 的官方文档站。
76+
* 它会读取 `packages/soy-ui/src/components/**/index.md` 作为 API 文档内容。
77+
* 它会解析并渲染 `packages/soy-ui/src/components/**/demos/*.vue` 作为交互式示例。
78+
79+
## 3. 开发新组件流程
80+
81+
1. **创建组件目录**:
82+
`packages/soy-ui/src/components/` 下创建新的组件文件夹,例如 `MyNewComponent`
83+
2. **编写组件源码**:
84+
`MyNewComponent/` 下创建 `MyNewComponent.vue` 文件,并实现组件逻辑。
85+
3. **编写示例 (Demos)**:
86+
`MyNewComponent/demos/` 目录下创建 `.vue` 示例文件,如:
87+
* `basic.vue` (基础用法)
88+
* `advanced-features.vue` (高级特性展示)
89+
每个 demo 都应该是一个可以独立运行和展示特定用法的 Vue 组件。
90+
同时,在该目录下创建一个 `index.ts` 文件,导出所有 `.vue` 示例。例如:
91+
```typescript
92+
// MyNewComponent/demos/index.ts
93+
export { default as BasicDemo } from './basic.vue';
94+
export { default as AdvancedFeaturesDemo } from './advanced-features.vue';
95+
```
96+
4. **编写组件文档**:
97+
`MyNewComponent/` 下创建 `index.md` 文件。内容应包括:
98+
* 组件简介和用途。
99+
* Props, Events, Slots, MethodsAPI 表格和说明。
100+
* 通过特定语法嵌入或引用 `demos/` 中的示例,并配以说明。
101+
* 设计规范、最佳实践等。
102+
5. **导出组件**:
103+
`packages/soy-ui/src/index.ts` (或相应的入口文件) 中导出新组件。
104+
6. **Playground 中预览和调试**:
105+
* 启动 `apps/playground` 开发服务器。
106+
* Playground 应能自动发现新的 `MyNewComponent` 及其 `demos/index.ts`
107+
* Playground 会加载 `index.ts` 模块,并展示其中导出的所有 demo 组件。
108+
* 通过 Playground 交互式地测试组件的各种状态和 props
109+
7. **更新文档站 (可选,通常自动)**:
110+
* 启动 `apps/official-site` (Nuxt 文档站) 开发服务器。
111+
* 文档站应能自动发现并展示新组件的 `index.md`demos
112+
113+
## 4. 运行开发环境
114+
115+
* **启动 Playground (用于组件开发)**:
116+
```bash
117+
pnpm --filter ./apps/playground dev
118+
```
119+
(假设 `apps/playground/package.json` 中定义了 `dev` 脚本)
120+
121+
* **启动文档站 (用于预览最终文档)**:
122+
```bash
123+
pnpm --filter ./apps/official-site dev
124+
```
125+
(假设 `apps/official-site/package.json` 中定义了 `dev` 脚本)
126+
127+
## 5. 编写与组织 Demos
128+
129+
* **原子性**: 每个 demo `.vue` 文件应专注于展示组件的一个特定功能或用例。
130+
* **简洁性**: Demo 代码应尽可能简洁明了,移除不相关的逻辑。
131+
* **可直接运行**: Demo 本身就是一个完整的 Vue 组件片段,可以直接在 Playground 或文档中渲染。
132+
* **命名清晰**: Demo 文件名应能清晰反映其展示的内容,如 `disabled-state.vue`, `custom-icon.vue`。导出到 `index.ts` 时也建议使用清晰的导出名 (如 `BasicDemo`, `CustomIconDemo`)。
133+
* **`index.ts` 聚合**: 每个组件的 `demos` 目录下应包含一个 `index.ts` 文件,该文件负责导出目录内所有的 `.vue` demo 组件。这使得 Playground 或其他工具可以方便地一次性导入所有相关的 demos
134+
135+
## 6. 文档编写 (Markdown)
136+
137+
* 组件的 `index.md` 是其官方文档的核心。
138+
* **API 文档**: 清晰列出 Props, Events, Slots, Methods 等,并提供类型、默认值和描述。
139+
* **代码示例**: 使用 Markdown 的代码块语法展示简短的用法片段。
140+
* **嵌入 Demos**:
141+
文档站 (Nuxt) 需要实现一种机制,允许在 Markdown 中通过特定语法引用并渲染 `demos/` 目录下的 `.vue` 文件。例如:
142+
```markdown
143+
## 基础用法
144+
145+
<Demo src="basic.vue" title="基础的 Alert 组件" />
146+
147+
## 带图标的 Alert
148+
149+
<Demo src="with-icon.vue" description="可以配置不同的图标类型。" />
150+
```
151+
这里的 `<Demo>` 是一个需要在 Nuxt 文档站中实现的自定义组件,它会加载并显示对应的 demo 文件,并可能提供查看源码、复制代码等功能。
152+
153+
## 7. 废弃 `examples/` 目录
154+
155+
当前的 `examples/` 目录的功能将被以下两者取代:
156+
157+
1. **组件级 Demos**: 分散到 `packages/soy-ui/src/components/<ComponentName>/demos/` 中。
158+
2. **Playground 应用**: `apps/playground/` 提供集中的组件开发和预览环境。
159+
160+
如果 `examples/` 还承载了其他更复杂的集成示例或项目模板,可以考虑将其保留并重命名,或者将其内容迁移到 `apps/` 目录下作为单独的示例项目。
161+
162+
## 8. 总结
163+
164+
通过上述结构和流程调整,期望可以:
165+
166+
* **降低维护成本**: 组件代码、示例和文档物理上更接近,修改和同步更容易。
167+
* **提升开发体验**: Playground 为组件开发提供即时反馈。
168+
* **改善文档质量**: Demos 直接来源于开发过程,保证了示例的准确性和实用性。
169+
* **清晰的职责分离**: `soy-ui` 聚焦于组件实现,`playground` 聚焦于开发预览,`official-site` 聚焦于最终用户文档。

NUXT_DOCS_SETUP_PLAN.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Nuxt.js Documentation Site Setup Plan for Soybean UI
2+
3+
This document outlines the steps and considerations for building the new documentation website for Soybean UI using Nuxt.js. The goal is to create a modern, performant, and maintainable documentation site, inspired by sites like Shadcn UI, while also incorporating multi-language support.
4+
5+
## Phase 1: Project Setup and Basic Structure
6+
7+
1. **Initialize Nuxt Project:**
8+
* Create a new Nuxt project within the `apps/official-site` directory (as defined in `DEVELOPMENT_GUIDE.md`).
9+
* Command: `pnpm dlx nuxi@latest init apps/official-site`
10+
* Choose appropriate settings (TypeScript, package manager pnpm).
11+
12+
2. **Basic Layout and Pages:**
13+
* Design a default layout (`layouts/default.vue`) including a header, sidebar (for navigation), and a main content area.
14+
* Create an initial `pages/index.vue` for the homepage.
15+
* Set up basic routing.
16+
17+
3. **Integrate UnoCSS:**
18+
* Add UnoCSS to the Nuxt project for styling, leveraging `@soybean-ui/unocss-preset` if possible or creating a compatible configuration.
19+
* Ensure UnoCSS works correctly within Nuxt components and Markdown-generated content.
20+
21+
4. **Directory Structure for Content:**
22+
* Confirm the strategy for sourcing component documentation:
23+
* Markdown files: `packages/soy-ui/src/components/<ComponentName>/index.md`
24+
* Demo files: `packages/soy-ui/src/components/<ComponentName>/demos/*.vue`
25+
26+
## Phase 2: Content Rendering and Component Integration
27+
28+
1. **Markdown Rendering:**
29+
* Choose and configure a Nuxt module for Markdown rendering (e.g., `@nuxt/content`).
30+
* Ensure it can parse frontmatter from `index.md` files for metadata (title, description, etc.).
31+
* Style the rendered HTML output to match the design.
32+
33+
2. **Dynamic Component Pages:**
34+
* Create a dynamic route, e.g., `pages/components/[...slug].vue`.
35+
* This page will fetch and render the `index.md` content for the corresponding component based on the slug.
36+
* The slug should map to component names (e.g., `alert`, `button`).
37+
38+
3. **Demo Rendering (`<Demo>` Component):**
39+
* Develop a global Nuxt component (e.g., `<DemoViewer />` or similar name as `<Demo>` in `DEVELOPMENT_GUIDE.md`).
40+
* This component will be used within Markdown files to embed live demos.
41+
* It should dynamically load and render `.vue` demo files from `packages/soy-ui/src/components/<ComponentName>/demos/<demoName>.vue`.
42+
* Features for `<DemoViewer />`:
43+
* Display the rendered demo.
44+
* Option to view the source code of the demo.
45+
* Option to copy the source code.
46+
* Potentially link to a playground environment (e.g., StackBlitz, CodeSandbox, or the local `apps/playground`).
47+
48+
4. **Automatic Navigation/Sidebar Generation:**
49+
* The sidebar should list all available components, grouped категоріями (if applicable).
50+
* This list should be generated dynamically by scanning the `packages/soy-ui/src/components/` directory or from a configuration file.
51+
* Clicking a component name should navigate to its documentation page.
52+
53+
## Phase 3: Enhancements and Features
54+
55+
1. **Search Functionality:**
56+
* Implement search across component documentation (API, descriptions).
57+
* Consider using `@nuxt/content`'s built-in search or integrating a service like Algolia.
58+
59+
2. **Multi-language Support (i18n):**
60+
* Integrate `@nuxtjs/i18n` or a similar Nuxt i18n module.
61+
* Plan the structure for translated Markdown content and demo descriptions.
62+
* Option 1: `index.en.md`, `index.zh.md`
63+
* Option 2: Subdirectories per locale, e.g., `en/index.md`, `zh/index.md`.
64+
* Implement a language switcher UI element.
65+
* Ensure demos and their textual descriptions can also be localized if necessary.
66+
67+
3. **Theme Customization (Dark Mode, Primary Color):**
68+
* Implement a theme switcher for dark/light mode, similar to the current setup.
69+
* Allow users to preview components with different primary colors (if this is a feature of `soy-ui`). This might involve dynamic CSS variable changes.
70+
71+
4. **SEO and Meta Tags:**
72+
* Ensure proper meta tags (title, description) are generated for each page.
73+
* Utilize Nuxt's head management features.
74+
75+
5. **Shadcn UI Inspired Design:**
76+
* Adopt a clean, modern aesthetic similar to `ui.shadcn.com`.
77+
* Focus on typography, spacing, and overall user experience.
78+
* The `<DemoViewer />` component should be a key focus for a polished look and feel.
79+
80+
## Phase 4: Build, Deployment, and Maintenance
81+
82+
1. **Static Site Generation (SSG):**
83+
* Configure Nuxt for full static site generation for optimal performance.
84+
* Command: `pnpm --filter ./apps/official-site generate` (or similar, based on Nuxt version).
85+
86+
2. **Deployment:**
87+
* Choose a hosting platform (e.g., Vercel, Netlify, GitHub Pages).
88+
* Set up CI/CD pipeline to automatically build and deploy the site on changes to the `main` branch or specific documentation-related branches/tags.
89+
90+
3. **Maintenance Plan:**
91+
* Document how to add new component documentation.
92+
* Keep Nuxt and its dependencies updated.
93+
94+
## Key Technologies and Modules (Tentative)
95+
96+
* **Framework:** Nuxt.js 3
97+
* **Styling:** UnoCSS (with `@soybean-ui/unocss-preset`)
98+
* **Content:** `@nuxt/content` (or alternative Markdown/Vue component rendering solution)
99+
* **i18n:** `@nuxtjs/i18n`
100+
* **State Management (if needed):** Pinia (comes with Nuxt 3)
101+
* **UI Components (for the docs site itself):** Potentially use `soy-ui` components if stable, or build simple ones.
102+
103+
## Open Questions / Decisions to be Made
104+
105+
* Exact mechanism for the `<Demo>` component to resolve and load `.vue` demo files from a different package (`packages/soy-ui`) within the Nuxt app (`apps/official-site`). This might involve Vite/Nuxt configuration for aliasing or custom loaders/plugins.
106+
* Strategy for managing API tables in Markdown (manual, or generated from JSDoc/TSDoc comments).
107+
* Specific UI design details and component choices for the documentation site itself.
108+
109+
This plan will be updated as the project progresses.

apps/official-site/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Nuxt dev/build outputs
2+
.output
3+
.data
4+
.nuxt
5+
.nitro
6+
.cache
7+
dist
8+
9+
# Node dependencies
10+
node_modules
11+
12+
# Logs
13+
logs
14+
*.log
15+
16+
# Misc
17+
.DS_Store
18+
.fleet
19+
.idea
20+
21+
# Local env files
22+
.env
23+
.env.*
24+
!.env.example

apps/official-site/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Nuxt Minimal Starter
2+
3+
Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
4+
5+
## Setup
6+
7+
Make sure to install dependencies:
8+
9+
```bash
10+
# npm
11+
npm install
12+
13+
# pnpm
14+
pnpm install
15+
16+
# yarn
17+
yarn install
18+
19+
# bun
20+
bun install
21+
```
22+
23+
## Development Server
24+
25+
Start the development server on `http://localhost:3000`:
26+
27+
```bash
28+
# npm
29+
npm run dev
30+
31+
# pnpm
32+
pnpm dev
33+
34+
# yarn
35+
yarn dev
36+
37+
# bun
38+
bun run dev
39+
```
40+
41+
## Production
42+
43+
Build the application for production:
44+
45+
```bash
46+
# npm
47+
npm run build
48+
49+
# pnpm
50+
pnpm build
51+
52+
# yarn
53+
yarn build
54+
55+
# bun
56+
bun run build
57+
```
58+
59+
Locally preview production build:
60+
61+
```bash
62+
# npm
63+
npm run preview
64+
65+
# pnpm
66+
pnpm preview
67+
68+
# yarn
69+
yarn preview
70+
71+
# bun
72+
bun run preview
73+
```
74+
75+
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.

apps/official-site/app.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<template>
2+
<div>
3+
<NuxtRouteAnnouncer />
4+
<NuxtWelcome />
5+
</div>
6+
</template>

apps/official-site/nuxt.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// https://nuxt.com/docs/api/configuration/nuxt-config
2+
export default defineNuxtConfig({
3+
compatibilityDate: '2024-11-01',
4+
devtools: { enabled: true }
5+
})

0 commit comments

Comments
 (0)