From 06962f3d807bb81c2212b62ab26446686cdb1343 Mon Sep 17 00:00:00 2001 From: "Vanya A. Sergeev" Date: Fri, 24 Feb 2023 05:38:19 -0600 Subject: [PATCH] add package version and commit id global constants --- src/vite-env.d.ts | 9 +++++++++ vite.config.ts | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 4078e74..b986b54 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -1,2 +1,11 @@ /// /// + +declare global { + interface Window { + __APP_VERSION__: string; + __APP_COMMIT_ID__: string; + } +} + +export {}; diff --git a/vite.config.ts b/vite.config.ts index 9cac67c..c4712af 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,8 +1,22 @@ import { defineConfig } from 'vite'; import { svelte } from '@sveltejs/vite-plugin-svelte'; +import * as child_process from 'child_process'; + +/* Get commit id */ +let commitId: string; +try { + commitId = child_process.execSync('git rev-parse --short HEAD 2>/dev/null').toString(); +} catch { + commitId = 'unknown'; +} + // https://vitejs.dev/config/ export default defineConfig({ base: '', + define: { + 'window.__APP_VERSION__': JSON.stringify(process.env.npm_package_version), + 'window.__APP_COMMIT_ID__': JSON.stringify(commitId), + }, plugins: [svelte()], });