feat: 新增应用全局常量 APP,消除硬编码散落
- 新增 src/shared/app.ts,定义应用元信息(name、title、subtitle、description、version) - 后端 3 处硬编码改为引用 APP.name - 前端 3 处硬编码改为引用 APP.title/APP.description - localStorage key 从 my-app.theme.preference 改为 theme.preference - 构建脚本可执行文件名改为引用 APP.name - 更新 README.md 和 DEVELOPMENT.md 文档 - 新增 openspec/specs/app-constants/spec.md 规范文档
This commit is contained in:
@@ -34,6 +34,7 @@ src/
|
||||
health.ts GET /health
|
||||
shared/
|
||||
api.ts 前后端共享 TypeScript 类型
|
||||
app.ts 应用全局常量(name、title、subtitle、description、version)
|
||||
web/ React 前端(通过 Vite 构建)
|
||||
index.html HTML 入口
|
||||
app.tsx 根组件(Layout + Header + Content,/health 联调示例展示)
|
||||
@@ -161,6 +162,7 @@ export function handleHealth(mode: RuntimeMode): Response;
|
||||
### 1.5 类型定义规范
|
||||
|
||||
- **共享类型**以 `src/shared/api.ts` 为唯一源头,前后端共同引用
|
||||
- **应用常量**以 `src/shared/app.ts` 为唯一源头,定义 `APP` 对象(name、title、subtitle、description、version),前后端及构建脚本共同引用
|
||||
- 前端不得 `import src/server/` 下的任何文件
|
||||
- **严格联合类型**优先于宽类型:如 `RuntimeMode: "development" | "production" | "test"` 而非 `RuntimeMode: string`
|
||||
- API 响应类型(`ApiErrorResponse`、`HealthResponse`)定义在 shared 中
|
||||
@@ -233,7 +235,7 @@ main.tsx
|
||||
hooks/use-theme-preference.ts(浏览器 UI 偏好)
|
||||
├── ThemePreference: system / light / dark(RadioGroup 受控值)
|
||||
├── EffectiveTheme: light / dark(写入 document.documentElement theme-mode)
|
||||
├── localStorage key: my-app.theme.preference(同一浏览器记忆)
|
||||
├── localStorage key: theme.preference(同一浏览器记忆)
|
||||
└── matchMedia("(prefers-color-scheme: dark)")(系统模式下跟随系统明暗变化)
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user