Skip to content

Commit

Permalink
Merge pull request #33 from expressots/feature/32-create-middleware-s…
Browse files Browse the repository at this point in the history
…caffold

feat: add middleware scaffold
  • Loading branch information
rsaz committed Mar 22, 2024
2 parents ea42780 + 56aaea6 commit a4d2992
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/generate/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -40,6 +42,7 @@ const generateProject = (): CommandModule<CommandModuleArgs, any> => {
"provider",
"entity",
"module",
"middleware",
] as const,
describe: "The schematic to generate",
type: "string",
Expand Down
5 changes: 4 additions & 1 deletion src/generate/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ const splitTarget = async ({
target.includes("\\") ||
target.includes("//")
) {
//pathContent = target.split("/").filter((item) => item !== "");
if (schematic === "service") schematic = "controller";
if (
schematic === "service" ||
Expand Down Expand Up @@ -448,6 +447,10 @@ const schematicFolder = (schematic: string): string | undefined => {
return "providers";
case "entity":
return "entities";
case "middleware":
return "providers/middlewares";
case "module":
return "useCases";
}

return undefined;
Expand Down
10 changes: 10 additions & 0 deletions src/generate/templates/middleware.tpl
Original file line number Diff line number Diff line change
@@ -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<void> {
throw new Error("Method not implemented.");
}
}
3 changes: 2 additions & 1 deletion src/generate/templates/module-default.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ContainerModule } from "inversify";
import { CreateModule } from "@expressots/core";

export const {{moduleName}}Module = CreateModule([]);
export const {{moduleName}}Module: ContainerModule = CreateModule([]);
3 changes: 2 additions & 1 deletion src/generate/templates/module.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ContainerModule } from "inversify";
import { CreateModule } from "@expressots/core";
import { {{className}}Controller } from "{{{path}}}";

export const {{moduleName}}Module = CreateModule([{{className}}Controller]);
export const {{moduleName}}Module: ContainerModule = CreateModule([{{className}}Controller]);

0 comments on commit a4d2992

Please sign in to comment.