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:
31
README.md
31
README.md
@@ -25,23 +25,23 @@ cd my-project
|
||||
rm -rf .git && git init
|
||||
```
|
||||
|
||||
### 2. 替换占位符 `my-app`
|
||||
### 2. 配置应用信息
|
||||
|
||||
在整个项目中全局搜索替换 `my-app` 为你的项目名称(如 `your-project`)。以下为所有出现位置:
|
||||
编辑 `src/shared/app.ts`,修改应用元信息:
|
||||
|
||||
| # | 文件 | 说明 |
|
||||
| --- | --------------------------------------- | ------------------------------------------ |
|
||||
| 1 | `package.json` | `name` 字段 |
|
||||
| 2 | `scripts/build.ts` | 可执行文件路径 |
|
||||
| 3 | `src/server/config.ts` | CLI 帮助文本 |
|
||||
| 4 | `src/server/helpers.ts` | `createHealthResponse()` 的 `service` 字段 |
|
||||
| 5 | `src/server/server.ts` | 服务启动日志消息 |
|
||||
| 6 | `src/web/index.html` | `<title>` 和 `<meta name="description">` |
|
||||
| 7 | `src/web/app.tsx` | Header 中的品牌名和欢迎标题 |
|
||||
| 8 | `src/web/hooks/use-theme-preference.ts` | `localStorage` 键名 |
|
||||
| 9 | `tests/web/App.test.tsx` | 测试中的品牌名断言 |
|
||||
```typescript
|
||||
export const APP = {
|
||||
name: "your-app", // 机器标识(kebab-case)
|
||||
title: "Your App", // 人类可读标题
|
||||
subtitle: "你的副标题", // 副标题
|
||||
description: "应用描述", // SEO meta 描述
|
||||
version: "0.1.0", // 版本号
|
||||
} as const;
|
||||
```
|
||||
|
||||
> **提示**:可直接在编辑器中全局搜索 `my-app`,一次性替换。
|
||||
同时修改 `package.json` 的 `name` 字段保持一致。
|
||||
|
||||
> **注意**:localStorage key 已从 `"my-app.theme.preference"` 变更为 `"theme.preference"`。如果从旧版本升级,用户的主题偏好设置将丢失,需重新选择。
|
||||
|
||||
### 3. 清理 OpenSpec 历史
|
||||
|
||||
@@ -111,7 +111,8 @@ bun run dev
|
||||
│ │ └── routes/ # API 路由处理器
|
||||
│ │ └── health.ts # 健康检查端点
|
||||
│ ├── shared/
|
||||
│ │ └── api.ts # 前后端共享 TypeScript 类型定义
|
||||
│ │ ├── api.ts # 前后端共享 TypeScript 类型定义
|
||||
│ │ └── app.ts # 应用全局常量(name、title、version 等)
|
||||
│ └── web/ # 前端代码
|
||||
│ ├── index.html # HTML 入口
|
||||
│ ├── main.tsx # React 入口(QueryClient + ErrorBoundary)
|
||||
|
||||
Reference in New Issue
Block a user