mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-18 09:21:56 +08:00
build(ui): define version constant
This commit is contained in:
parent
2aac79af54
commit
14a3f055ee
@ -1 +1,3 @@
|
|||||||
export const version = "v0.3.18";
|
// .env > git tag > v0.0.0-beta
|
||||||
|
// https://vite.dev/guide/env-and-mode.html#env-variables
|
||||||
|
export const version = import.meta.env.VITE_APP_VERSION || __APP_VERSION__ || "v0.0.0-dev";
|
||||||
|
1
ui/types/vite-env.d.ts
vendored
1
ui/types/vite-env.d.ts
vendored
@ -1 +1,2 @@
|
|||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
|
declare const __APP_VERSION__: string;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
import { type SpawnSyncReturns, execFileSync } from "node:child_process";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
import legacyPlugin from "@vitejs/plugin-legacy";
|
import legacyPlugin from "@vitejs/plugin-legacy";
|
||||||
import reactPlugin from "@vitejs/plugin-react";
|
import reactPlugin from "@vitejs/plugin-react";
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import { type Plugin, defineConfig } from "vite";
|
import { type Plugin, defineConfig, loadEnv } from "vite";
|
||||||
|
|
||||||
const preserveFilesPlugin = (filesToPreserve: string[]): Plugin => {
|
const preserveFilesPlugin = (filesToPreserve: string[]): Plugin => {
|
||||||
return {
|
return {
|
||||||
@ -32,7 +33,24 @@ const preserveFilesPlugin = (filesToPreserve: string[]): Plugin => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
|
const envs = loadEnv(mode, process.cwd());
|
||||||
|
let appVersion = undefined;
|
||||||
|
if (!envs?.VITE_APP_VERSION) {
|
||||||
|
try {
|
||||||
|
appVersion = execFileSync("git", ["describe", "--match", "v[0-9]*", "--tags", "--abbrev=8"], {
|
||||||
|
stdio: [],
|
||||||
|
})?.toString();
|
||||||
|
} catch (error) {
|
||||||
|
const err = error as SpawnSyncReturns<Buffer>;
|
||||||
|
console.warn("[Warn] failed to get version number through git", err?.stderr?.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
define: {
|
||||||
|
__APP_VERSION__: JSON.stringify(appVersion),
|
||||||
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
reactPlugin({}),
|
reactPlugin({}),
|
||||||
legacyPlugin({
|
legacyPlugin({
|
||||||
@ -50,4 +68,5 @@ export default defineConfig({
|
|||||||
"/api": "http://127.0.0.1:8090",
|
"/api": "http://127.0.0.1:8090",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user