feat: 게임 정보에 빌드 커밋 표시
프로필 배포가 고정한 전체 커밋 SHA를 프론트 빌드와 Turbo 캐시 입력에 전달한다. 게임 정보 대화상자와 데스크톱·모바일 Chromium 검증을 함께 보강한다.
This commit is contained in:
@@ -1,9 +1,29 @@
|
||||
import { defineConfig, loadEnv } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import path from 'path';
|
||||
import { mergeViteEnv } from './src/config/viteEnv';
|
||||
|
||||
const fullCommitShaPattern = /^[0-9a-f]{40,64}$/iu;
|
||||
|
||||
export const resolveBuildCommitSha = (explicitSha: string | undefined, repositoryRoot: string): string => {
|
||||
const normalizedExplicitSha = explicitSha?.trim();
|
||||
if (normalizedExplicitSha && fullCommitShaPattern.test(normalizedExplicitSha)) {
|
||||
return normalizedExplicitSha.toLowerCase();
|
||||
}
|
||||
try {
|
||||
const repositorySha = execFileSync('git', ['rev-parse', 'HEAD'], {
|
||||
cwd: repositoryRoot,
|
||||
encoding: 'utf8',
|
||||
stdio: ['ignore', 'pipe', 'ignore'],
|
||||
}).trim();
|
||||
return fullCommitShaPattern.test(repositorySha) ? repositorySha.toLowerCase() : 'unknown';
|
||||
} catch {
|
||||
return 'unknown';
|
||||
}
|
||||
};
|
||||
|
||||
const normalizeBasePath = (value: string | undefined): string => {
|
||||
const pathValue = (value ?? '/').trim();
|
||||
if (!pathValue || pathValue === '/') {
|
||||
@@ -27,9 +47,13 @@ const resolvePreviewAllowedHosts = (value: string | undefined): true | string[]
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = mergeViteEnv(loadEnv(mode, process.cwd(), ''), process.env);
|
||||
const buildCommitSha = resolveBuildCommitSha(env.VITE_BUILD_COMMIT_SHA, path.resolve(import.meta.dirname, '../..'));
|
||||
return {
|
||||
base: normalizeBasePath(env.VITE_APP_BASE_PATH),
|
||||
plugins: [vue(), tailwindcss()],
|
||||
define: {
|
||||
'import.meta.env.VITE_BUILD_COMMIT_SHA': JSON.stringify(buildCommitSha),
|
||||
},
|
||||
build: {
|
||||
sourcemap: true,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user