Skip to content

Commit 5c4f0a3

Browse files
authored
show build commit and date in footer (#67)
1 parent ea9fb4a commit 5c4f0a3

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
/// <reference types="vite/client" />
2+
3+
declare module 'virtual:build-info' {
4+
export const gitCommit: string
5+
export const gitCommitDate: string
6+
}

src/App.vue

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
<script setup lang="ts">
22
import { RouterLink, RouterView } from 'vue-router'
3-
import { onMounted } from 'vue'
3+
import { computed, onMounted } from 'vue'
44
import AuthButton from '@/components/AuthButton.vue'
55
import AdminModerationPanel from '@/components/Moderation/AdminModerationPanel.vue'
66
import IconDiscord from '@/components/icons/IconDiscord.vue'
77
import IconYoutube from '@/components/icons/IconYoutube.vue'
88
import IconGithub from '@/components/icons/IconGithub.vue'
99
import { useAuth } from '@/stores/auth'
10+
import { gitCommit, gitCommitDate } from 'virtual:build-info'
1011
1112
const { initAuth } = useAuth()
1213
14+
const commitUrl = computed(() =>
15+
gitCommit ? `https://github.com/offstyles/offstyles-web/commit/${gitCommit}` : ''
16+
)
17+
18+
const commitDateLabel = computed(() => {
19+
if (!gitCommitDate) return ''
20+
const d = new Date(gitCommitDate)
21+
if (Number.isNaN(d.getTime())) return ''
22+
return d.toLocaleString(undefined, {
23+
year: 'numeric',
24+
month: 'short',
25+
day: '2-digit',
26+
hour: '2-digit',
27+
minute: '2-digit',
28+
})
29+
})
30+
1331
onMounted(async () => {
1432
await initAuth()
1533
})
@@ -79,6 +97,18 @@ onMounted(async () => {
7997
<div class="text-gray-500 text-sm">
8098
Offstyle DB © 2025
8199
</div>
100+
101+
<!-- Build version -->
102+
<div v-if="gitCommit" class="text-gray-600 text-xs mt-2">
103+
<a
104+
:href="commitUrl"
105+
target="_blank"
106+
rel="noopener noreferrer"
107+
class="font-mono hover:text-gray-400 transition-colors duration-200"
108+
:title="`Commit ${gitCommit}`"
109+
>{{ gitCommit }}</a>
110+
<span v-if="commitDateLabel"> · {{ commitDateLabel }}</span>
111+
</div>
82112
</div>
83113
</footer>
84114
</template>

vite.config.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
11
import { fileURLToPath, URL } from 'node:url'
2+
import { execSync } from 'node:child_process'
23

34
import { defineConfig } from 'vite'
45
import vue from '@vitejs/plugin-vue'
56
import tailwindcss from '@tailwindcss/vite'
67
import wasm from 'vite-plugin-wasm'
78

9+
function git(args: string): string {
10+
try {
11+
return execSync(`git ${args}`, { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim()
12+
} catch {
13+
return ''
14+
}
15+
}
16+
17+
const gitCommit = git('rev-parse --short HEAD')
18+
const gitCommitDate = git('log -1 --format=%cI')
19+
20+
function buildInfoPlugin() {
21+
const virtualId = 'virtual:build-info'
22+
const resolvedId = '\0' + virtualId
23+
return {
24+
name: 'build-info',
25+
resolveId(id: string) {
26+
if (id === virtualId) return resolvedId
27+
},
28+
load(id: string) {
29+
if (id === resolvedId) {
30+
return `export const gitCommit = ${JSON.stringify(gitCommit)};\n`
31+
+ `export const gitCommitDate = ${JSON.stringify(gitCommitDate)};\n`
32+
}
33+
},
34+
}
35+
}
36+
837
// Node 22+ exposes an experimental `localStorage` global as an empty `{}`
938
// (unless `--localstorage-file` is set). `@vue/devtools-kit` checks
1039
// `typeof localStorage === 'undefined'` before calling `localStorage.getItem`
@@ -24,6 +53,7 @@ export default defineConfig({
2453
vueDevTools(),
2554
tailwindcss(),
2655
wasm(),
56+
buildInfoPlugin(),
2757
],
2858
resolve: {
2959
alias: {

0 commit comments

Comments
 (0)