Skip to content

Commit 7822a6e

Browse files
committed
chore: use git to get cookiePolicyDate
1 parent 3b5bca4 commit 7822a6e

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

config/env.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ export async function getGitInfo() {
7373
return { branch, commit, shortCommit }
7474
}
7575

76+
export async function getFileLastUpdated(path: string) {
77+
try {
78+
// Get ISO date of last commit for file
79+
const date = await git.log(['-1', '--format=%cI', '--', path])
80+
return date.latest?.date || new Date().toISOString()
81+
} catch {
82+
return new Date().toISOString()
83+
}
84+
}
85+
7686
export async function getEnv(isDevelopment: boolean) {
7787
const { commit, shortCommit, branch } = await getGitInfo()
7888
const env = isDevelopment

modules/build-env.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { BuildInfo } from '../shared/types'
22
import { createResolver, defineNuxtModule } from 'nuxt/kit'
33
import { isCI } from 'std-env'
4-
import { getEnv, version } from '../config/env'
4+
import { getEnv, getFileLastUpdated, version } from '../config/env'
55

66
const { resolve } = createResolver(import.meta.url)
77

@@ -10,7 +10,10 @@ export default defineNuxtModule({
1010
name: 'npmx:build-env',
1111
},
1212
async setup(_options, nuxt) {
13-
const { env, commit, shortCommit, branch } = await getEnv(nuxt.options.dev)
13+
const [{ env, commit, shortCommit, branch }, cookiePolicyDate] = await Promise.all([
14+
getEnv(nuxt.options.dev),
15+
getFileLastUpdated('app/pages/cookie-policy.vue'),
16+
])
1417

1518
nuxt.options.appConfig = nuxt.options.appConfig || {}
1619
nuxt.options.appConfig.env = env
@@ -21,6 +24,7 @@ export default defineNuxtModule({
2124
shortCommit,
2225
branch,
2326
env,
27+
cookiePolicyDate,
2428
} satisfies BuildInfo
2529

2630
nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || []

shared/types/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export interface BuildInfo {
55
time: number
66
branch: string
77
env: 'preview' | 'canary' | 'dev' | 'release'
8+
cookiePolicyDate: string
89
}

0 commit comments

Comments
 (0)