mirror of
https://github.com/elk-zone/elk.git
synced 2024-09-06 12:19:08 +01:00
31 lines
771 B
TypeScript
31 lines
771 B
TypeScript
|
import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
|
||
|
import Git from 'simple-git'
|
||
|
import { version } from '../package.json'
|
||
|
import type { BuildInfo } from '~/types'
|
||
|
|
||
|
export default defineNuxtModule({
|
||
|
meta: {
|
||
|
name: 'elk:build-info',
|
||
|
},
|
||
|
async setup() {
|
||
|
const git = Git()
|
||
|
const buildInfo: BuildInfo = {
|
||
|
version,
|
||
|
time: +Date.now(),
|
||
|
commit: await git.revparse(['HEAD']),
|
||
|
branch: await git.revparse(['--abbrev-ref', 'HEAD']),
|
||
|
}
|
||
|
addVitePlugin({
|
||
|
name: 'elk:build-info',
|
||
|
resolveId(id) {
|
||
|
if (id === 'virtual:build-info')
|
||
|
return id
|
||
|
},
|
||
|
load(id) {
|
||
|
if (id === 'virtual:build-info')
|
||
|
return `export default ${JSON.stringify(buildInfo, null, 2)}`
|
||
|
},
|
||
|
})
|
||
|
},
|
||
|
})
|