chore: output version to version.json

This commit is contained in:
Miodec 2024-07-26 18:17:08 +02:00
parent c1bd66a82c
commit 0b3e3d9a32
3 changed files with 23 additions and 1 deletions

View file

@ -103,6 +103,15 @@
"value": "no-cache, no-store, must-revalidate"
}
]
},
{
"source": "/version.json",
"headers": [
{
"key": "Cache-Control",
"value": "no-cache, no-store, must-revalidate"
}
]
}
]
}

View file

@ -0,0 +1 @@
{ "version": "DEVELOPMENT_CLIENT" }

View file

@ -7,6 +7,7 @@ import path from "node:path";
import { splitVendorChunkPlugin } from "vite";
import childProcess from "child_process";
import { checker } from "vite-plugin-checker";
import { writeFileSync } from "fs";
function pad(numbers, maxLength, fillString) {
return numbers.map((number) =>
@ -31,7 +32,7 @@ function buildClientVersion() {
.execSync("git rev-parse --short HEAD")
.toString();
return `${version}.${commitHash}`;
return `${version}.${commitHash}`.replace(/\n/g, "");
} catch (e) {
return `${version}.unknown-hash`;
}
@ -57,6 +58,17 @@ export default {
});
},
},
{
name: "generate-version-json",
apply: "build",
closeBundle() {
const version = buildClientVersion();
const versionJson = JSON.stringify({ version });
const versionPath = path.resolve(__dirname, "dist/version.json");
writeFileSync(versionPath, versionJson);
},
},
{
name: "vite-plugin-webfonts-preview",
apply: "build",