1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-05 08:29:57 +00:00
elk/modules/build-info.ts

34 lines
786 B
TypeScript
Raw Normal View History

2022-12-26 19:33:19 +00:00
import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
2023-01-04 13:26:30 +00:00
import { getEnv, version } from '../config/env'
2022-12-26 19:33:19 +00:00
import type { BuildInfo } from '~/types'
export default defineNuxtModule({
meta: {
name: 'elk:build-info',
},
2023-01-04 13:26:30 +00:00
async setup(_options, nuxt) {
const { env, commit, branch } = await getEnv()
nuxt.options.runtimeConfig.public.env = env
2022-12-26 19:33:19 +00:00
const buildInfo: BuildInfo = {
version,
time: +Date.now(),
2023-01-04 13:26:30 +00:00
commit,
branch,
env,
2022-12-26 19:33:19 +00:00
}
2023-01-04 13:26:30 +00:00
2022-12-26 19:33:19 +00:00
addVitePlugin({
name: 'elk:build-info',
resolveId(id) {
if (id === 'virtual:build-info')
return id
},
load(id) {
if (id === 'virtual:build-info')
2023-01-04 13:26:30 +00:00
return `export const buildInfo = ${JSON.stringify(buildInfo, null, 2)}`
2022-12-26 19:33:19 +00:00
},
})
},
})