Skip to content

Commit 25c9305

Browse files
authored
Merge pull request #2236 from dandi/fix-version
Add version string back into frontend
2 parents c7ecf09 + 7416460 commit 25c9305

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

web/vite.config.mts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,35 @@ import VueRouter from 'unplugin-vue-router/vite'
88

99
// Utilities
1010
import { defineConfig } from 'vite'
11+
import { execSync } from 'node:child_process'
1112
import { fileURLToPath, URL } from 'node:url'
1213

1314
import { commonjsDeps } from '@koumoul/vjsf/utils/build.js'
1415

16+
function getVersion() {
17+
// Try to get the version via `git` if available; otherwise fall back on
18+
// the COMMIT_REF environment variable provided by Netlify's build
19+
// environment; if that is missing, report "unknown" as the version.
20+
21+
try {
22+
return execSync('git describe --tags').toString();
23+
} catch {
24+
return process.env.COMMIT_REF ? process.env.COMMIT_REF : 'unknown';
25+
}
26+
}
27+
28+
function getGitRevision() {
29+
try {
30+
return execSync('git rev-parse HEAD').toString();
31+
} catch {
32+
return '';
33+
}
34+
}
35+
36+
process.env.VITE_APP_VERSION = getVersion();
37+
process.env.VITE_APP_GIT_REVISION = getGitRevision();
38+
39+
1540
// https://vitejs.dev/config/
1641
export default defineConfig({
1742
plugins: [

0 commit comments

Comments
 (0)