Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add middleware scaffold #33

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]);