From 5ffcac103bf163c577c89142c2290b51277def18 Mon Sep 17 00:00:00 2001 From: Juliano Leonardo Soares Date: Mon, 18 Mar 2024 15:03:29 -0300 Subject: [PATCH] feat: add middleware scaffold --- src/generate/cli.ts | 5 ++++- src/generate/form.ts | 2 ++ src/generate/templates/middleware.tpl | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/generate/templates/middleware.tpl diff --git a/src/generate/cli.ts b/src/generate/cli.ts index 79455de..bb533d2 100644 --- a/src/generate/cli.ts +++ b/src/generate/cli.ts @@ -18,8 +18,10 @@ const coerceSchematicAliases = (arg: string) => { return "provider"; case "e": return "entity"; - case "m": + case "mo": return "module"; + case "m": + return "middleware"; default: return arg; } @@ -40,6 +42,7 @@ const generateProject = (): CommandModule => { "provider", "entity", "module", + "middleware", ] as const, describe: "The schematic to generate", type: "string", diff --git a/src/generate/form.ts b/src/generate/form.ts index 099f99a..8c1d17e 100644 --- a/src/generate/form.ts +++ b/src/generate/form.ts @@ -448,6 +448,8 @@ const schematicFolder = (schematic: string): string | undefined => { return "providers"; case "entity": return "entities"; + case "middleware": + return "providers/middlewares"; } return undefined; diff --git a/src/generate/templates/middleware.tpl b/src/generate/templates/middleware.tpl new file mode 100644 index 0000000..1dac6d1 --- /dev/null +++ b/src/generate/templates/middleware.tpl @@ -0,0 +1,10 @@ +import { ExpressoMiddleware } from "@expressots/core"; +import { NextFunction, Request, Response } from "express"; +import { provide } from "inversify-binding-decorators"; + +@provide({{className}}Middleware) +export class {{className}}Middleware extends ExpressoMiddleware { + use(req: Request, res: Response, next: NextFunction): void | Promise { + throw new Error("Method not implemented."); + } +} \ No newline at end of file