feat: implement versioning system by extracting version from environment, git tags, or package.json, and display app version in MainLayout; enhance ConfigPage with search functionality and CodeMirror integration for YAML editing
This commit is contained in:
@@ -2,6 +2,38 @@ import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import { viteSingleFile } from 'vite-plugin-singlefile';
|
||||
import path from 'path';
|
||||
import { execSync } from 'child_process';
|
||||
import fs from 'fs';
|
||||
|
||||
// Get version from environment, git tag, or package.json
|
||||
function getVersion(): string {
|
||||
// 1. Environment variable (set by GitHub Actions)
|
||||
if (process.env.VERSION) {
|
||||
return process.env.VERSION;
|
||||
}
|
||||
|
||||
// 2. Try git tag
|
||||
try {
|
||||
const gitTag = execSync('git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo ""', { encoding: 'utf8' }).trim();
|
||||
if (gitTag) {
|
||||
return gitTag;
|
||||
}
|
||||
} catch {
|
||||
// Git not available or no tags
|
||||
}
|
||||
|
||||
// 3. Fall back to package.json version
|
||||
try {
|
||||
const pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json'), 'utf8'));
|
||||
if (pkg.version && pkg.version !== '0.0.0') {
|
||||
return pkg.version;
|
||||
}
|
||||
} catch {
|
||||
// package.json not readable
|
||||
}
|
||||
|
||||
return 'dev';
|
||||
}
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
@@ -11,6 +43,9 @@ export default defineConfig({
|
||||
removeViteModuleLoader: true
|
||||
})
|
||||
],
|
||||
define: {
|
||||
__APP_VERSION__: JSON.stringify(getVersion())
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src')
|
||||
|
||||
Reference in New Issue
Block a user