diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx index f5c7af97..f0d89270 100644 --- a/src/components/Settings.tsx +++ b/src/components/Settings.tsx @@ -167,6 +167,16 @@ const Settings: React.FC = ({ settings, onSave, onClose, relayPoo +
+ Version {typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : 'dev'} + {typeof __GIT_COMMIT__ !== 'undefined' && __GIT_COMMIT__ ? ( + + {' '}ยท {typeof __GIT_BRANCH__ !== 'undefined' && __GIT_BRANCH__ ? `${__GIT_BRANCH__} ` : ''} + {__GIT_COMMIT__.slice(0, 7)} + {' '}({typeof __BUILD_TIME__ !== 'undefined' ? new Date(__BUILD_TIME__).toLocaleString() : ''}) + + ) : null} +
) } diff --git a/vite.config.ts b/vite.config.ts index 8ab83bea..9e07f72c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,8 +1,43 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import { VitePWA } from 'vite-plugin-pwa' +import { readFileSync } from 'node:fs' +import { execSync } from 'node:child_process' + +function getGitMetadata() { + const envSha = process.env.VERCEL_GIT_COMMIT_SHA || '' + const envRef = process.env.VERCEL_GIT_COMMIT_REF || '' + let commit = envSha + let branch = envRef + try { + if (!commit) commit = execSync('git rev-parse HEAD', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim() + } catch {} + try { + if (!branch) branch = execSync('git rev-parse --abbrev-ref HEAD', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim() + } catch {} + return { commit, branch } +} + +function getPackageVersion() { + try { + const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url)).toString()) + return pkg.version as string + } catch { + return '0.0.0' + } +} + +const { commit, branch } = getGitMetadata() +const version = getPackageVersion() +const buildTime = new Date().toISOString() export default defineConfig({ + define: { + __APP_VERSION__: JSON.stringify(version), + __GIT_COMMIT__: JSON.stringify(commit), + __GIT_BRANCH__: JSON.stringify(branch), + __BUILD_TIME__: JSON.stringify(buildTime) + }, plugins: [ react(), VitePWA({