From 639b5c53fe2ec1097c3ab236a67c0e2fc02352a9 Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Wed, 3 Apr 2024 13:06:58 +0200 Subject: [PATCH 1/3] feat: build hooks in Cloudflare Ci --- src/module/index.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/module/index.ts b/src/module/index.ts index 1a05eafc..eb7c5f92 100644 --- a/src/module/index.ts +++ b/src/module/index.ts @@ -74,6 +74,7 @@ export default defineNuxtModule({ const hub = runtimeConfig.hub = defu(runtimeConfig.hub || {}, options, { url: process.env.NUXT_HUB_URL || 'https://admin.hub.nuxt.com', projectKey: process.env.NUXT_HUB_PROJECT_KEY || '', + deployKey: process.env.NUXT_HUB_PROJECT_DEPLOY_KEY || '', projectUrl: process.env.NUXT_HUB_PROJECT_URL || '', projectSecretKey: process.env.NUXT_HUB_PROJECT_SECRET_KEY || '', userToken: process.env.NUXT_HUB_USER_TOKEN || '', @@ -114,6 +115,24 @@ export default defineNuxtModule({ return } + if (process.env.CF_PAGES) { + nuxt.hook('build:before', async () => { + await $fetch('/api/projects/build/start', { + baseURL: hub.url, + method: 'POST', + body: hub, + }).catch(() => {}) + }) + + nuxt.hook('build:done', async () => { + await $fetch('/api/projects/build/finish', { + baseURL: hub.url, + method: 'POST', + body: hub, + }).catch(() => {}) + }) + } + if (hub.remote) { // Can either use projectKey or projectUrl if (hub.projectKey && hub.projectUrl) { From 5e9836dbb3ab6d36a243c580f09ffe57eccf68da Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Wed, 3 Apr 2024 13:08:09 +0200 Subject: [PATCH 2/3] chore: update api name --- src/module/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/module/index.ts b/src/module/index.ts index eb7c5f92..fdb50f10 100644 --- a/src/module/index.ts +++ b/src/module/index.ts @@ -117,7 +117,7 @@ export default defineNuxtModule({ if (process.env.CF_PAGES) { nuxt.hook('build:before', async () => { - await $fetch('/api/projects/build/start', { + await $fetch('/api/projects/build/before', { baseURL: hub.url, method: 'POST', body: hub, @@ -125,7 +125,7 @@ export default defineNuxtModule({ }) nuxt.hook('build:done', async () => { - await $fetch('/api/projects/build/finish', { + await $fetch('/api/projects/build/done', { baseURL: hub.url, method: 'POST', body: hub, From 6c339dd4400e6b415f4605d6d560765cb169a84f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Wed, 3 Apr 2024 16:55:23 +0200 Subject: [PATCH 3/3] chore: up --- src/module/index.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/module/index.ts b/src/module/index.ts index fdb50f10..8386721a 100644 --- a/src/module/index.ts +++ b/src/module/index.ts @@ -72,13 +72,16 @@ export default defineNuxtModule({ remoteArg = (remoteArg === '' ? 'true' : remoteArg) const runtimeConfig = nuxt.options.runtimeConfig const hub = runtimeConfig.hub = defu(runtimeConfig.hub || {}, options, { - url: process.env.NUXT_HUB_URL || 'https://admin.hub.nuxt.com', - projectKey: process.env.NUXT_HUB_PROJECT_KEY || '', - deployKey: process.env.NUXT_HUB_PROJECT_DEPLOY_KEY || '', + // Self-hosted project projectUrl: process.env.NUXT_HUB_PROJECT_URL || '', projectSecretKey: process.env.NUXT_HUB_PROJECT_SECRET_KEY || '', + // Deployed on NuxtHub + url: process.env.NUXT_HUB_URL || 'https://admin.hub.nuxt.com', + projectKey: process.env.NUXT_HUB_PROJECT_KEY || '', userToken: process.env.NUXT_HUB_USER_TOKEN || '', + // Remote storage remote: remoteArg || process.env.NUXT_HUB_REMOTE, + // Other options version, env: process.env.NUXT_HUB_ENV || 'production', openapi: nuxt.options.nitro.experimental?.openAPI === true @@ -115,20 +118,27 @@ export default defineNuxtModule({ return } - if (process.env.CF_PAGES) { + // Within CF Pages CI/CD to notice NuxtHub about the build and hub config + if (!nuxt.options.dev && process.env.CF_PAGES && process.env.NUXT_HUB_PROJECT_DEPLOY_TOKEN && process.env.NUXT_HUB_PROJECT_KEY && process.env.NUXT_HUB_ENV) { nuxt.hook('build:before', async () => { - await $fetch('/api/projects/build/before', { + await $fetch(`/api/projects/${process.env.NUXT_HUB_PROJECT_KEY}/build/${process.env.NUXT_HUB_ENV}/before`, { baseURL: hub.url, method: 'POST', - body: hub, + headers: { + authorization: `Bearer ${process.env.NUXT_HUB_PROJECT_DEPLOY_TOKEN}` + }, + body: {}, }).catch(() => {}) }) nuxt.hook('build:done', async () => { - await $fetch('/api/projects/build/done', { + await $fetch(`/api/projects/${process.env.NUXT_HUB_PROJECT_KEY}/build/${process.env.NUXT_HUB_ENV}/done`, { baseURL: hub.url, method: 'POST', - body: hub, + headers: { + authorization: `Bearer ${process.env.NUXT_HUB_PROJECT_DEPLOY_TOKEN}` + }, + body: {}, }).catch(() => {}) }) }