refactor: Stamp build information in as "defines" (#2654)

This commit is contained in:
Dermot Duffy
2026-08-03 22:36:32 -07:00
committed by GitHub
parent 2d124fe3cd
commit 06bcfd58ba
13 changed files with 133 additions and 148 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ import { localize } from './localize/localize.js';
import cardStyle from './scss/card.scss';
import type { MediaLoadedInfoEventDetail } from './types.js';
import { hasAction } from './utils/action.js';
import { getReleaseVersion } from './utils/diagnostics';
import { getReleaseVersion } from './utils/build-info.js';
// ***************************************************************************
// General Card-Wide Notes
+1 -1
View File
@@ -9,7 +9,7 @@ import { customElement, property } from 'lit/decorators.js';
import loadingStyle from '../scss/loading.scss';
import type { EffectName, EffectsManagerInterface } from '../types';
import { getReleaseVersion } from '../utils/diagnostics';
import { getReleaseVersion } from '../utils/build-info.js';
import './icon';
+41
View File
@@ -0,0 +1,41 @@
declare const __ADVANCED_CAMERA_CARD_RELEASE_VERSION__: string | undefined;
declare const __ADVANCED_CAMERA_CARD_GIT_HASH__: string | undefined;
declare const __ADVANCED_CAMERA_CARD_GIT_DATE__: string | undefined;
declare const __ADVANCED_CAMERA_CARD_BUILD_DATE__: string | undefined;
const DEVELOPMENT_VERSION = 'dev';
/* v8 ignore start: substituted by the build -- @preserve */
const RELEASE_VERSION =
typeof __ADVANCED_CAMERA_CARD_RELEASE_VERSION__ === 'undefined'
? DEVELOPMENT_VERSION
: __ADVANCED_CAMERA_CARD_RELEASE_VERSION__;
const GIT_HASH =
typeof __ADVANCED_CAMERA_CARD_GIT_HASH__ === 'undefined'
? undefined
: __ADVANCED_CAMERA_CARD_GIT_HASH__;
const GIT_DATE =
typeof __ADVANCED_CAMERA_CARD_GIT_DATE__ === 'undefined'
? undefined
: __ADVANCED_CAMERA_CARD_GIT_DATE__;
const BUILD_DATE =
typeof __ADVANCED_CAMERA_CARD_BUILD_DATE__ === 'undefined'
? undefined
: __ADVANCED_CAMERA_CARD_BUILD_DATE__;
/* v8 ignore stop -- @preserve */
export interface GitInfo {
hash?: string;
commitDate?: string;
buildDate?: string;
}
export const getReleaseVersion = (): string => RELEASE_VERSION;
export const getGitInfo = (): GitInfo => ({
hash: GIT_HASH,
commitDate: GIT_DATE,
buildDate: BUILD_DATE,
});
+6 -20
View File
@@ -1,4 +1,3 @@
import pkg from '../../package.json';
import type { IssueKey, IssuePresence } from '../card-controller/issues/types';
import type { RawAdvancedCameraCardConfig } from '../config/types';
import { getIntegrationManifest } from '../ha/integration';
@@ -7,6 +6,7 @@ import type { DeviceRegistryManager } from '../ha/registry/device';
import type { HomeAssistant } from '../ha/types';
import { HASS_WEB_PROXY_DOMAIN } from '../ha/web-proxy';
import { getLanguage } from '../localize/localize';
import { getGitInfo, getReleaseVersion } from './build-info';
type FrigateDevices = Record<string, string>;
@@ -21,22 +21,6 @@ interface IntegrationDiagnostics {
version?: string;
}
export const getReleaseVersion = (): string => {
const releaseVersion: string = '__ADVANCED_CAMERA_CARD_RELEASE_VERSION__';
/* v8 ignore if: depends on rollup substitution -- @preserve */
if (releaseVersion === 'pkg') {
return pkg.version;
}
/* v8 ignore if: depends on rollup substitution -- @preserve */
if (releaseVersion === 'dev') {
return `dev+${pkg['gitAbbrevHash']}`;
}
return releaseVersion;
};
interface Diagnostics {
card_version: string;
browser: string;
@@ -103,6 +87,8 @@ export const getDiagnostics = async (
});
});
const gitInfo = getGitInfo();
return {
card_version: getReleaseVersion(),
browser: navigator.userAgent,
@@ -110,9 +96,9 @@ export const getDiagnostics = async (
lang: getLanguage(),
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
git: {
...(pkg['gitAbbrevHash'] && { hash: pkg['gitAbbrevHash'] }),
...(pkg['buildDate'] && { build_date: pkg['buildDate'] }),
...(pkg['gitDate'] && { commit_date: pkg['gitDate'] }),
...(gitInfo.hash && { hash: gitInfo.hash }),
...(gitInfo.buildDate && { build_date: gitInfo.buildDate }),
...(gitInfo.commitDate && { commit_date: gitInfo.commitDate }),
},
...(hass && { ha_version: hass.config.version }),
custom_integrations: {