Skip to content

Commit 182ab8d

Browse files
committed
feat(subtitle): 在Docker环境下显示"Docker 构建"副标题
1 parent fbd515f commit 182ab8d

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ tests/
2525

2626
# 忽略 Git 相关文件
2727
.github/
28+
.git/
2829
.gitignore
2930
.gitattributes
3031

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ COPY ./package*.json ./
55
COPY ./.npmrc ./
66
RUN npm install
77
COPY . .
8+
ENV VITE_IS_DOCKER_ENVIRONMENT=true
89
ENV VITE_ENABLE_RUNTIME_CONFIG=true
910
RUN npm run build
1011

src/console/ConsoleLayout.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,15 @@ export default function ConsoleLayout({
130130
<Flex className="title-bar" align="center" justify="space-between">
131131
<div className="title">
132132
<span className="major">求是潮纳新开放系统</span>
133-
<Tooltip title={<span style={{ whiteSpace: 'pre-wrap' }}>{import.meta.env.VITE_BUILD_INFO_DETAIL ?? '未获取到构建详情'}</span>}>
134-
<span className="minor">{import.meta.env.VITE_BUILD_INFO ?? '构建版本未知'}</span>
135-
</Tooltip>
133+
{import.meta.env.VITE_IS_DOCKER_ENVIRONMENT?.match(/^(true|1)$/i) ? (
134+
<Tooltip title={<span style={{ whiteSpace: 'pre-wrap' }}>Docker 构建版本</span>}>
135+
<span className="minor">Docker 构建版本</span>
136+
</Tooltip>
137+
) : (
138+
<Tooltip title={<span style={{ whiteSpace: 'pre-wrap' }}>{import.meta.env.VITE_BUILD_INFO_DETAIL ?? '未获取到构建详情'}</span>}>
139+
<span className="minor">{import.meta.env.VITE_BUILD_INFO ?? '构建版本未知'}</span>
140+
</Tooltip>
141+
)}
136142
</div>
137143
<Dropdown
138144
className="current-activity"

vite.config.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@ import { execSync } from 'node:child_process';
66
function sh(cmd: string) {
77
return execSync(cmd, { encoding: 'utf-8' }).trim();
88
}
9-
const headSha = sh('git rev-parse HEAD');
10-
const headCommitCount = sh('git rev-list --count HEAD');
11-
const headBranch = sh('git rev-parse --abbrev-ref HEAD');
12-
const anyChanges = sh('git status --porcelain -uall').length > 0;
9+
let headSha: string, headCommitCount: string, headBranch: string, anyChanges: boolean;
10+
try {
11+
headSha = sh('git rev-parse HEAD');
12+
headCommitCount = sh('git rev-list --count HEAD');
13+
headBranch = sh('git rev-parse --abbrev-ref HEAD');
14+
anyChanges = sh('git status --porcelain -uall').length > 0;
15+
} catch {
16+
headSha = 'unknown';
17+
headCommitCount = 'unknown';
18+
headBranch = 'unknown';
19+
anyChanges = false;
20+
}
21+
1322
// https://vitejs.dev/config/
1423
export default defineConfig({
1524
define: {

0 commit comments

Comments
 (0)