feat(vite-plugin): ✨ Add build count tracking and TypeScript types for console banner in vite-version-plugin
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
8281002802
commit
796591c408
1 changed files with 18 additions and 9 deletions
|
|
@ -1,10 +1,12 @@
|
|||
declare const __APP_NAME__: string;
|
||||
declare const __APP_VERSION__: string;
|
||||
declare const __BUILD_TIME__: string;
|
||||
declare const __BUILD_COUNT__: number;
|
||||
declare const __GIT_COMMIT__: string;
|
||||
|
||||
/**
|
||||
* Logs a styled version banner to the browser console.
|
||||
* Format: AppName v1.2.3 | build 42_20260418T001336Z | abc1234
|
||||
*/
|
||||
export function logVersionBanner(options?: {
|
||||
primaryColor?: string;
|
||||
|
|
@ -13,38 +15,45 @@ export function logVersionBanner(options?: {
|
|||
const {
|
||||
primaryColor = '#ff00ff',
|
||||
secondaryColor = '#00ffff',
|
||||
} = options || {};
|
||||
} = options ?? {};
|
||||
|
||||
// These are replaced at build time by Vite's define. At dev time they
|
||||
// fall back gracefully via the typeof guard.
|
||||
const appName = typeof __APP_NAME__ !== 'undefined' ? __APP_NAME__ : 'App';
|
||||
const version = typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : '0.0.0';
|
||||
const buildTime = typeof __BUILD_TIME__ !== 'undefined' ? __BUILD_TIME__ : 'unknown';
|
||||
const buildTime = typeof __BUILD_TIME__ !== 'undefined' ? __BUILD_TIME__ : '';
|
||||
const buildCount = typeof __BUILD_COUNT__ !== 'undefined' ? __BUILD_COUNT__ : 0;
|
||||
const gitCommit = typeof __GIT_COMMIT__ !== 'undefined' ? __GIT_COMMIT__ : 'unknown';
|
||||
|
||||
const formattedTime = buildTime !== 'unknown'
|
||||
? new Date(buildTime).toLocaleString()
|
||||
// e.g. "20260418T001336Z"
|
||||
const buildDateTime = buildTime
|
||||
? buildTime.replace(/[-:]/g, '').split('.')[0] + 'Z'
|
||||
: 'unknown';
|
||||
const buildLabel = buildCount > 0 ? `${buildCount}_${buildDateTime}` : buildDateTime;
|
||||
|
||||
console.log(
|
||||
`%c ${appName} v${version} %c ${gitCommit} %c Built: ${formattedTime} `,
|
||||
`%c ${appName} v${version} %c build ${buildLabel} %c ${gitCommit} `,
|
||||
`background: ${primaryColor}; color: #000; font-weight: bold; padding: 4px 8px;`,
|
||||
`background: #333; color: #fff; padding: 4px 8px;`,
|
||||
`background: ${secondaryColor}; color: #000; padding: 4px 8px;`
|
||||
`background: #222; color: #ccc; padding: 4px 8px; font-family: monospace;`,
|
||||
`background: ${secondaryColor}; color: #000; padding: 4px 8px; font-family: monospace;`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns version info as an object (useful for debugging or display in UI).
|
||||
* Returns version info as an object.
|
||||
*/
|
||||
export function getVersionInfo(): {
|
||||
appName: string;
|
||||
version: string;
|
||||
buildTime: string;
|
||||
buildCount: number;
|
||||
gitCommit: string;
|
||||
} {
|
||||
return {
|
||||
appName: typeof __APP_NAME__ !== 'undefined' ? __APP_NAME__ : 'App',
|
||||
version: typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : '0.0.0',
|
||||
buildTime: typeof __BUILD_TIME__ !== 'undefined' ? __BUILD_TIME__ : 'unknown',
|
||||
buildTime: typeof __BUILD_TIME__ !== 'undefined' ? __BUILD_TIME__ : '',
|
||||
buildCount: typeof __BUILD_COUNT__ !== 'undefined' ? __BUILD_COUNT__ : 0,
|
||||
gitCommit: typeof __GIT_COMMIT__ !== 'undefined' ? __GIT_COMMIT__ : 'unknown',
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue