feat: add getProjectDisplayName utility

This commit is contained in:
2026-03-04 21:21:53 +08:00
parent 87271c4602
commit 149e3a5924
2 changed files with 61 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
// lib/utils.ts
// Client-safe utility functions
import * as fs from 'fs';
import * as path from 'path';
/**
* 格式化版本号显示 (0_42 -> 0.42)
@@ -29,3 +31,18 @@ export function formatDateTime(date: Date): string {
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}`;
}
/**
* 获取项目显示名称(从别名配置)
*/
export function getProjectDisplayName(projectName: string): string {
try {
const aliasesPath = path.join(process.cwd(), 'lib', 'project-aliases.json');
const aliasesContent = fs.readFileSync(aliasesPath, 'utf-8');
const aliases = JSON.parse(aliasesContent);
return aliases[projectName] || projectName;
} catch {
// If file doesn't exist or is invalid, return original name
return projectName;
}
}