feat: Add web version check

This commit is contained in:
hayden
2024-11-02 19:47:17 +08:00
parent 26fa78e2b7
commit bab643ee3d
3 changed files with 92 additions and 2 deletions

View File

@@ -86,8 +86,29 @@ function dev(): Plugin {
}
}
function createWebVersion(): Plugin {
return {
name: 'vite-plugin-web-version',
apply: 'build',
enforce: 'post',
writeBundle() {
const pyProjectContent = fs.readFileSync('pyproject.toml', 'utf8')
const [, version] = pyProjectContent.match(/version = "(.*)"/) ?? []
const metadata = [
`version: ${version}`,
`build_time: ${new Date().toISOString()}`,
'',
].join('\n')
const metadataFilePath = path.join(__dirname, 'web', 'version.yaml')
fs.writeFileSync(metadataFilePath, metadata, 'utf-8')
},
}
}
export default defineConfig({
plugins: [vue(), css(), output(), dev()],
plugins: [vue(), css(), output(), dev(), createWebVersion()],
build: {
outDir: 'web',