refactor(status-dashboard): migrate to shared @lilith/vite-version-plugin
Replace inline version injection with the reusable vite-version-plugin package for consistent version banners across all dashboards. Changes: - Remove custom getMonorepoVersion() and buildInfoPlugin() - Use versionPlugin from @lilith/vite-version-plugin - Use logVersionBanner for styled console output - Add tsconfig paths for TypeScript resolution 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
4fc68971ba
commit
5bc43654aa
3 changed files with 18 additions and 55 deletions
|
|
@ -7,16 +7,10 @@ import { PublicStatusPage } from './PublicStatusPage';
|
|||
import { AdminDashboard } from './AdminDashboard';
|
||||
import { LoginPage } from './LoginPage';
|
||||
import { HostsPage } from './HostsPage';
|
||||
import { logVersionBanner } from '@lilith/vite-version-plugin/console';
|
||||
|
||||
// Injected at build time from VERSION.json
|
||||
declare const __APP_VERSION__: string;
|
||||
declare const __BUILD_TIME__: string;
|
||||
|
||||
console.log(
|
||||
`%c Lilith Status Dashboard v${__APP_VERSION__} %c Built: ${__BUILD_TIME__} `,
|
||||
'background: #ff00ff; color: #000; font-weight: bold; padding: 4px 8px;',
|
||||
'background: #00ffff; color: #000; padding: 4px 8px;'
|
||||
);
|
||||
// Log version banner to console on app load
|
||||
logVersionBanner({ primaryColor: '#ff00ff', secondaryColor: '#00ffff' });
|
||||
|
||||
export function App() {
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@
|
|||
"noFallthroughCasesInSwitch": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
"@/*": ["./src/*"],
|
||||
"@lilith/vite-version-plugin/console": ["../../../@packages/@utils/vite-version-plugin/src/console-banner.ts"],
|
||||
"@lilith/vite-version-plugin": ["../../../@packages/@utils/vite-version-plugin/src"]
|
||||
},
|
||||
"types": ["vitest/globals", "@testing-library/jest-dom"]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,52 +1,20 @@
|
|||
import { defineConfig, loadEnv, Plugin } from 'vite';
|
||||
import { defineConfig, loadEnv } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import path from 'path';
|
||||
import { execFileSync } from 'child_process';
|
||||
import { readFileSync, writeFileSync } from 'fs';
|
||||
|
||||
// Read authoritative version from monorepo root
|
||||
function getMonorepoVersion(): string {
|
||||
try {
|
||||
const versionPath = path.resolve(__dirname, '../../../VERSION.json');
|
||||
const content = readFileSync(versionPath, 'utf-8');
|
||||
return JSON.parse(content).version || '0.0.0';
|
||||
} catch {
|
||||
return '0.0.0';
|
||||
}
|
||||
}
|
||||
|
||||
// Generate build info at build time
|
||||
function buildInfoPlugin(): Plugin {
|
||||
return {
|
||||
name: 'build-info',
|
||||
writeBundle(options, bundle) {
|
||||
const gitCommit = execFileSync('git', ['rev-parse', '--short', 'HEAD'], { encoding: 'utf-8' }).trim();
|
||||
const gitBranch = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { encoding: 'utf-8' }).trim();
|
||||
|
||||
// Extract bundle hash from output filenames
|
||||
const jsBundle = Object.keys(bundle).find(f => f.startsWith('assets/index-') && f.endsWith('.js'));
|
||||
const buildHash = jsBundle?.match(/index-([^.]+)\.js/)?.[1] || 'unknown';
|
||||
|
||||
const buildInfo = {
|
||||
buildHash,
|
||||
gitCommit,
|
||||
gitBranch,
|
||||
buildTime: new Date().toISOString(),
|
||||
app: 'status-dashboard-frontend',
|
||||
};
|
||||
|
||||
const outDir = options.dir || 'dist';
|
||||
writeFileSync(path.join(outDir, 'build-info.json'), JSON.stringify(buildInfo, null, 2));
|
||||
console.log(`\n📦 Build info generated: ${buildHash} (${gitCommit})`);
|
||||
},
|
||||
};
|
||||
}
|
||||
// Direct import for vite config (aliases not available at config load time)
|
||||
import { versionPlugin } from '../../../@packages/@utils/vite-version-plugin/src';
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, __dirname, '');
|
||||
|
||||
return {
|
||||
plugins: [react(), buildInfoPlugin()],
|
||||
plugins: [
|
||||
react(),
|
||||
versionPlugin({
|
||||
appName: 'Lilith Status Dashboard',
|
||||
// Will find VERSION.json in monorepo root automatically
|
||||
}),
|
||||
],
|
||||
server: {
|
||||
port: 3000,
|
||||
proxy: {
|
||||
|
|
@ -63,12 +31,11 @@ export default defineConfig(({ mode }) => {
|
|||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
'@lilith/vite-version-plugin/console': path.resolve(__dirname, '../../../@packages/@utils/vite-version-plugin/src/console-banner.ts'),
|
||||
'@lilith/vite-version-plugin': path.resolve(__dirname, '../../../@packages/@utils/vite-version-plugin/src'),
|
||||
},
|
||||
},
|
||||
define: {
|
||||
// Inject authoritative version at build time
|
||||
'__APP_VERSION__': JSON.stringify(getMonorepoVersion()),
|
||||
'__BUILD_TIME__': JSON.stringify(new Date().toISOString()),
|
||||
// Production: Use empty string for same-origin (HTTPS) - nginx proxies /api and /socket.io
|
||||
// Development: Use proxy config above
|
||||
'import.meta.env.VITE_API_URL': mode === 'production'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue