2023-01-08 12:17:09 +01:00
|
|
|
import { createResolver, defineNuxtModule } from '@nuxt/kit'
|
2023-01-08 14:27:29 +01:00
|
|
|
import { isCI } from 'std-env'
|
2023-01-08 12:17:09 +01:00
|
|
|
import { getEnv, version } from '../config/env'
|
|
|
|
import type { BuildInfo } from '~/types'
|
|
|
|
|
|
|
|
const { resolve } = createResolver(import.meta.url)
|
|
|
|
|
|
|
|
export default defineNuxtModule({
|
|
|
|
meta: {
|
|
|
|
name: 'elk:build-env',
|
|
|
|
},
|
|
|
|
async setup(_options, nuxt) {
|
|
|
|
const { env, commit, branch } = await getEnv()
|
|
|
|
const buildInfo: BuildInfo = {
|
|
|
|
version,
|
|
|
|
time: +Date.now(),
|
|
|
|
commit,
|
|
|
|
branch,
|
|
|
|
env,
|
|
|
|
}
|
|
|
|
|
|
|
|
nuxt.options.runtimeConfig.public.env = env
|
|
|
|
nuxt.options.runtimeConfig.public.buildInfo = buildInfo
|
|
|
|
|
2023-01-08 14:27:29 +01:00
|
|
|
nuxt.hook('nitro:config', (config) => {
|
|
|
|
config.publicAssets = config.publicAssets || []
|
|
|
|
if (env === 'dev')
|
2023-01-08 21:23:04 +01:00
|
|
|
config.publicAssets.unshift({ dir: resolve('../public-dev') })
|
2023-01-08 14:27:29 +01:00
|
|
|
else if (env === 'canary' || env === 'preview' || !isCI)
|
2023-01-08 21:23:04 +01:00
|
|
|
config.publicAssets.unshift({ dir: resolve('../public-staging') })
|
2023-01-08 14:27:29 +01:00
|
|
|
})
|
2023-01-08 12:17:09 +01:00
|
|
|
},
|
|
|
|
})
|