From 796591c408ae78fdcd0d995da8142918ce0a4cce Mon Sep 17 00:00:00 2001 From: autocommit Date: Fri, 17 Apr 2026 17:37:06 -0700 Subject: [PATCH] =?UTF-8?q?feat(vite-plugin):=20=E2=9C=A8=20Add=20build=20?= =?UTF-8?q?count=20tracking=20and=20TypeScript=20types=20for=20console=20b?= =?UTF-8?q?anner=20in=20vite-version-plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- .../vite-version-plugin/src/console-banner.ts | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/vite-version-plugin/src/console-banner.ts b/packages/vite-version-plugin/src/console-banner.ts index cc18942..47cc86a 100644 --- a/packages/vite-version-plugin/src/console-banner.ts +++ b/packages/vite-version-plugin/src/console-banner.ts @@ -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', }; }