@lmy54321/design-system 1.1.4 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,46 @@ provider:
16
16
 
17
17
  ## 自动执行步骤
18
18
 
19
+ ### 0. 环境检测(新电脑必须先过这一关)
20
+
21
+ 在执行任何操作前,**自动检测**以下依赖,缺什么装什么,全程自动,不要让用户手动操作:
22
+
23
+ #### 检测 Node.js
24
+ ```bash
25
+ node -v
26
+ ```
27
+ - 如果命令不存在或版本 < 18:
28
+ - **macOS**:先检查 `brew -v`,如果没有 Homebrew,先安装:
29
+ ```bash
30
+ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
31
+ ```
32
+ 然后安装 Node.js:
33
+ ```bash
34
+ brew install node
35
+ ```
36
+ - **Windows**:通过 winget 安装(Windows 10/11 自带):
37
+ ```bash
38
+ winget install OpenJS.NodeJS.LTS --accept-source-agreements --accept-package-agreements
39
+ ```
40
+ 如果 winget 不可用,提示用户前往 https://nodejs.org 下载 LTS 版本安装包,安装后重启 CodeBuddy。
41
+ - **Linux**:
42
+ ```bash
43
+ curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
44
+ sudo apt-get install -y nodejs
45
+ ```
46
+ - 安装完成后**再次验证** `node -v` 和 `npm -v`,确认可用后才继续。
47
+
48
+ #### 检测 npm
49
+ ```bash
50
+ npm -v
51
+ ```
52
+ npm 随 Node.js 一起安装,正常情况下不需要单独处理。如果 Node 装好了但 npm 异常,运行:
53
+ ```bash
54
+ node -e "console.log('node ok')" && npm -v
55
+ ```
56
+
57
+ > **原则:** 环境检测和安装全程自动执行,用户只需等待。如果某步安装需要管理员权限,告诉用户「需要输入电脑密码来安装 XXX」即可,不要让用户去搜教程或手动下载。
58
+
19
59
  ### 1. 创建 React + Vite 项目
20
60
  ```bash
21
61
  npm create vite@latest . -- --template react-ts
@@ -27,6 +67,7 @@ npm create vite@latest . -- --template react-ts
27
67
  npm install
28
68
  npm install @lmy54321/design-system
29
69
  npm install tailwindcss @tailwindcss/vite
70
+ npm install react-router-dom motion
30
71
  ```
31
72
 
32
73
  ### 3. 同步设计系统 AI 规则
@@ -39,54 +80,51 @@ cp node_modules/@lmy54321/design-system/.codebuddy/rules/init-project.mdc .codeb
39
80
 
40
81
  > **说明:** 规则文件随 npm 包版本同步发布,每次升级设计系统版本后应重新执行此复制命令以获取最新规范。`init-project.mdc` 也会被复制,这样项目后续可以再次执行初始化或帮助其他同事同步规则。
41
82
 
42
- ### 4. 配置 Vite(添加 Tailwind 插件)
43
- 修改 `vite.config.ts`:
44
- ```ts
45
- import { defineConfig } from 'vite'
46
- import react from '@vitejs/plugin-react'
47
- import tailwindcss from '@tailwindcss/vite'
83
+ ### 4. 复制完整 Demo 模板
48
84
 
49
- export default defineConfig({
50
- plugins: [react(), tailwindcss()],
51
- })
52
- ```
85
+ 设计系统 npm 包中内置了完整的 Demo 项目模板(地图首页、探索页、行程规划、个人中心、开发者入口、组件库展示等),直接复制即可运行。
53
86
 
54
- ### 5. 配置入口样式
55
- 将 `src/index.css` 内容替换为:
56
- ```css
57
- @import "@lmy54321/design-system/styles";
87
+ **模板会覆盖 Vite 默认文件**(`vite.config.ts`、`tsconfig.json`、`index.html`、`src/` 下的所有文件),已包含正确的 Tailwind + 设计系统样式配置,无需手动修改:
58
88
 
59
- @source "../src";
60
- @source "../node_modules/@lmy54321/design-system/dist";
61
- ```
89
+ ```bash
90
+ # 复制 Demo 模板文件(覆盖 Vite 默认生成的文件)
91
+ cp -r node_modules/@lmy54321/design-system/template/src/* src/
92
+ cp node_modules/@lmy54321/design-system/template/index.html index.html
93
+ cp node_modules/@lmy54321/design-system/template/vite.config.ts vite.config.ts
94
+ cp node_modules/@lmy54321/design-system/template/tsconfig.json tsconfig.json
95
+
96
+ # 复制 public 资源(manifest 等,图片通过 CDN 加载无需复制)
97
+ cp node_modules/@lmy54321/design-system/template/public/manifest.json public/manifest.json 2>/dev/null || true
62
98
 
63
- > **注意:** 不要在 `src/index.css` 中单独写 `@import "tailwindcss"`,设计系统的样式文件内部已包含 Tailwind 初始化,重复导入会导致样式冲突。
64
- > `src/main.tsx` 中也不需要通过 JS 导入样式(不需要 `import '@lmy54321/design-system/styles'`),CSS 的 `@import` 已经处理了。
65
-
66
- ### 6. 清理 Vite 默认模板
67
- - 清空 `src/App.css` 的内容
68
- - 将 `src/App.tsx` 替换为一个简单的欢迎页面,使用设计系统组件:
69
- ```tsx
70
- import { Btn, IconFont } from '@lmy54321/design-system'
71
-
72
- function App() {
73
- return (
74
- <div style={{ minHeight: '100dvh', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 16, fontFamily: 'var(--font-family-sans)' }}>
75
- <IconFont name="map-location" size="48px" />
76
- <h1 style={{ fontSize: 24, fontWeight: 600 }}>项目已就绪</h1>
77
- <p style={{ fontSize: 14, color: 'rgba(0,0,0,0.42)' }}>设计系统已加载,可以开始创建页面了</p>
78
- <Btn variant="primary" label="开始" />
79
- </div>
80
- )
81
- }
82
-
83
- export default App
99
+ # 删除 Vite 默认生成的无用文件
100
+ rm -f src/App.css src/assets/react.svg public/vite.svg
84
101
  ```
85
102
 
103
+ > **说明:** 模板包含以下路由页面,启动后可通过浏览器访问:
104
+ > - `/` — 开发者入口(默认首页,四个功能卡片导航)
105
+ > - `/dev` — 开发者入口(同上)
106
+ > - `/demo` — Demo 手机预览(地图首页、探索、行程、我的四个 Tab)
107
+ > - `/components` — 组件库交互式展示
108
+ > - `/sync` — 规范同步工具
109
+ > - `/deploy` — 部署预览
110
+ >
111
+ > **注意:** 模板中的图片资源通过 CDN 加载(jsDelivr + GitHub),无需在本地存放图片文件。
112
+ >
113
+ > **注意:** 模板中的 `src/index.css` 已配置好样式导入,不需要手动修改。不要在其中单独写 `@import "tailwindcss"`,设计系统样式内部已包含 Tailwind 初始化。
114
+
86
115
  ### 7. 启动开发服务器
87
116
  ```bash
88
117
  npm run dev
89
118
  ```
90
119
 
91
- ### 8. 完成后告诉用户
92
- 告诉用户:「项目已初始化完成,设计系统已加载。你可以直接描述你想要的页面,比如:做一个地图首页 / 做一个搜索页面 / 做一个 POI 列表页。」
120
+ ### 6. 完成后告诉用户
121
+ 告诉用户:
122
+
123
+ 「项目已初始化完成!已加载完整的 Demo 项目,包含多个示例页面。
124
+
125
+ **访问地址:**
126
+ - 开发者入口(默认首页):http://localhost:5173/
127
+ - Demo 手机预览:http://localhost:5173/demo
128
+ - 组件库:http://localhost:5173/components
129
+
130
+ 你可以在这些 Demo 的基础上修改,或者描述你想要的新页面。」
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lmy54321/design-system",
3
- "version": "1.1.4",
3
+ "version": "1.3.0",
4
4
  "description": "A comprehensive React component library and design system based on Tailwind CSS and Motion.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -18,6 +18,8 @@
18
18
  "files": [
19
19
  "dist",
20
20
  "styles",
21
+ "template",
22
+ "!template/public/images",
21
23
  ".codebuddy/rules/design-system.mdc",
22
24
  ".codebuddy/rules/init-project.mdc"
23
25
  ],
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
6
+ <!-- PWA 全屏模式,添加到主屏幕后无地址栏 -->
7
+ <meta name="mobile-web-app-capable" content="yes">
8
+ <meta name="apple-mobile-web-app-capable" content="yes">
9
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
10
+ <meta name="theme-color" content="#4B526B">
11
+ <link rel="manifest" href="/manifest.json">
12
+ <title>Design Demo</title>
13
+ </head>
14
+ <body>
15
+ <div id="root"></div>
16
+ <script type="module" src="/src/main.tsx"></script>
17
+ </body>
18
+ </html>
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "Design System Demo",
3
+ "short_name": "Demo",
4
+ "start_url": "/",
5
+ "display": "standalone",
6
+ "background_color": "#ffffff",
7
+ "theme_color": "#4B526B",
8
+ "orientation": "any"
9
+ }
@@ -0,0 +1,55 @@
1
+ import { useState, useCallback } from "react";
2
+ import type { TabId } from "@lmy54321/design-system";
3
+ import { MapHome } from "./pages/MapHome";
4
+ import { ExplorePage } from "./pages/ExplorePage";
5
+ import { PlanPage } from "./pages/PlanPage";
6
+ import { MePage } from "./pages/MePage";
7
+
8
+ export interface NewPlanPayload {
9
+ title: string;
10
+ spots: number;
11
+ image: string;
12
+ stops: { name: string; icon: string; dur: string }[];
13
+ }
14
+
15
+ export default function App() {
16
+ const [activeTab, setActiveTab] = useState<TabId>("home");
17
+ const [newPlan, setNewPlan] = useState<NewPlanPayload | null>(null);
18
+
19
+ const handleCreatePlan = useCallback((plan: NewPlanPayload) => {
20
+ setNewPlan(plan);
21
+ setActiveTab("plan");
22
+ }, []);
23
+
24
+ const handlePlanConsumed = useCallback(() => {
25
+ setNewPlan(null);
26
+ }, []);
27
+
28
+ const renderPage = () => {
29
+ switch (activeTab) {
30
+ case "home":
31
+ return <MapHome activeTab={activeTab} onTabChange={setActiveTab} />;
32
+ case "explore":
33
+ return <ExplorePage activeTab={activeTab} onTabChange={setActiveTab} onCreatePlan={handleCreatePlan} />;
34
+ case "plan":
35
+ return (
36
+ <PlanPage
37
+ activeTab={activeTab}
38
+ onTabChange={setActiveTab}
39
+ newPlan={newPlan}
40
+ onNewPlanConsumed={handlePlanConsumed}
41
+ />
42
+ );
43
+ case "me":
44
+ return <MePage activeTab={activeTab} onTabChange={setActiveTab} />;
45
+ default:
46
+ return <MapHome activeTab={activeTab} onTabChange={setActiveTab} />;
47
+ }
48
+ };
49
+
50
+ return (
51
+ <div className="w-full max-w-[100vw] h-[100dvh] overflow-hidden relative">
52
+ {renderPage()}
53
+ </div>
54
+ );
55
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * CDN 资源配置
3
+ * 图片托管在 GitHub,通过 jsDelivr CDN 全球加速访问
4
+ */
5
+
6
+ const CDN_BASE =
7
+ "https://cdn.jsdelivr.net/gh/lmy910510/design-system-assets@main";
8
+
9
+ /** 拼接 CDN 图片完整 URL */
10
+ export function cdnImage(path: string): string {
11
+ return `${CDN_BASE}${path}`;
12
+ }
@@ -0,0 +1,4 @@
1
+ @import "@lmy54321/design-system/styles";
2
+
3
+ @source "../src";
4
+ @source "../node_modules/@lmy54321/design-system/dist";
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ import ReactDOM from "react-dom/client";
3
+ import { BrowserRouter, Routes, Route } from "react-router-dom";
4
+ import App from "./App";
5
+ import { DevPortal } from "./pages/DevPortal";
6
+ import { ComponentLibrary } from "./pages/ComponentLibrary";
7
+ import { SyncTool } from "./pages/SyncTool";
8
+ import { DeployPage } from "./pages/DeployPage";
9
+ import "./index.css";
10
+
11
+ ReactDOM.createRoot(document.getElementById("root")!).render(
12
+ <React.StrictMode>
13
+ <BrowserRouter>
14
+ <Routes>
15
+ {/* 开发者入口(默认首页) */}
16
+ <Route path="/" element={<DevPortal />} />
17
+ {/* 开发者入口别名 */}
18
+ <Route path="/dev" element={<DevPortal />} />
19
+ {/* 组件库展示 */}
20
+ <Route path="/components" element={<ComponentLibrary />} />
21
+ {/* 规范同步 */}
22
+ <Route path="/sync" element={<SyncTool />} />
23
+ {/* 部署预览 */}
24
+ <Route path="/deploy" element={<DeployPage />} />
25
+ {/* Demo 手机预览内容(通配符放最后作为 fallback) */}
26
+ <Route path="/demo/*" element={<App />} />
27
+ </Routes>
28
+ </BrowserRouter>
29
+ </React.StrictMode>
30
+ );