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:
2026-05-20 15:54:15 +08:00
parent 4a38d4dac7
commit 5aed73523e
12 changed files with 112 additions and 26 deletions

View File

@@ -1,3 +1,5 @@
import { APP } from "../shared/app";
export interface ServerConfig {
host: string;
port: number;
@@ -43,7 +45,7 @@ export function parseRuntimeArgs(argv: string[] = Bun.argv.slice(2)): { configPa
if (argv.length === 0) return {};
const firstArg = argv[0];
if (firstArg === "--help" || firstArg === "-h") {
console.log("用法: my-app [config.yaml]");
console.log(`用法: ${APP.name} [config.yaml]`);
console.log(" config.yaml 可选 YAML 配置文件路径(不存在时使用默认配置)");
process.exit(0);
}

View File

@@ -1,5 +1,7 @@
import type { ApiErrorResponse, HealthResponse, RuntimeMode } from "../shared/api";
import { APP } from "../shared/app";
export function createApiError(error: string, status: number): ApiErrorResponse {
return { error, status };
}
@@ -18,7 +20,7 @@ export function createHeaders(mode: RuntimeMode, init: HeadersInit): Headers {
export function createHealthResponse(): HealthResponse {
return {
ok: true,
service: "my-app",
service: APP.name,
timestamp: new Date().toISOString(),
};
}

View File

@@ -2,6 +2,7 @@ import type { RuntimeMode } from "../shared/api";
import type { ServerConfig } from "./config";
import type { StaticAssets } from "./static";
import { APP } from "../shared/app";
import { createApiError, jsonResponse } from "./helpers";
import { handleHealth } from "./routes/health";
import { serveStaticAsset } from "./static";
@@ -32,7 +33,7 @@ export function startServer(options: StartServerOptions) {
},
});
console.log(`my-app listening on ${server.url}`);
console.log(`${APP.name} listening on ${server.url}`);
return server;
}