Skip to content

Commit 59b3701

Browse files
authored
chore: use compiled hook from nitro to final build event (#338)
1 parent 47448a2 commit 59b3701

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/utils/build.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,26 @@ export function addBuildHooks(nuxt: Nuxt, hub: HubConfig) {
7575
})
7676
})
7777

78-
nuxt.hook('build:done', async () => {
79-
await $fetch(`/api/projects/${process.env.NUXT_HUB_PROJECT_KEY}/build/${process.env.NUXT_HUB_ENV}/done`, {
80-
baseURL: hub.url,
81-
method: 'POST',
82-
headers: {
83-
authorization: `Bearer ${process.env.NUXT_HUB_PROJECT_DEPLOY_TOKEN}`
84-
},
85-
body: {
86-
pagesUrl: process.env.CF_PAGES_URL
87-
}
88-
}).catch((e) => {
89-
if (e.response?._data?.message) {
90-
log.error(e.response._data.message)
91-
} else {
92-
log.error('Failed run build:done hook on NuxtHub.', e)
93-
}
78+
nuxt.hook('nitro:init', async (nitro) => {
79+
nitro.hooks.hook('compiled', async () => {
80+
await $fetch(`/api/projects/${process.env.NUXT_HUB_PROJECT_KEY}/build/${process.env.NUXT_HUB_ENV}/done`, {
81+
baseURL: hub.url,
82+
method: 'POST',
83+
headers: {
84+
authorization: `Bearer ${process.env.NUXT_HUB_PROJECT_DEPLOY_TOKEN}`
85+
},
86+
body: {
87+
pagesUrl: process.env.CF_PAGES_URL
88+
}
89+
}).catch((e) => {
90+
if (e.response?._data?.message) {
91+
log.error(e.response._data.message)
92+
} else {
93+
log.error('Failed run build:done hook on NuxtHub.', e)
94+
}
9495

95-
process.exit(1)
96+
process.exit(1)
97+
})
9698
})
9799
})
98100
} else {

0 commit comments

Comments
 (0)