From a3905241d00f2a1edcc65c6859c078fbc4ad3920 Mon Sep 17 00:00:00 2001 From: hmerritt Date: Tue, 2 Jan 2024 23:03:50 +0000 Subject: [PATCH] feat: global version info --- src/lib/global/global.d.ts | 12 +++++++++++- src/lib/global/index.ts | 4 ++-- src/lib/global/version.ts | 10 ++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/lib/global/global.d.ts b/src/lib/global/global.d.ts index 468b6c5..83eb5dc 100644 --- a/src/lib/global/global.d.ts +++ b/src/lib/global/global.d.ts @@ -1,5 +1,5 @@ -import type { LogStoreType } from "./log"; import type { FeatureFlags, FeatureOptions } from "./featureFlags"; +import type { LogStoreType } from "./log"; type LogFunction = (logLevel: any, ...args: any[]) => void; type FeatureFunction = (mode: FeatureFlags, options?: FeatureOptions) => boolean; @@ -9,6 +9,11 @@ declare global { var debug: LogFunction; var logStore: LogStoreType; var feature: FeatureFunction; + var appName: string; + var appVersion: any; + var gitBranch: any; + var gitCommitHash: any; + var environment: string; var getNumberOfEventListeners: () => number; var getObjectOfEventListeners: () => Record; @@ -17,6 +22,11 @@ declare global { debug: LogFunction; logStore: LogStoreType; feature: FeatureFunction; + appName: string; + appVersion: any; + gitBranch: any; + gitCommitHash: any; + environment: string; getNumberOfEventListeners: () => number; getObjectOfEventListeners: () => Record; } diff --git a/src/lib/global/index.ts b/src/lib/global/index.ts index 0f42c06..6ef3e2a 100644 --- a/src/lib/global/index.ts +++ b/src/lib/global/index.ts @@ -10,11 +10,10 @@ * * @Warning - Since the window object is exposed, don't put anything remotely sensitive in here. */ - import { injectDevTools } from "./devTools"; import { injectFeature } from "./featureFlags"; import { injectLog } from "./log"; -import { versionString } from "./version"; +import { injectVersion, versionString } from "./version"; export const globalInit = () => { if (import.meta.env.MODE !== "test") @@ -23,6 +22,7 @@ export const globalInit = () => { // Inject global functions. injectLog(); injectFeature(); + injectVersion(); if (import.meta.env.MODE !== "production") injectDevTools(); }; diff --git a/src/lib/global/version.ts b/src/lib/global/version.ts index ae9572d..ee95f52 100644 --- a/src/lib/global/version.ts +++ b/src/lib/global/version.ts @@ -1,3 +1,5 @@ +import { $global } from "./utils"; + export const appName = "App"; // Optionally use `import.meta.env.VITE_NAME` export const appVersion = import.meta.env.VITE_VERSION; export const gitBranch = import.meta.env.VITE_GIT_BRANCH; @@ -37,3 +39,11 @@ export const versionString = () => { return versionString; }; + +export const injectVersion = () => { + $global.appName = appName; + $global.appVersion = appVersion; + $global.gitBranch = gitBranch; + $global.gitCommitHash = gitCommitHash; + $global.environment = environment; +};