1
0
elk/modules/build-info.ts

34 lines
786 B
TypeScript
Raw Normal View History

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