2023-01-08 20:17:09 +09:00
|
|
|
import { createResolver, defineNuxtModule } from '@nuxt/kit'
|
2023-01-08 22:27:29 +09:00
|
|
|
import { isCI } from 'std-env'
|
2023-01-08 20:17:09 +09:00
|
|
|
import type { BuildInfo } from '~/types'
|
2024-09-30 17:11:56 +09:00
|
|
|
import { getEnv, version } from '../config/env'
|
2023-01-08 20:17:09 +09:00
|
|
|
|
|
|
|
const { resolve } = createResolver(import.meta.url)
|
|
|
|
|
|
|
|
export default defineNuxtModule({
|
|
|
|
meta: {
|
|
|
|
name: 'elk:build-env',
|
|
|
|
},
|
|
|
|
async setup(_options, nuxt) {
|
2023-02-23 20:17:28 +09:00
|
|
|
const { env, commit, shortCommit, branch } = await getEnv()
|
2023-01-08 20:17:09 +09:00
|
|
|
const buildInfo: BuildInfo = {
|
|
|
|
version,
|
|
|
|
time: +Date.now(),
|
|
|
|
commit,
|
2023-02-23 20:17:28 +09:00
|
|
|
shortCommit,
|
2023-01-08 20:17:09 +09:00
|
|
|
branch,
|
|
|
|
env,
|
|
|
|
}
|
|
|
|
|
2023-01-29 23:18:27 +09:00
|
|
|
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-08 20:17:09 +09:00
|
|
|
|
2023-01-09 20:12:43 +09: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') })
|
2023-01-08 20:17:09 +09:00
|
|
|
},
|
|
|
|
})
|