Files
muh/frontend/vite.config.ts
2026-03-24 11:15:18 +01:00

56 lines
1.6 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
const CONFIG_DIR = path.dirname(fileURLToPath(import.meta.url));
const APPLICATION_CONFIG_PATH = path.resolve(CONFIG_DIR, "../backend/src/main/resources/application.yml");
function resolveAppVersion(): string {
const lines = fs.readFileSync(APPLICATION_CONFIG_PATH, "utf8").split(/\r?\n/);
let inMuhSection = false;
let inAppSection = false;
for (const line of lines) {
const trimmedLine = line.trim();
if (!trimmedLine || trimmedLine.startsWith("#")) {
continue;
}
const indentation = line.length - line.trimStart().length;
if (indentation === 0) {
inMuhSection = trimmedLine === "muh:";
inAppSection = false;
continue;
}
if (inMuhSection && indentation === 2) {
inAppSection = trimmedLine === "app:";
continue;
}
if (inMuhSection && inAppSection && indentation === 4 && trimmedLine.startsWith("version:")) {
const version = trimmedLine.slice("version:".length).trim().replace(/^['"]|['"]$/g, "");
if (/^\d+\.\d+\.\d+$/.test(version)) {
return version;
}
throw new Error(`Ungueltige Versionsnummer in ${APPLICATION_CONFIG_PATH}: ${version}`);
}
}
throw new Error(`muh.app.version konnte nicht aus ${APPLICATION_CONFIG_PATH} ermittelt werden.`);
}
export default defineConfig({
plugins: [react()],
define: {
__APP_VERSION__: JSON.stringify(resolveAppVersion()),
},
server: {
port: 5173,
host: "0.0.0.0",
},
});