@kevairy/template 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/package.json +1 -1
  2. package/template/.env +0 -3
  3. package/template/.env.production +1 -1
  4. package/template/README.md +12 -0
  5. package/template/package.json +5 -5
  6. package/template/scripts/build-info.ts +76 -0
  7. package/template/src/assets/images/common/logo.webp +0 -0
  8. package/template/src/assets/images/favicon.ico +0 -0
  9. package/template/src/components/core/layouts/art-chat-window/index.vue +15 -24
  10. package/template/src/components/core/layouts/art-header-bar/widget/ArtUserMenu.vue +17 -8
  11. package/template/src/components/core/layouts/art-notification/index.vue +11 -21
  12. package/template/src/components/core/layouts/art-screen-lock/index.vue +6 -2
  13. package/template/src/config/index.ts +1 -2
  14. package/template/src/env.d.ts +1 -0
  15. package/template/src/types/build-info.ts +11 -0
  16. package/template/src/types/config/index.ts +1 -3
  17. package/template/src/utils/sys/console.ts +63 -7
  18. package/template/tests/unit/build/build-info.spec.ts +151 -0
  19. package/template/tsconfig.json +8 -1
  20. package/template/vite.config.ts +16 -9
  21. package/template/src/assets/images/avatar/avatar.webp +0 -0
  22. package/template/src/assets/images/avatar/avatar1.webp +0 -0
  23. package/template/src/assets/images/avatar/avatar10.webp +0 -0
  24. package/template/src/assets/images/avatar/avatar2.webp +0 -0
  25. package/template/src/assets/images/avatar/avatar3.webp +0 -0
  26. package/template/src/assets/images/avatar/avatar4.webp +0 -0
  27. package/template/src/assets/images/avatar/avatar5.webp +0 -0
  28. package/template/src/assets/images/avatar/avatar6.webp +0 -0
  29. package/template/src/assets/images/avatar/avatar7.webp +0 -0
  30. package/template/src/assets/images/avatar/avatar8.webp +0 -0
  31. package/template/src/assets/images/avatar/avatar9.webp +0 -0
  32. package/template/src/assets/images/ceremony/xc.png +0 -0
  33. package/template/src/assets/images/draw/draw1.png +0 -0
  34. package/template/src/assets/images/lock/bg_dark.webp +0 -0
  35. package/template/src/assets/images/lock/bg_light.webp +0 -0
  36. package/template/src/assets/images/login/lf_icon2.webp +0 -0
  37. package/template/src/assets/images/svg/500.svg +0 -5
  38. package/template/src/assets/images/user/avatar.webp +0 -0
  39. package/template/src/assets/images/user/bg.webp +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevairy/template",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Project template consumed by @kevairy/cli",
5
5
  "keywords": [
6
6
  "vue",
package/template/.env CHANGED
@@ -1,8 +1,5 @@
1
1
  # 【通用】环境变量
2
2
 
3
- # 版本号
4
- VITE_VERSION = 0.1.0
5
-
6
3
  # 端口号
7
4
  VITE_PORT = 3006
8
5
 
@@ -6,7 +6,7 @@ VITE_BASE_URL = /
6
6
  # API 地址前缀
7
7
  VITE_API_URL = /api/
8
8
 
9
- # CI 可注入 Git SHA / 发布编号;留空时自动使用构建时间。
9
+ # CI 可注入唯一构建编号;留空时自动生成 UTC 时间 + Git 提交 + 随机后缀。
10
10
  VITE_BUILD_ID =
11
11
 
12
12
  # true 生成 hidden sourcemap;上传诊断平台后必须从静态部署目录删除 .map 文件。
@@ -20,3 +20,15 @@ __RUN_COMMAND__ typecheck
20
20
  __RUN_COMMAND__ test
21
21
  __RUN_COMMAND__ build
22
22
  ```
23
+
24
+ ## 版本与构建
25
+
26
+ 发布版本由项目根目录 package.json 的 version 管理。每次执行构建命令会自动生成独立的构建编号、UTC 构建时间、Git 提交和未提交状态,不修改版本文件。
27
+
28
+ 浏览器控制台在生产环境也会显示一次构建信息;dist/version.json 和错误诊断使用相同的发布版本与构建编号。没有 Git 也可以正常构建,无法确认的提交和工作区状态标为 null。
29
+
30
+ CI 可以通过 VITE_BUILD_ID 覆盖构建编号(应保证每次构建唯一),通过进程环境变量 BUILD_GIT_COMMIT 和 BUILD_GIT_DIRTY 注入提交与工作区状态。BUILD_GIT_DIRTY 仅接受 true 或 false;只注入提交时,工作区状态标为未知。
31
+
32
+ 部署时将 version.json 与同一批静态资源一起发布,并对该文件配置 Cache-Control: no-store。浏览器输出代表当前页面已加载的版本,服务器的 version.json 代表服务器当前提供的版本。
33
+
34
+ 准备正式发布时再升级 package.json 的 version,例如运行 npm version patch --no-git-tag-version;自动构建编号不参与本地存储版本迁移。
@@ -17,7 +17,7 @@
17
17
  "@vueuse/core": "13.9.0",
18
18
  "@wangeditor/editor": "5.1.23",
19
19
  "@wangeditor/editor-for-vue": "5.1.12",
20
- "axios": "1.19.0",
20
+ "axios": "1.21.1",
21
21
  "driver.js": "1.9.0",
22
22
  "echarts": "6.1.0",
23
23
  "element-plus": "2.14.4",
@@ -29,8 +29,8 @@
29
29
  "pinia-plugin-persistedstate": "4.7.1",
30
30
  "qrcode.vue": "3.10.0",
31
31
  "tailwindcss": "4.3.3",
32
- "vue": "3.5.41",
33
- "vue-i18n": "11.4.8",
32
+ "vue": "3.5.45",
33
+ "vue-i18n": "11.4.18",
34
34
  "vue-router": "4.6.4",
35
35
  "xgplayer": "3.0.26"
36
36
  },
@@ -65,7 +65,7 @@
65
65
  "@playwright/test": "1.62.1",
66
66
  "@types/node": "24.13.3",
67
67
  "@vitejs/plugin-vue": "6.0.8",
68
- "@vue/compiler-sfc": "3.5.41",
68
+ "@vue/compiler-sfc": "3.5.45",
69
69
  "@vue/test-utils": "2.4.11",
70
70
  "happy-dom": "20.11.2",
71
71
  "rollup-plugin-visualizer": "5.14.0",
@@ -74,7 +74,7 @@
74
74
  "unplugin-auto-import": "20.3.0",
75
75
  "unplugin-element-plus": "0.10.0",
76
76
  "unplugin-vue-components": "29.2.0",
77
- "vite": "7.3.6",
77
+ "vite": "7.3.8",
78
78
  "vitest": "4.1.10",
79
79
  "vue-demi": "0.14.10",
80
80
  "vue-img-cutter": "3.1.1",
@@ -0,0 +1,76 @@
1
+ import { execFileSync } from 'node:child_process'
2
+ import { randomUUID } from 'node:crypto'
3
+ import { readFileSync } from 'node:fs'
4
+ import path from 'node:path'
5
+ import type { Plugin } from 'vite'
6
+ import type { BuildInfo } from '../src/types/build-info'
7
+
8
+ interface BuildInfoOptions {
9
+ root: string
10
+ mode: string
11
+ buildId?: string
12
+ gitCommit?: string
13
+ gitDirty?: string
14
+ }
15
+
16
+ function readGit(root: string, args: string[]): string | null {
17
+ try {
18
+ return execFileSync('git', args, {
19
+ cwd: root,
20
+ encoding: 'utf8',
21
+ stdio: ['ignore', 'pipe', 'ignore'],
22
+ timeout: 3000
23
+ }).trim()
24
+ } catch {
25
+ return null
26
+ }
27
+ }
28
+
29
+ export function createBuildInfo(options: BuildInfoOptions): BuildInfo {
30
+ const { version } = JSON.parse(readFileSync(path.join(options.root, 'package.json'), 'utf8'))
31
+ if (typeof version !== 'string' || !version.trim()) {
32
+ throw new Error('package.json 必须包含非空的 version 字段')
33
+ }
34
+
35
+ const gitCommit = options.gitCommit?.trim() || readGit(options.root, ['rev-parse', 'HEAD'])
36
+ // CI 指定提交时,不把构建机工作区状态误当成该提交的状态。
37
+ const status = options.gitCommit?.trim()
38
+ ? null
39
+ : readGit(options.root, ['status', '--porcelain', '--untracked-files=normal'])
40
+ if (options.gitDirty && !['true', 'false'].includes(options.gitDirty)) {
41
+ throw new Error('BUILD_GIT_DIRTY 只允许 true 或 false')
42
+ }
43
+ const gitDirty = options.gitDirty
44
+ ? options.gitDirty === 'true'
45
+ : status === null
46
+ ? null
47
+ : status.length > 0
48
+ const builtAt = new Date().toISOString()
49
+ const timestamp = builtAt.replace(/[-:.]/g, '')
50
+ const buildId =
51
+ options.buildId?.trim() ||
52
+ `${timestamp}-${gitCommit?.slice(0, 12) || 'nogit'}${gitDirty ? '-dirty' : ''}-${randomUUID().slice(0, 8)}`
53
+
54
+ return { version, buildId, gitCommit, gitDirty, builtAt, mode: options.mode }
55
+ }
56
+
57
+ /** 常量与静态清单复用同一份快照,不在输出阶段重新生成编号。 */
58
+ export function buildInfoPlugin(info: BuildInfo): Plugin {
59
+ return {
60
+ name: 'app-build-info',
61
+ config: () => ({
62
+ define: {
63
+ __APP_VERSION__: JSON.stringify(info.version),
64
+ __BUILD_ID__: JSON.stringify(info.buildId),
65
+ __BUILD_INFO__: JSON.stringify(info)
66
+ }
67
+ }),
68
+ generateBundle() {
69
+ this.emitFile({
70
+ type: 'asset',
71
+ fileName: 'version.json',
72
+ source: `${JSON.stringify(info, null, 2)}\n`
73
+ })
74
+ }
75
+ }
76
+ }
@@ -32,7 +32,9 @@
32
32
  message.isMe ? 'flex-row-reverse' : 'flex-row'
33
33
  ]"
34
34
  >
35
- <ElAvatar :size="32" :src="message.avatar" class="shrink-0" />
35
+ <ElAvatar :size="32" :src="message.avatar" class="shrink-0">
36
+ <ArtSvgIcon :icon="AppConfig.assets.defaultAvatarIcon" class="text-lg" />
37
+ </ElAvatar>
36
38
  <div
37
39
  :class="['flex max-w-[70%] flex-col', message.isMe ? 'items-end' : 'items-start']"
38
40
  >
@@ -91,8 +93,7 @@
91
93
  <script setup lang="ts">
92
94
  import { Picture, Paperclip, Close } from '@element-plus/icons-vue'
93
95
  import { mittBus } from '@/utils/sys'
94
- import meAvatar from '@/assets/images/avatar/avatar5.webp'
95
- import aiAvatar from '@/assets/images/avatar/avatar10.webp'
96
+ import AppConfig from '@/config'
96
97
 
97
98
  defineOptions({ name: 'ArtChatWindow' })
98
99
 
@@ -103,7 +104,7 @@
103
104
  content: string
104
105
  time: string
105
106
  isMe: boolean
106
- avatar: string
107
+ avatar?: string
107
108
  }
108
109
 
109
110
  // 常量定义
@@ -132,72 +133,63 @@
132
133
  sender: BOT_NAME,
133
134
  content: '你好!我是你的AI助手,有什么我可以帮你的吗?',
134
135
  time: '10:00',
135
- isMe: false,
136
- avatar: aiAvatar
136
+ isMe: false
137
137
  },
138
138
  {
139
139
  id: 2,
140
140
  sender: USER_NAME,
141
141
  content: '我想了解一下系统的使用方法。',
142
142
  time: '10:01',
143
- isMe: true,
144
- avatar: meAvatar
143
+ isMe: true
145
144
  },
146
145
  {
147
146
  id: 3,
148
147
  sender: BOT_NAME,
149
148
  content: '好的,我来为您介绍系统的主要功能。首先,您可以通过左侧菜单访问不同的功能模块...',
150
149
  time: '10:02',
151
- isMe: false,
152
- avatar: aiAvatar
150
+ isMe: false
153
151
  },
154
152
  {
155
153
  id: 4,
156
154
  sender: USER_NAME,
157
155
  content: '听起来很不错,能具体讲讲数据分析部分吗?',
158
156
  time: '10:05',
159
- isMe: true,
160
- avatar: meAvatar
157
+ isMe: true
161
158
  },
162
159
  {
163
160
  id: 5,
164
161
  sender: BOT_NAME,
165
162
  content: '当然可以。数据分析模块可以帮助您实时监控关键指标,并生成详细的报表...',
166
163
  time: '10:06',
167
- isMe: false,
168
- avatar: aiAvatar
164
+ isMe: false
169
165
  },
170
166
  {
171
167
  id: 6,
172
168
  sender: USER_NAME,
173
169
  content: '太好了,那我如何开始使用呢?',
174
170
  time: '10:08',
175
- isMe: true,
176
- avatar: meAvatar
171
+ isMe: true
177
172
  },
178
173
  {
179
174
  id: 7,
180
175
  sender: BOT_NAME,
181
176
  content: '您可以先创建一个项目,然后在项目中添加相关的数据源,系统会自动进行分析。',
182
177
  time: '10:09',
183
- isMe: false,
184
- avatar: aiAvatar
178
+ isMe: false
185
179
  },
186
180
  {
187
181
  id: 8,
188
182
  sender: USER_NAME,
189
183
  content: '明白了,谢谢你的帮助!',
190
184
  time: '10:10',
191
- isMe: true,
192
- avatar: meAvatar
185
+ isMe: true
193
186
  },
194
187
  {
195
188
  id: 9,
196
189
  sender: BOT_NAME,
197
190
  content: '不客气,有任何问题随时联系我。',
198
191
  time: '10:11',
199
- isMe: false,
200
- avatar: aiAvatar
192
+ isMe: false
201
193
  }
202
194
  ]
203
195
 
@@ -231,8 +223,7 @@
231
223
  sender: USER_NAME,
232
224
  content: text,
233
225
  time: formatCurrentTime(),
234
- isMe: true,
235
- avatar: meAvatar
226
+ isMe: true
236
227
  }
237
228
 
238
229
  messages.value.push(newMessage)
@@ -12,20 +12,29 @@
12
12
  popper-style="padding: 5px 16px;"
13
13
  >
14
14
  <template #reference>
15
- <img
16
- class="user-menu-avatar size-8.5 mr-5 c-p rounded-full max-sm:w-6.5 max-sm:h-6.5 max-sm:mr-[16px]"
17
- :src="userInfo.avatar || AppConfig.assets.defaultAvatar"
15
+ <ElAvatar
16
+ class="user-menu-avatar !size-8.5 mr-5 c-p max-sm:!size-6.5 max-sm:mr-[16px]"
17
+ :src="userInfo.avatar"
18
18
  :alt="userInfo.userName || '用户头像'"
19
- />
19
+ role="img"
20
+ :aria-label="userInfo.userName || '用户头像'"
21
+ >
22
+ <ArtSvgIcon :icon="AppConfig.assets.defaultAvatarIcon" class="text-xl max-sm:text-base" />
23
+ </ElAvatar>
20
24
  </template>
21
25
  <template #default>
22
26
  <div class="pt-3">
23
27
  <div class="flex-c pb-1 px-0">
24
- <img
25
- class="w-10 h-10 mr-3 ml-0 overflow-hidden rounded-full float-left"
26
- :src="userInfo.avatar || AppConfig.assets.defaultAvatar"
28
+ <ElAvatar
29
+ :size="40"
30
+ class="mr-3 shrink-0"
31
+ :src="userInfo.avatar"
27
32
  :alt="userInfo.userName || '用户头像'"
28
- />
33
+ role="img"
34
+ :aria-label="userInfo.userName || '用户头像'"
35
+ >
36
+ <ArtSvgIcon :icon="AppConfig.assets.defaultAvatarIcon" class="text-2xl" />
37
+ </ElAvatar>
29
38
  <div class="w-[calc(100%-60px)] h-full">
30
39
  <span class="block text-sm font-medium text-g-800 truncate">{{
31
40
  userInfo.userName
@@ -58,7 +58,9 @@
58
58
  class="box-border flex-c px-3.5 py-3.5 c-p last:border-b-0 hover:bg-g-200/60"
59
59
  >
60
60
  <div class="w-9 h-9">
61
- <img :src="item.avatar" class="w-full h-full rounded-lg" />
61
+ <ElAvatar :size="36" :src="item.avatar" shape="square" class="rounded-lg">
62
+ <ArtSvgIcon :icon="AppConfig.assets.defaultAvatarIcon" class="text-xl" />
63
+ </ElAvatar>
62
64
  </div>
63
65
  <div class="w-[calc(100%-45px)] ml-3.5">
64
66
  <h4 class="text-xs font-normal leading-5.5">{{ item.title }}</h4>
@@ -106,13 +108,7 @@
106
108
  import { computed, ref, watch, type Ref, type ComputedRef } from 'vue'
107
109
  import { useI18n } from 'vue-i18n'
108
110
 
109
- // 导入头像图片
110
- import avatar1 from '@/assets/images/avatar/avatar1.webp'
111
- import avatar2 from '@/assets/images/avatar/avatar2.webp'
112
- import avatar3 from '@/assets/images/avatar/avatar3.webp'
113
- import avatar4 from '@/assets/images/avatar/avatar4.webp'
114
- import avatar5 from '@/assets/images/avatar/avatar5.webp'
115
- import avatar6 from '@/assets/images/avatar/avatar6.webp'
111
+ import AppConfig from '@/config'
116
112
 
117
113
  defineOptions({ name: 'ArtNotification' })
118
114
 
@@ -131,7 +127,7 @@
131
127
  /** 时间 */
132
128
  time: string
133
129
  /** 头像 */
134
- avatar: string
130
+ avatar?: string
135
131
  }
136
132
 
137
133
  interface PendingItem {
@@ -210,33 +206,27 @@
210
206
  const msgList = ref<MessageItem[]>([
211
207
  {
212
208
  title: '池不胖 关注了你',
213
- time: '2021-2-26 23:50',
214
- avatar: avatar1
209
+ time: '2021-2-26 23:50'
215
210
  },
216
211
  {
217
212
  title: '唐不苦 关注了你',
218
- time: '2021-2-21 8:05',
219
- avatar: avatar2
213
+ time: '2021-2-21 8:05'
220
214
  },
221
215
  {
222
216
  title: '中小鱼 关注了你',
223
- time: '2020-1-17 21:12',
224
- avatar: avatar3
217
+ time: '2020-1-17 21:12'
225
218
  },
226
219
  {
227
220
  title: '何小荷 关注了你',
228
- time: '2021-01-14 0:20',
229
- avatar: avatar4
221
+ time: '2021-01-14 0:20'
230
222
  },
231
223
  {
232
224
  title: '誶誶淰 关注了你',
233
- time: '2020-12-20 0:15',
234
- avatar: avatar5
225
+ time: '2020-12-20 0:15'
235
226
  },
236
227
  {
237
228
  title: '冷月呆呆 关注了你',
238
- time: '2020-12-17 22:06',
239
- avatar: avatar6
229
+ time: '2020-12-17 22:06'
240
230
  }
241
231
  ])
242
232
 
@@ -12,9 +12,13 @@
12
12
  <div class="screen-lock__panel">
13
13
  <ElAvatar
14
14
  :size="72"
15
- :src="userInfo.avatar || AppConfig.assets.defaultAvatar"
15
+ :src="userInfo.avatar"
16
16
  class="screen-lock__avatar"
17
- />
17
+ role="img"
18
+ :aria-label="userInfo.userName || '用户头像'"
19
+ >
20
+ <ArtSvgIcon :icon="AppConfig.assets.defaultAvatarIcon" class="text-[40px]" />
21
+ </ElAvatar>
18
22
  <div class="screen-lock__name">{{ userInfo.userName || 'User' }}</div>
19
23
 
20
24
  <!-- 已设置密码:输入密码解锁 -->
@@ -34,7 +34,6 @@ import { configImages } from './assets/images'
34
34
  import fastEnterConfig from './modules/fastEnter'
35
35
  import logo from '@imgs/common/logo.webp'
36
36
  import favicon from '@imgs/favicon.ico'
37
- import defaultAvatar from '@imgs/user/avatar.webp'
38
37
 
39
38
  const appConfig: SystemConfig = {
40
39
  // 系统信息
@@ -78,7 +77,7 @@ const appConfig: SystemConfig = {
78
77
  namespace: 'admin-template'
79
78
  },
80
79
  assets: {
81
- defaultAvatar
80
+ defaultAvatarIcon: 'ri:user-3-line'
82
81
  },
83
82
  links: {
84
83
  documentation: '',
@@ -31,3 +31,4 @@ declare module 'qrcode.vue' {
31
31
  // 全局变量声明
32
32
  declare const __APP_VERSION__: string // 版本号
33
33
  declare const __BUILD_ID__: string // 每次构建的唯一标识,可由 CI 注入
34
+ declare const __BUILD_INFO__: Readonly<import('./types/build-info').BuildInfo>
@@ -0,0 +1,11 @@
1
+ /** 当前页面所加载产物的构建信息,所有字段均可公开。 */
2
+ export interface BuildInfo {
3
+ version: string
4
+ buildId: string
5
+ gitCommit: string | null
6
+ /** null 表示无法确认工作区状态(例如没有 Git 或由 CI 仅注入提交号)。 */
7
+ gitDirty: boolean | null
8
+ builtAt: string
9
+ /** Vite 构建模式,不代表实际部署环境。 */
10
+ mode: string
11
+ }
@@ -124,7 +124,7 @@ export interface AppStorageConfig {
124
124
  }
125
125
 
126
126
  export interface AppAssetConfig {
127
- defaultAvatar: string
127
+ defaultAvatarIcon: string
128
128
  }
129
129
 
130
130
  export interface AppLinkConfig {
@@ -199,8 +199,6 @@ export interface SystemConfig {
199
199
  export interface EnvConfig {
200
200
  // 环境名称
201
201
  NODE_ENV: string
202
- // 应用版本
203
- VITE_VERSION: string
204
202
  // 应用端口
205
203
  VITE_PORT: string
206
204
  // 应用基础路径
@@ -1,9 +1,65 @@
1
- import AppConfig from '@/config'
1
+ const info = __BUILD_INFO__
2
+ const builtAt = Object.fromEntries(
3
+ new Intl.DateTimeFormat('zh-CN', {
4
+ year: 'numeric',
5
+ month: '2-digit',
6
+ day: '2-digit',
7
+ hour: '2-digit',
8
+ minute: '2-digit',
9
+ second: '2-digit',
10
+ hourCycle: 'h23',
11
+ timeZoneName: 'shortOffset'
12
+ })
13
+ .formatToParts(new Date(info.builtAt))
14
+ .map(({ type, value }) => [type, value])
15
+ )
16
+ const localBuildTime = [
17
+ `${builtAt.year}-${builtAt.month}-${builtAt.day}`,
18
+ `${builtAt.hour}:${builtAt.minute}:${builtAt.second}`,
19
+ builtAt.timeZoneName
20
+ ].join(' ')
21
+ const font = 'font-family:ui-monospace,SFMono-Regular,Consolas,monospace;'
22
+ const badge = `${font}padding:5px 10px;font-size:12px;line-height:2;font-weight:600;`
23
+ const labelStyle = `${font}color:#7b8798;line-height:1.9;`
24
+ const valueStyle = `${font}color:inherit;line-height:1.9;`
25
+ const workspace =
26
+ info.gitDirty === null
27
+ ? { text: 'Unknown · 无法确认', color: '#7b8798' }
28
+ : info.gitDirty
29
+ ? { text: 'Dirty · 有未提交改动', color: '#d97706' }
30
+ : { text: 'Clean · 无未提交改动', color: '#16a34a' }
2
31
 
3
- const banner = [
4
- `%c${AppConfig.systemInfo.name}%c ${AppConfig.systemInfo.description ?? ''}`,
5
- 'padding:4px 8px;border-radius:6px 0 0 6px;background:#1e40af;color:#fff;font-weight:600',
6
- 'padding:4px 8px;border-radius:0 6px 6px 0;background:#dbeafe;color:#1e3a8a;font-weight:500'
7
- ] as const
32
+ const rows = [
33
+ { label: 'Build ID', value: info.buildId, style: valueStyle },
34
+ { label: 'Commit', value: info.gitCommit?.slice(0, 12) ?? 'Unavailable', style: valueStyle },
35
+ {
36
+ label: 'Built at',
37
+ value: localBuildTime,
38
+ style: valueStyle
39
+ },
40
+ {
41
+ label: 'Workspace',
42
+ value: workspace.text,
43
+ style: `${font}color:${workspace.color};line-height:1.9;`
44
+ }
45
+ ]
8
46
 
9
- console.info(...banner)
47
+ const details = rows.map(({ label }) => `%c ${label.padEnd(11)}%c%s`).join('\n')
48
+
49
+ // 只有启动信息通过绑定调用保留;业务 console.info 仍由生产构建移除。
50
+ const printBuildInfo = console.info.bind(console)
51
+ printBuildInfo(
52
+ `%cBuild Info%c v%s %c %s %c\n\n${details}\n\n%c Details %c%o`,
53
+ `${badge}background:#2563eb;color:#fff;border-radius:6px 0 0 6px;`,
54
+ `${badge}background:#dbeafe;color:#1e40af;border-radius:0 6px 6px 0;`,
55
+ info.version,
56
+ `${badge}background:#e2e8f0;color:#334155;border-radius:6px;margin-left:8px;`,
57
+ info.mode.toUpperCase(),
58
+ '',
59
+ ...rows.flatMap(({ value, style }) => [labelStyle, style, value]),
60
+ labelStyle,
61
+ valueStyle,
62
+ info
63
+ )
64
+
65
+ export {}
@@ -0,0 +1,151 @@
1
+ // @vitest-environment node
2
+ import { execFileSync } from 'node:child_process'
3
+ import { mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promises'
4
+ import os from 'node:os'
5
+ import path from 'node:path'
6
+ import { fileURLToPath } from 'node:url'
7
+ import { runInNewContext } from 'node:vm'
8
+ import { build } from 'vite'
9
+ import { afterEach, describe, expect, it, vi } from 'vitest'
10
+ import { buildInfoPlugin, createBuildInfo } from '../../../scripts/build-info'
11
+
12
+ const directories: string[] = []
13
+ const git = (root: string, ...args: string[]) =>
14
+ execFileSync('git', args, {
15
+ cwd: root,
16
+ encoding: 'utf8',
17
+ stdio: ['ignore', 'pipe', 'pipe']
18
+ }).trim()
19
+
20
+ async function fixture(withGit = false) {
21
+ const root = await realpath(await mkdtemp(path.join(os.tmpdir(), 'kevairy-build-info-')))
22
+ directories.push(root)
23
+ await writeFile(path.join(root, 'package.json'), JSON.stringify({ version: '1.2.3' }))
24
+ if (withGit) {
25
+ git(root, 'init')
26
+ git(root, 'add', 'package.json')
27
+ git(
28
+ root,
29
+ '-c',
30
+ 'user.name=Build Test',
31
+ '-c',
32
+ 'user.email=build-test@example.invalid',
33
+ '-c',
34
+ 'commit.gpgsign=false',
35
+ '-c',
36
+ 'core.hooksPath=/dev/null',
37
+ 'commit',
38
+ '-m',
39
+ 'Initial fixture'
40
+ )
41
+ }
42
+ return root
43
+ }
44
+
45
+ afterEach(async () => {
46
+ vi.useRealTimers()
47
+ await Promise.all(directories.splice(0).map((root) => rm(root, { recursive: true, force: true })))
48
+ })
49
+
50
+ describe('build identity', () => {
51
+ it('uses the project version and creates distinct IDs even within the same millisecond', async () => {
52
+ const root = await fixture()
53
+ vi.useFakeTimers()
54
+ vi.setSystemTime(new Date('2026-11-11T07:30:00.000Z'))
55
+ const first = createBuildInfo({ root, mode: 'production' })
56
+ const second = createBuildInfo({ root, mode: 'production' })
57
+ expect(first).toMatchObject({
58
+ version: '1.2.3',
59
+ builtAt: '2026-11-11T07:30:00.000Z',
60
+ gitCommit: null,
61
+ gitDirty: null,
62
+ mode: 'production'
63
+ })
64
+ expect(first.buildId).toMatch(/^20261111T073000000Z-nogit-[a-f0-9]{8}$/)
65
+ expect(second.buildId).not.toBe(first.buildId)
66
+ expect(JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8')).version).toBe(
67
+ '1.2.3'
68
+ )
69
+ })
70
+
71
+ it('records clean commits and detects both tracked and untracked changes', async () => {
72
+ const root = await fixture(true)
73
+ const clean = createBuildInfo({ root, mode: 'production' })
74
+ expect(clean.gitCommit).toBe(git(root, 'rev-parse', 'HEAD'))
75
+ expect(clean.gitDirty).toBe(false)
76
+ await writeFile(path.join(root, 'new-file.txt'), 'Untracked change')
77
+ expect(createBuildInfo({ root, mode: 'production' }).gitDirty).toBe(true)
78
+ await rm(path.join(root, 'new-file.txt'))
79
+ await writeFile(path.join(root, 'package.json'), JSON.stringify({ version: '1.2.4' }))
80
+ const dirty = createBuildInfo({ root, mode: 'production' })
81
+ expect(dirty.gitDirty).toBe(true)
82
+ expect(dirty.buildId).toContain('-dirty-')
83
+ expect(dirty.version).toBe('1.2.4')
84
+ expect(dirty.gitCommit).toBe(clean.gitCommit)
85
+ })
86
+
87
+ it('handles a repository without a first commit and supports CI overrides', async () => {
88
+ const root = await fixture()
89
+ git(root, 'init')
90
+ expect(createBuildInfo({ root, mode: 'production' })).toMatchObject({
91
+ gitCommit: null,
92
+ gitDirty: true
93
+ })
94
+ const options = { root, mode: 'staging', buildId: 'pipeline-123', gitCommit: 'a'.repeat(40) }
95
+ expect(createBuildInfo(options)).toMatchObject({
96
+ buildId: 'pipeline-123',
97
+ gitCommit: 'a'.repeat(40),
98
+ gitDirty: null,
99
+ mode: 'staging'
100
+ })
101
+ expect(createBuildInfo({ ...options, gitDirty: 'false' }).gitDirty).toBe(false)
102
+ expect(() => createBuildInfo({ ...options, gitDirty: 'invalid' })).toThrow('BUILD_GIT_DIRTY')
103
+ })
104
+
105
+ it('keeps the startup identity in minified production JS and matches version.json', async () => {
106
+ const root = await fixture()
107
+ const consolePath = fileURLToPath(new URL('../../../src/utils/sys/console.ts', import.meta.url))
108
+ await writeFile(
109
+ path.join(root, 'index.html'),
110
+ '<script type="module" src="/entry.ts"></script>'
111
+ )
112
+ await writeFile(
113
+ path.join(root, 'entry.ts'),
114
+ `
115
+ import ${JSON.stringify(consolePath)}
116
+ console.info('business-log-must-be-removed')
117
+ globalThis.diagnosticIdentity = [__APP_VERSION__, __BUILD_ID__]
118
+ `
119
+ )
120
+ await writeFile(
121
+ path.join(root, 'config.ts'),
122
+ `
123
+ export default { systemInfo: { name: 'Fixture App', description: 'Test' } }
124
+ `
125
+ )
126
+ const info = createBuildInfo({ root, mode: 'production' })
127
+ const result = await build({
128
+ root,
129
+ configFile: false,
130
+ logLevel: 'silent',
131
+ base: '/admin/',
132
+ plugins: [buildInfoPlugin(info)],
133
+ resolve: { alias: { '@/config': path.join(root, 'config.ts') } },
134
+ esbuild: { pure: ['console.log', 'console.debug', 'console.info'], drop: ['debugger'] },
135
+ build: { write: false, modulePreload: false, minify: 'esbuild' }
136
+ })
137
+ if (Array.isArray(result) || !('output' in result)) throw new Error('Expected one build output')
138
+ const manifest = result.output.find((item) => item.fileName === 'version.json')
139
+ if (!manifest || manifest.type !== 'asset') throw new Error('Missing version.json')
140
+ expect(JSON.parse(String(manifest.source))).toEqual(info)
141
+ const entry = result.output.find((item) => item.type === 'chunk' && item.isEntry)
142
+ if (!entry || entry.type !== 'chunk') throw new Error('Missing entry JS')
143
+ const log = vi.fn()
144
+ const context = { console: { info: log }, diagnosticIdentity: [] }
145
+ runInNewContext(entry.code, context)
146
+ expect(log).toHaveBeenCalledTimes(1)
147
+ expect(log.mock.calls[0].at(-1)).toEqual(info)
148
+ expect(context.diagnosticIdentity).toEqual([info.version, info.buildId])
149
+ expect(entry.code).not.toContain('business-log-must-be-removed')
150
+ })
151
+ })
@@ -23,6 +23,13 @@
23
23
  "@styles/*": ["src/assets/styles/*"]
24
24
  }
25
25
  },
26
- "include": ["src/**/*", "src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
26
+ "include": [
27
+ "src/**/*",
28
+ "src/**/*.ts",
29
+ "src/**/*.d.ts",
30
+ "src/**/*.tsx",
31
+ "src/**/*.vue",
32
+ "scripts/**/*.ts"
33
+ ],
27
34
  "exclude": ["node_modules", "dist", "**/*.js"]
28
35
  }
@@ -1,4 +1,4 @@
1
- import { defineConfig, loadEnv } from 'vite'
1
+ import { defineConfig, loadEnv, type ConfigEnv } from 'vite'
2
2
  import vue from '@vitejs/plugin-vue'
3
3
  import path from 'path'
4
4
  import { fileURLToPath } from 'url'
@@ -6,12 +6,22 @@ import Components from 'unplugin-vue-components/vite'
6
6
  import AutoImport from 'unplugin-auto-import/vite'
7
7
  import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
8
8
  import tailwindcss from '@tailwindcss/vite'
9
+ import { buildInfoPlugin, createBuildInfo } from './scripts/build-info'
9
10
  // import { visualizer } from 'rollup-plugin-visualizer'
10
11
 
11
- export default ({ mode }: { mode: string }) => {
12
- const root = process.cwd()
12
+ export default ({ mode, isPreview }: ConfigEnv) => {
13
+ const root = fileURLToPath(new URL('.', import.meta.url))
13
14
  const env = loadEnv(mode, root)
14
- const { VITE_VERSION, VITE_PORT, VITE_BASE_URL, VITE_API_URL, VITE_API_PROXY_URL } = env
15
+ const { VITE_PORT, VITE_BASE_URL, VITE_API_URL, VITE_API_PROXY_URL } = env
16
+ const buildInfo = isPreview
17
+ ? undefined
18
+ : createBuildInfo({
19
+ root,
20
+ mode,
21
+ buildId: env.VITE_BUILD_ID,
22
+ gitCommit: process.env.BUILD_GIT_COMMIT,
23
+ gitDirty: process.env.BUILD_GIT_DIRTY
24
+ })
15
25
  const proxy = VITE_API_PROXY_URL
16
26
  ? {
17
27
  '/api': {
@@ -24,13 +34,9 @@ export default ({ mode }: { mode: string }) => {
24
34
  : undefined
25
35
 
26
36
  console.log(`🚀 API_URL = ${VITE_API_URL}`)
27
- console.log(`🚀 VERSION = ${VITE_VERSION}`)
37
+ if (buildInfo) console.log(`🚀 VERSION = ${buildInfo.version} / BUILD = ${buildInfo.buildId}`)
28
38
 
29
39
  return defineConfig({
30
- define: {
31
- __APP_VERSION__: JSON.stringify(VITE_VERSION),
32
- __BUILD_ID__: JSON.stringify(env.VITE_BUILD_ID || new Date().toISOString())
33
- },
34
40
  base: VITE_BASE_URL,
35
41
  server: {
36
42
  port: Number(VITE_PORT),
@@ -67,6 +73,7 @@ export default ({ mode }: { mode: string }) => {
67
73
  }
68
74
  },
69
75
  plugins: [
76
+ ...(buildInfo ? [buildInfoPlugin(buildInfo)] : []),
70
77
  vue(),
71
78
  tailwindcss(),
72
79
  // 自动按需导入 API
@@ -1,5 +0,0 @@
1
- <svg
2
- viewBox="0 0 400 300"
3
- fill="none"
4
- xmlns="http://www.w3.org/2000/svg"
5
- ><mask id="a" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="47" y="38" width="307" height="224"><path d="M353.3 38H47.5v223.8h305.8V38Z" fill="#fff"/></mask><g mask="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M299.2 200.6H61.6v5.1h240.3l-2.7-5.1Z" fill="#C7DEFF"/><path d="m308.9 185.8-6.5 20H183.7M332.3 127.6h10.6l-5 16.7-14.8-.1-7.2 21.1M328.8 127.4l13.6-39.6M307.6 166 337 84.7H180.6l-9.8 26.9h-10.5M296.6 196l4.3-11.8M157.2 149.2l6.4-17.7" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M324.8 93.1H188.5l-34.8 95.8h136.4l34.7-95.8ZM169.9 166.2l5-13.6-5 13.6Z" fill="#fff"/><path d="m169.9 166.2 5-13.6" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M324.8 93.1H188.5l-4 11.7h135.8l4.5-11.7Z" fill="#006EFF"/><path fill-rule="evenodd" clip-rule="evenodd" d="M102.6 159.5h38.3l2.7 36.6h-38.4c-10.1 0-20.9-8.2-20.9-18.3 0-10.1 8.2-18.3 18.3-18.3Z" fill="#DEEBFC"/><path fill-rule="evenodd" clip-rule="evenodd" d="M84.3 174.102c2.5 3.4 10 5 17.9 2.8 16.6-6.5 23.8-3.9 23.8-3.9s.5-3.4 1.3-5c-5.8-3-15.4.3-26.1 3.1-10.7 2.8-15.8-2.5-15.8-2.5-.4 0-1.1 2.8-1.1 5.5Z" fill="#fff"/><path d="M96.5 194.2c-7.2-3.3-12.2-10.5-12.2-19m0 0c0-11.5 9.3-20.8 20.8-20.8h29.4" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M140.3 195.1c-8.4-2.7-14.5-10.6-14.5-19.8l14.5 19.8Zm-14.5-19.8c0-11.5 9.3-20.8 20.8-20.8l-20.8 20.8Zm20.8-20.8c11.5 0 20.8 9.3 20.8 20.8l-20.8-20.8Zm20.8 20.8c0 8.4-5 15.6-12.1 18.9l12.1-18.9Z" fill="#fff"/><path d="M140.3 195.1c-8.4-2.7-14.5-10.6-14.5-19.8m0 0c0-11.5 9.3-20.8 20.8-20.8m0 0c11.5 0 20.8 9.3 20.8 20.8m0 0c0 8.4-5 15.6-12.1 18.9" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M161.5 177.2c0-7.7-6.3-14-14-14s-14 6.3-14 14c0 5.8 3.5 10.8 8.6 12.9.1 0 5.8 1.6 10.7 0 5.3-1.7 8.7-7.1 8.7-12.9Z" fill="#00E4E5"/><path d="M140.5 190.1c-5.8-2.4-9.9-8.2-9.9-14.9 0-8.9 7.2-16.1 16.1-16.1 8.9 0 16.1 7.2 16.1 16.1 0 6.8-4.2 12.5-10.1 14.9M88.4 170.604c2.9 1.3 7.7 2.6 13.6.3 14.7-5.7 22.3-4.3 24.6-3.5M84.5 174.599s5.9 6.5 19 1.7c9.2-3.4 15.3-3.9 18.8-3.8" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M340.6 112.3h-55.2l-2.7 6.2H338l2.6-6.2Z" fill="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M236.8 117.9c-16.13 0-29.2 13.07-29.2 29.2s13.07 29.2 29.2 29.2 29.2-13.07 29.2-29.2-13.07-29.2-29.2-29.2Z" fill="#00E4E5"/><path d="M265 123.3c13.1 13.1 13.1 34.4 0 47.6M306 205.9h19.2M61.7 205.9h32.9M181.2 196.2h115.2M47.5 205.9h10v-9.7h73.8" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M146.7 179.2c-2.49 0-4.5 2.01-4.5 4.5s2.01 4.5 4.5 4.5 4.5-2.01 4.5-4.5-2.01-4.5-4.5-4.5Z" fill="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M169.5 196.2c3.9 0 7.1 3.2 7.1 7.1 0 3.9-3.2 7.1-7.1 7.1H144c-2.1 0-3.9 1.7-3.9 3.9v1c0 2.1 1.7 3.9 3.9 3.9h48c5.1 0 9.2 4.1 9.2 9.2s-4.1 9.3-9.2 9.2h-33.8c-2.3 0-4.1 1.8-4.1 4.1s1.8 4.1 4.1 4.1h4.2c4.4 0 8 3.6 8 8s-3.6 8-8 8H111c-3.7 0-6.8-3-6.8-6.8 0-3.7 3-6.8 6.8-6.8h.3c2.3 0 4.1-1.8 4.1-4.1s-1.8-4.1-4.1-4.1H79c-4.5 0-8.1-3.6-8.1-8.1s3.6-8.1 8.1-8.1h37.7c2.1 0 3.9-1.7 3.9-3.9 0-2.1-1.7-3.9-3.9-3.9h-7.9c-4.4 0-7.9-3.5-7.9-7.9s3.5-7.9 7.9-7.9h30.4c2.2 0 3.9-1.8 3.9-3.9V187c0-1.9 1.6-3.5 3.5-3.5s3.5 1.6 3.5 3.5v5.3c0 2.2 1.8 3.9 3.9 3.9h15.5Z" fill="#006EFF"/><path d="m227.8 138.5 18.7 18.7M227.8 157.2l18.7-18.7" stroke="#fff" stroke-width="6"/><path fill-rule="evenodd" clip-rule="evenodd" d="M194.8 96.9c-.99 0-1.8.81-1.8 1.8s.81 1.8 1.8 1.8 1.8-.81 1.8-1.8-.81-1.8-1.8-1.8ZM202.9 96.9c-.99 0-1.8.81-1.8 1.8s.81 1.8 1.8 1.8 1.8-.81 1.8-1.8-.81-1.8-1.8-1.8Z" fill="#fff"/><path d="m291.7 184.3-1.6 4.6h-121M298.1 166.7l22.5-61.9" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="m193 134.1 2.2-5.1h-19.4l-2.3 5.1H193ZM313.2 123.5l2.2-5.1h-24.5l-2.3 5.1h24.6Z" fill="#DEEBFC"/><path d="m164.5 159.2 19.8-54.6" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M199.6 119.8h-53.2l-4.4 9.3h53.2l4.4-9.3Z" fill="#00E4E5"/><path d="M151.3 129.1H142l4.4-9.3h16.9" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M353.3 169.4h-67.4l-4.8 12.2h67.3l4.9-12.2Z" fill="#006EFF"/><path d="M332.4 169.4h20.9l-4.9 12.2h-39.7M242.7 235.5v-4.8c0-3.8 3.1-7 7-7h20.2c3.8 0 7 3.1 7 7" stroke="#071F4D"/><path d="M261.1 235.5v-4.8c0-3.8 3.1-7 7-7h13.7c3.8 0 7 3.1 7 7v4.8M242.6 230.7h13.7M235.2 237.7h63.3M224 237.7h6.7" stroke="#071F4D"/><path fill-rule="evenodd" clip-rule="evenodd" d="M324.1 141.3H335l3.3-10.7h-10.2l-4 10.7Z" fill="#C7DEFF"/><path fill-rule="evenodd" clip-rule="evenodd" d="M288.3 230.4c0-3.6-2.9-6.5-6.5-6.5h-14.2c-3.6 0-6.5 2.9-6.5 6.5v5.3h27.2v-5.3Z" fill="#071F4D"/><path d="M80.4 228.5H83M87.7 228.5h19.2M146.3 195.8v2c0 3.6-2.9 6.6-6.6 6.6H138M133.4 204.3h1.5M154 249.9h9.4" stroke="#DEEBFC"/><path d="m299.4 141.9 5.1-13.9" stroke="#071F4D"/></g></svg>