1
0
mirror of https://github.com/elk-zone/elk synced 2024-11-30 15:58:06 +09:00
elk/modules/build-env.ts
renovate[bot] 320ddc0e28
chore(deps): update dependency @antfu/eslint-config to v3 (#2984)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: TAKAHASHI Shuuji <shuuji3@gmail.com>
2024-09-30 08:11:56 +00:00

37 lines
1.2 KiB
TypeScript

import { createResolver, defineNuxtModule } from '@nuxt/kit'
import { isCI } from 'std-env'
import type { BuildInfo } from '~/types'
import { getEnv, version } from '../config/env'
const { resolve } = createResolver(import.meta.url)
export default defineNuxtModule({
meta: {
name: 'elk:build-env',
},
async setup(_options, nuxt) {
const { env, commit, shortCommit, branch } = await getEnv()
const buildInfo: BuildInfo = {
version,
time: +Date.now(),
commit,
shortCommit,
branch,
env,
}
nuxt.options.appConfig = nuxt.options.appConfig || {}
nuxt.options.appConfig.env = env
nuxt.options.appConfig.buildInfo = buildInfo
nuxt.options.nitro.virtual = nuxt.options.nitro.virtual || {}
nuxt.options.nitro.virtual['#build-info'] = `export const env = ${JSON.stringify(env)}`
nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || []
if (env === 'dev')
nuxt.options.nitro.publicAssets.unshift({ dir: resolve('../public-dev') })
else if (env === 'canary' || env === 'preview' || !isCI)
nuxt.options.nitro.publicAssets.unshift({ dir: resolve('../public-staging') })
},
})