mirror of
https://github.com/Xevion/banner.git
synced 2025-12-06 05:14:26 -06:00
fix: make version retrieval search current dir, add basic logs, existence check
This commit is contained in:
@@ -2,19 +2,38 @@ import { defineConfig } from "vite";
|
||||
import viteReact from "@vitejs/plugin-react";
|
||||
import tanstackRouter from "@tanstack/router-plugin/vite";
|
||||
import { resolve } from "node:path";
|
||||
import { readFileSync } from "fs";
|
||||
import { readFileSync, existsSync } from "node:fs";
|
||||
|
||||
// Extract version from Cargo.toml
|
||||
function getVersion() {
|
||||
try {
|
||||
const cargoTomlPath = resolve(__dirname, "..", "Cargo.toml");
|
||||
const cargoTomlContent = readFileSync(cargoTomlPath, "utf8");
|
||||
const versionMatch = cargoTomlContent.match(/^version\s*=\s*"([^"]+)"/m);
|
||||
return versionMatch ? versionMatch[1] : "unknown";
|
||||
} catch (error) {
|
||||
console.warn("Could not read version from Cargo.toml:", error);
|
||||
return "unknown";
|
||||
const filename = "Cargo.toml";
|
||||
const paths = [
|
||||
resolve(__dirname, filename),
|
||||
resolve(__dirname, "..", filename),
|
||||
];
|
||||
|
||||
for (const path of paths) {
|
||||
try {
|
||||
// Check if file exists before reading
|
||||
if (!existsSync(path)) {
|
||||
console.log("Skipping ", path, " because it does not exist");
|
||||
continue;
|
||||
}
|
||||
|
||||
const cargoTomlContent = readFileSync(path, "utf8");
|
||||
const versionMatch = cargoTomlContent.match(/^version\s*=\s*"([^"]+)"/m);
|
||||
if (versionMatch) {
|
||||
console.log("Found version in ", path, ": ", versionMatch[1]);
|
||||
return versionMatch[1];
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Failed to read Cargo.toml at path: ", path, error);
|
||||
// Continue to next path
|
||||
}
|
||||
}
|
||||
|
||||
console.warn("Could not read version from Cargo.toml in any location");
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
const version = getVersion();
|
||||
|
||||
Reference in New Issue
Block a user