elk/modules/build-env.ts

37 lines
1.2 KiB
TypeScript
Raw Normal View History

import { createResolver, defineNuxtModule } from '@nuxt/kit'
2023-01-08 16:27:29 +03:00
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) {
2023-02-23 14:17:28 +03:00
const { env, commit, shortCommit, branch } = await getEnv()
const buildInfo: BuildInfo = {
version,
time: +Date.now(),
commit,
2023-02-23 14:17:28 +03:00
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)}`
2023-01-09 14:12:43 +03:00
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') })
},
})