Skip to content

Commit

Permalink
refactor: build version file for moonraker (#1449)
Browse files Browse the repository at this point in the history
  • Loading branch information
meteyou authored Jul 1, 2023
1 parent d844125 commit 21d3d39
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/plugins/build-release_info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from 'fs'
import path from 'path'
import { version } from '../../package.json'
import { PluginOption } from 'vite'

/**
* Custom build plugin to write the version in a dedicated release_info.json file after bundling
*/

export default function buildReleaseInfo(): PluginOption {
return {
name: 'build-release_info',
writeBundle: () => {
setImmediate(async () => {
const versionIdentifier = version.toString()
const releaseInfoFile = await fs.promises.open(
path.resolve(__dirname, '../../dist/release_info.json'),
'w'
)
await releaseInfoFile.writeFile(
JSON.stringify({
project_name: 'mainsail',
project_owner: 'mainsail-crew',
version: `v${versionIdentifier}`,
})
)
await releaseInfoFile.close()
})
},
}
}
2 changes: 2 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import checker from 'vite-plugin-checker'

import path from 'path'
import buildVersion from './src/plugins/build-version'
import buildReleaseInfo from './src/plugins/build-release_info'
import { VitePWA, VitePWAOptions } from 'vite-plugin-pwa'

const PWAConfig: Partial<VitePWAOptions> = {
Expand Down Expand Up @@ -66,6 +67,7 @@ export default defineConfig({
plugins: [
VitePWA(PWAConfig),
buildVersion(),
buildReleaseInfo(),
vue(),
loadVersion(),
checker({ typescript: true }),
Expand Down

0 comments on commit 21d3d39

Please sign in to comment.