From d48db66616e82b6a5c9014935e4a6ee90485c0ae Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Thu, 23 Nov 2023 10:38:00 +0100 Subject: [PATCH 1/4] fix(strapi): Ignore all prompts when serving --- packages/strapi/src/executors/serve/serve.impl.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/strapi/src/executors/serve/serve.impl.ts b/packages/strapi/src/executors/serve/serve.impl.ts index 5eb47020..a8f9506b 100644 --- a/packages/strapi/src/executors/serve/serve.impl.ts +++ b/packages/strapi/src/executors/serve/serve.impl.ts @@ -29,6 +29,7 @@ export async function serveExecutor( return execPackageManagerCommand(buildCommand([ 'strapi develop', + '--ignore-prompts', !build && '--no-build', watchAdmin && '--watch-admin', browser && `--browser=${browser}` From ae761293edd48e8de1c80f2a9be5cd168ba0ec3a Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Wed, 29 Nov 2023 11:43:58 +0100 Subject: [PATCH 2/4] fix(gcp-functions): Small fixes when generating project/runner --- packages/gcp-functions/README.md | 20 +++++++++++++++++++ .../src/generators/init-runner/init.impl.ts | 7 +++++-- .../src/generators/init/init.impl.ts | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/gcp-functions/README.md b/packages/gcp-functions/README.md index 68c17b98..c2f7b5db 100644 --- a/packages/gcp-functions/README.md +++ b/packages/gcp-functions/README.md @@ -24,3 +24,23 @@ nx g @nx-extend/gcp-functions:init | name | type | default | description | |------|------|---------|-------------| +## Runner +This projects includes a runner to run all your functions, to generate the runner: +```sh +nx g @nx-extend/gcp-functions:init-runner +``` + +This will generate a `main.ts` file like this: +```ts +import { bootstrapRunner } from '@nx-extend/gcp-functions/runner' + +/* eslint-disable @nx/enforce-module-boundaries */ +bootstrapRunner(new Map([ + ['nx function project name', import('path to main of of project')] + ]) +) +``` + +You can now add all your functions to the map, **note:** make sure that the `nx function project name` is the same name as +known by Nx (`name` prop of that functions `project.json`). The runner uses the `deploy` target of that `project.json` to determine +how to serve the function (http/pub sub/bucket event). diff --git a/packages/gcp-functions/src/generators/init-runner/init.impl.ts b/packages/gcp-functions/src/generators/init-runner/init.impl.ts index 5ad7cf12..34dbbfff 100644 --- a/packages/gcp-functions/src/generators/init-runner/init.impl.ts +++ b/packages/gcp-functions/src/generators/init-runner/init.impl.ts @@ -72,11 +72,14 @@ export default async function ( options: { outputPath: `dist/${normalizedOptions.projectRoot}`, main: `${normalizedOptions.projectRoot}/src/main.ts`, - tsConfig: `${normalizedOptions.projectRoot}/tsconfig.app.json` + tsConfig: `${normalizedOptions.projectRoot}/tsconfig.app.json`, + compiler: 'tsc', + target: 'node', + namedChunks: true } }, serve: { - executor: '@nx/node:execute', + executor: '@nx/js:node', options: { buildTarget: `${normalizedOptions.projectName}:_build` } diff --git a/packages/gcp-functions/src/generators/init/init.impl.ts b/packages/gcp-functions/src/generators/init/init.impl.ts index 9291093a..85ec27f8 100644 --- a/packages/gcp-functions/src/generators/init/init.impl.ts +++ b/packages/gcp-functions/src/generators/init/init.impl.ts @@ -101,7 +101,8 @@ export default async function ( executor: '@nx-extend/gcp-functions:deploy', options: { functionName: normalizedOptions.projectName, - envVarsFile: `${normalizedOptions.projectRoot}/src/environments/production.yaml` + envVarsFile: `${normalizedOptions.projectRoot}/src/environments/production.yaml`, + entryPoint: names(normalizedOptions.name).className } } }, From 36dca386354e20bdc284f3e3e580775195e9b27f Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Wed, 29 Nov 2023 11:45:47 +0100 Subject: [PATCH 3/4] fix(gcp-secrets): Use verbose logging and run commands with `--quiet` option --- .../src/executors/deploy/deploy.impl.ts | 16 ++++++++-------- .../src/utils/add-or-update-secret.ts | 17 +++++++---------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/packages/gcp-secrets/src/executors/deploy/deploy.impl.ts b/packages/gcp-secrets/src/executors/deploy/deploy.impl.ts index b5699b5e..65feb23c 100644 --- a/packages/gcp-secrets/src/executors/deploy/deploy.impl.ts +++ b/packages/gcp-secrets/src/executors/deploy/deploy.impl.ts @@ -1,5 +1,5 @@ import { ExecutorContext, logger } from '@nx/devkit' -import { buildCommand, execCommand } from '@nx-extend/core' +import { buildCommand, execCommand, USE_VERBOSE_LOGGING } from '@nx-extend/core' import { existsSync, mkdirSync, unlinkSync, writeFileSync } from 'fs' import 'dotenv/config' @@ -48,7 +48,7 @@ export async function deployExecutor( getCommandOptions(options) ]), { - silent: true, + silent: !USE_VERBOSE_LOGGING, asJSON: true } ).map((secret) => ({ @@ -73,8 +73,7 @@ export async function deployExecutor( // Get the content of the file const fileContent = getFileContent(file) - const isFileEncrypted = - fileContent.__gcp_metadata.status === 'encrypted' + const isFileEncrypted = fileContent.__gcp_metadata.status === 'encrypted' const decryptedFileContent = decryptFile(fileContent, true) // Decrypt the file if it's encrypted @@ -142,9 +141,7 @@ export async function deployExecutor( success: secretsCreated.filter(Boolean).length === files.length } } catch (err) { - logger.error( - `Error happened trying to decrypt files: ${err.message || err}` - ) + logger.error(`Error happened trying to deploy files: ${err.message || err}`) console.error(err.trace) return { success: false } @@ -155,7 +152,10 @@ export async function deployExecutor( } export const getCommandOptions = (options: DeploySchema): string => { - return buildCommand([options.project && `--project=${options.project}`]) + return buildCommand([ + options.project && `--project=${options.project}`, + '--quiet' + ]) } export const addLabelsIfNeeded = ( diff --git a/packages/gcp-secrets/src/utils/add-or-update-secret.ts b/packages/gcp-secrets/src/utils/add-or-update-secret.ts index 629fa713..277138b7 100644 --- a/packages/gcp-secrets/src/utils/add-or-update-secret.ts +++ b/packages/gcp-secrets/src/utils/add-or-update-secret.ts @@ -42,16 +42,13 @@ export const addOrUpdateSecret = ( if (JSON.stringify(existingLabels) !== JSON.stringify(metadata.labels)) { logger.info(`Updating "${secretName}" it's labels`) - execCommand( - buildCommand([ - `gcloud secrets update ${secretName}`, - addLabelsIfNeeded(metadata.labels, false), - getCommandOptions(options) - ]), - { - silent: true - } - ) + execCommand(buildCommand([ + `gcloud secrets update ${secretName}`, + addLabelsIfNeeded(metadata.labels, false), + getCommandOptions(options) + ]), { + silent: true + }) } // Get the new version of the secret From 7ad495462d296689247a513786863057cfe4c15d Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Wed, 29 Nov 2023 11:48:02 +0100 Subject: [PATCH 4/4] docs(gcp-functions): Added little inline comment --- .../src/generators/init/files-http/src/main.ts.template | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/gcp-functions/src/generators/init/files-http/src/main.ts.template b/packages/gcp-functions/src/generators/init/files-http/src/main.ts.template index 7dc0ae8b..ceefba2b 100644 --- a/packages/gcp-functions/src/generators/init/files-http/src/main.ts.template +++ b/packages/gcp-functions/src/generators/init/files-http/src/main.ts.template @@ -2,6 +2,8 @@ import type { HttpFunction } from '@google-cloud/functions-framework' const { foo = 'testBar'} = process.env +// Note: When changing "<%= className %>" to something else +// make sure to also update the "entryPoint" inside the "project.json" export const <%= className %>: HttpFunction = async (req, res) => { res.status(200) .send(foo)