feat: render app version in bottom-left footer
This commit is contained in:
@@ -6,18 +6,26 @@ import vue from "@vitejs/plugin-vue";
|
||||
import vueJsx from "@vitejs/plugin-vue-jsx";
|
||||
import svgLoader from "vite-svg-loader";
|
||||
|
||||
function getGitTag(): string {
|
||||
function sh(cmd: string): string {
|
||||
try {
|
||||
const tags = execSync("git tag --sort=-version:refname")
|
||||
return execSync(cmd, { stdio: ["ignore", "pipe", "ignore"] })
|
||||
.toString()
|
||||
.trim()
|
||||
.split("\n");
|
||||
return tags.length > 0 ? tags[0] : "unknown";
|
||||
} catch (fallbackError) {
|
||||
.trim();
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function getAppVersion(): string {
|
||||
const tag = sh("git tag --sort=-version:refname").split("\n")[0] || "";
|
||||
const shortSha = sh("git rev-parse --short HEAD");
|
||||
const tagSha = tag ? sh(`git rev-list -n 1 ${tag}`) : "";
|
||||
const headSha = sh("git rev-parse HEAD");
|
||||
if (tag && tagSha === headSha) return tag;
|
||||
if (tag && shortSha) return `${tag}+${shortSha}`;
|
||||
return shortSha || "dev";
|
||||
}
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
base: "./",
|
||||
@@ -25,7 +33,7 @@ export default defineConfig({
|
||||
target: "esnext",
|
||||
},
|
||||
define: {
|
||||
__APP_VERSION__: JSON.stringify(getGitTag()),
|
||||
__APP_VERSION__: JSON.stringify(getAppVersion()),
|
||||
},
|
||||
optimizeDeps: {
|
||||
esbuildOptions: {
|
||||
|
||||
Reference in New Issue
Block a user