Skip to content

Commit

Permalink
chore: use compiled hook from nitro to final build event (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux authored Oct 24, 2024
1 parent 47448a2 commit 59b3701
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/utils/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,26 @@ export function addBuildHooks(nuxt: Nuxt, hub: HubConfig) {
})
})

nuxt.hook('build:done', async () => {
await $fetch(`/api/projects/${process.env.NUXT_HUB_PROJECT_KEY}/build/${process.env.NUXT_HUB_ENV}/done`, {
baseURL: hub.url,
method: 'POST',
headers: {
authorization: `Bearer ${process.env.NUXT_HUB_PROJECT_DEPLOY_TOKEN}`
},
body: {
pagesUrl: process.env.CF_PAGES_URL
}
}).catch((e) => {
if (e.response?._data?.message) {
log.error(e.response._data.message)
} else {
log.error('Failed run build:done hook on NuxtHub.', e)
}
nuxt.hook('nitro:init', async (nitro) => {
nitro.hooks.hook('compiled', async () => {
await $fetch(`/api/projects/${process.env.NUXT_HUB_PROJECT_KEY}/build/${process.env.NUXT_HUB_ENV}/done`, {
baseURL: hub.url,
method: 'POST',
headers: {
authorization: `Bearer ${process.env.NUXT_HUB_PROJECT_DEPLOY_TOKEN}`
},
body: {
pagesUrl: process.env.CF_PAGES_URL
}
}).catch((e) => {
if (e.response?._data?.message) {
log.error(e.response._data.message)
} else {
log.error('Failed run build:done hook on NuxtHub.', e)
}

process.exit(1)
process.exit(1)
})
})
})
} else {
Expand Down

0 comments on commit 59b3701

Please sign in to comment.