From e4c570de74cc4d32206417f71848d7ce5e97ee86 Mon Sep 17 00:00:00 2001 From: Patrick Sullivan Date: Mon, 7 Aug 2023 07:05:01 -0400 Subject: [PATCH] feat(tools-executors-typescript): Added the `storm` schema code generation executor --- apps/web/shell/app/layout.tsx | 17 ++++-- apps/workers/contact-api/src/worker.ts | 5 +- .../kafka/renderers/ClassRenderer.ts | 7 ++- tools/executors/typescript/executors.json | 5 ++ tools/executors/typescript/project.json | 12 ++++ .../typescript/storm-generate/impl.ts | 57 +++++++++++++++++++ .../typescript/storm-generate/schema.d.ts | 8 +++ .../typescript/storm-generate/schema.json | 34 +++++++++++ 8 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 tools/executors/typescript/storm-generate/impl.ts create mode 100644 tools/executors/typescript/storm-generate/schema.d.ts create mode 100644 tools/executors/typescript/storm-generate/schema.json diff --git a/apps/web/shell/app/layout.tsx b/apps/web/shell/app/layout.tsx index fcb0b16f..4312beea 100644 --- a/apps/web/shell/app/layout.tsx +++ b/apps/web/shell/app/layout.tsx @@ -27,6 +27,11 @@ import RootProvider from "./root-provider"; () => import("./(components)/cookie-policy-banner.client") );*/ +const title = "Pat Sullivan Development"; +const description = "Software designed for tomorrow's brands"; +const image = + "https://pub-e71cff0f90204755bc910518d63cacf8.r2.dev/circle-logo.png"; + const contactJsonLd: WithContext = { "@context": "https://schema.org", "@type": "ContactPoint", @@ -64,7 +69,8 @@ const personJsonLd: WithContext = { hasOccupation: architectJsonLd, jobTitle: "Software Architect", knowsLanguage: "en", - description: "Software designed for tomorrow's brands", + description: + "A financial technology developer based out of the New York metropolitan area.", contactPoint: contactJsonLd, }; @@ -72,18 +78,19 @@ export const metadata = { colorScheme: "dark", themeColor: "#18181B", title: { - template: "%s - Pat Sullivan Development", - default: "Pat Sullivan Development", + template: `%s - ${title}`, + default: title, + images: [image], }, authors: [{ name: "Pat Sullivan", url: "https://patsullivan.org" }], metadataBase: new URL("https://patsullivan.org"), - description: "Software designed for tomorrow's brands", + description: description, manifest: "https://patsullivan.org/manifest.json", noindex: false, nofollow: false, canonical: "https://patsullivan.org", generator: "Pat Sullivan", - applicationName: "Pat Sullivan Development", + applicationName: title, referrer: "origin-when-cross-origin", keywords: [ "Pat", diff --git a/apps/workers/contact-api/src/worker.ts b/apps/workers/contact-api/src/worker.ts index b9fa0686..dddb4a22 100644 --- a/apps/workers/contact-api/src/worker.ts +++ b/apps/workers/contact-api/src/worker.ts @@ -1,8 +1,7 @@ import { ContactApiServerContext, - DB, builder, -} from "@open-system/contact-server-data-access"; +} from "@open-system/contact-server-graphql"; import { initContextCache } from "@pothos/core"; import { YogaInitialContext, @@ -51,7 +50,7 @@ const handler = { }), }; - return yoga.fetch(request, context as ContactApiServerContext); + return yoga.fetch(request, context); } catch (e: any) { return new Response(e?.message, { status: 500 }); } diff --git a/tools/async-api/kafka/renderers/ClassRenderer.ts b/tools/async-api/kafka/renderers/ClassRenderer.ts index 73879de9..d659de41 100644 --- a/tools/async-api/kafka/renderers/ClassRenderer.ts +++ b/tools/async-api/kafka/renderers/ClassRenderer.ts @@ -12,9 +12,10 @@ export class ClassRenderer extends TypeScriptObjectRenderer { await this.runAdditionalContentPreset(), ]; - return `class ${ - this.model.name ?? this.model.name - } extends IntegrationEvent { + return ` + +@Event() +class ${this.model.name ?? this.model.name} extends IntegrationEvent { ${this.indent(this.renderBlock(content, 2))} }`; } diff --git a/tools/executors/typescript/executors.json b/tools/executors/typescript/executors.json index 2551ef94..90f88c19 100644 --- a/tools/executors/typescript/executors.json +++ b/tools/executors/typescript/executors.json @@ -39,6 +39,11 @@ "implementation": "../../../dist/tools/executors/typescript/design-tokens-build/impl", "schema": "../../../dist/tools/executors/typescript/design-tokens-build/schema.json", "description": "Build the latest design tokens code from the extracted figma JSON." + }, + "storm-generate": { + "implementation": "../../../dist/tools/executors/typescript/storm-generate/impl", + "schema": "../../../dist/tools/executors/typescript/storm-generate/schema.json", + "description": "Generate code based on a provided Storm model." } } } diff --git a/tools/executors/typescript/project.json b/tools/executors/typescript/project.json index 407c72db..83240fb3 100644 --- a/tools/executors/typescript/project.json +++ b/tools/executors/typescript/project.json @@ -160,6 +160,18 @@ "output": "." } ] + }, + "storm-generate": { + "outputPath": "dist/tools/executors/typescript/storm-generate", + "main": "tools/executors/typescript/storm-generate/impl.ts", + "deleteOutputPath": true, + "assets": [ + { + "input": "tools/executors/typescript/storm-generate", + "glob": "schema.json", + "output": "." + } + ] } } }, diff --git a/tools/executors/typescript/storm-generate/impl.ts b/tools/executors/typescript/storm-generate/impl.ts new file mode 100644 index 00000000..ad0488c5 --- /dev/null +++ b/tools/executors/typescript/storm-generate/impl.ts @@ -0,0 +1,57 @@ +import { ExecutorContext, workspaceRoot } from "@nx/devkit"; +import { executeAsync } from "@open-system/core-server-utilities"; +import { ConsoleLogger } from "@open-system/core-shared-utilities"; +import { generateAction } from "@open-system/tools-storm-schema"; +import { existsSync } from "fs"; +import Path from "path"; +import { StormGenerateExecutorSchema } from "./schema"; + +export default async function ( + options: StormGenerateExecutorSchema, + context: ExecutorContext +) { + let result!: unknown; + try { + ConsoleLogger.info("Executing Storm (Code Generation) executor..."); + + const buildTarget = + context.workspace.projects[context.projectName].targets.build; + + const schemaPath = Path.join(workspaceRoot, options.schema); + if (!existsSync(schemaPath)) { + ConsoleLogger.error( + `No Storm schema file could be found at: "${schemaPath}" ` + ); + return { success: false }; + } + + const outputPath = Path.join(workspaceRoot, buildTarget.options.outputPath); + if (existsSync(outputPath)) { + result = await executeAsync(`rmdir /S /Q "${outputPath}" `); + if (result) { + ConsoleLogger.error(result); + return { success: false }; + } + } + + await generateAction({ + schema: schemaPath, + packageManager: options.packageManager, + dependencyCheck: options.dependencyCheck, + outDir: outputPath, + }); + + ConsoleLogger.success( + `Storm (Code Generation) executor successfully ran for ${context.projectName}.` + ); + + return { success: !result }; + } catch (e) { + ConsoleLogger.error( + `An error occurred syncing client API for ${context.projectName}` + ); + ConsoleLogger.error(e); + + return { success: false }; + } +} diff --git a/tools/executors/typescript/storm-generate/schema.d.ts b/tools/executors/typescript/storm-generate/schema.d.ts new file mode 100644 index 00000000..740ef1a5 --- /dev/null +++ b/tools/executors/typescript/storm-generate/schema.d.ts @@ -0,0 +1,8 @@ +export type PackageManagers = "npm" | "yarn" | "pnpm"; + +export interface StormGenerateExecutorSchema { + schema: string; + outputPath: string; + packageManager: PackageManagers; + dependencyCheck: boolean; +} diff --git a/tools/executors/typescript/storm-generate/schema.json b/tools/executors/typescript/storm-generate/schema.json new file mode 100644 index 00000000..7df5cf12 --- /dev/null +++ b/tools/executors/typescript/storm-generate/schema.json @@ -0,0 +1,34 @@ +{ + "$schema": "http://json-schema.org/schema", + "cli": "nx", + "id": "storm-generate", + "title": "Open System - Storm Generate", + "description": "Generate code based on a provided Storm model", + "type": "object", + "properties": { + "schema": { + "type": "string", + "description": "The `.storm` file name and path of the Storm model to use", + "default": "./schema.storm" + }, + "outputPath": { + "type": "string", + "description": "Path to the directory where the files will be generated", + "default": "src/__generated__" + }, + "packageManager": { + "type": "string", + "description": "Name of the package manager used by this repository", + "options": [ + "npm", "yarn", "pnpm" + ], + "default": "npm" + }, + "dependencyCheck": { + "type": "boolean", + "description": "Should the currently installed Prisma version be checked", + "default": true + } + }, + "required": ["stormFile", "outputPath", "packageManager", "dependencyCheck"] +}