mirror of
https://github.com/Xevion/banner.git
synced 2025-12-06 01:14:22 -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 viteReact from "@vitejs/plugin-react";
|
||||||
import tanstackRouter from "@tanstack/router-plugin/vite";
|
import tanstackRouter from "@tanstack/router-plugin/vite";
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync, existsSync } from "node:fs";
|
||||||
|
|
||||||
// Extract version from Cargo.toml
|
// Extract version from Cargo.toml
|
||||||
function getVersion() {
|
function getVersion() {
|
||||||
|
const filename = "Cargo.toml";
|
||||||
|
const paths = [
|
||||||
|
resolve(__dirname, filename),
|
||||||
|
resolve(__dirname, "..", filename),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const path of paths) {
|
||||||
try {
|
try {
|
||||||
const cargoTomlPath = resolve(__dirname, "..", "Cargo.toml");
|
// Check if file exists before reading
|
||||||
const cargoTomlContent = readFileSync(cargoTomlPath, "utf8");
|
if (!existsSync(path)) {
|
||||||
const versionMatch = cargoTomlContent.match(/^version\s*=\s*"([^"]+)"/m);
|
console.log("Skipping ", path, " because it does not exist");
|
||||||
return versionMatch ? versionMatch[1] : "unknown";
|
continue;
|
||||||
} catch (error) {
|
|
||||||
console.warn("Could not read version from Cargo.toml:", error);
|
|
||||||
return "unknown";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
const version = getVersion();
|
||||||
|
|||||||
Reference in New Issue
Block a user