Skip to content

Commit

Permalink
feat: global version info
Browse files Browse the repository at this point in the history
  • Loading branch information
hmerritt committed Jan 2, 2024
1 parent a30b9ca commit a390524
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/lib/global/global.d.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<string, number>;

Expand All @@ -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<string, number>;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/global/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -23,6 +22,7 @@ export const globalInit = () => {
// Inject global functions.
injectLog();
injectFeature();
injectVersion();
if (import.meta.env.MODE !== "production") injectDevTools();
};

Expand Down
10 changes: 10 additions & 0 deletions src/lib/global/version.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
};

0 comments on commit a390524

Please sign in to comment.