exp-node-server 1.1.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -20
- package/dist/cli.js +525 -0
- package/package.json +29 -9
- package/templates/mongoose/.dockerignore +10 -0
- package/templates/mongoose/.env.example +56 -7
- package/templates/mongoose/.prettierignore +3 -0
- package/templates/mongoose/.prettierrc +7 -0
- package/templates/mongoose/Dockerfile +33 -0
- package/templates/mongoose/_gitignore +32 -0
- package/templates/mongoose/docker-compose.yml +21 -0
- package/templates/mongoose/eslint.config.js +35 -0
- package/templates/mongoose/package-lock.json +6377 -0
- package/templates/mongoose/package.json +49 -10
- package/templates/mongoose/readme.md +85 -0
- package/templates/mongoose/src/app/configs/index.ts +178 -26
- package/templates/mongoose/src/app/errors/zodError.ts +16 -16
- package/templates/mongoose/src/app/lib/db.ts +18 -0
- package/templates/mongoose/src/app/lib/logger.ts +12 -0
- package/templates/mongoose/src/app/middlewares/auth.ts +48 -44
- package/templates/mongoose/src/app/middlewares/global_error_handler.ts +59 -65
- package/templates/mongoose/src/app/middlewares/not_found_api.ts +7 -7
- package/templates/mongoose/src/app/middlewares/rate_limiter.ts +153 -0
- package/templates/mongoose/src/app/middlewares/request_validator.ts +11 -10
- package/templates/mongoose/src/app/middlewares/uploader.ts +17 -13
- package/templates/mongoose/src/app/modules/account/account.controller.ts +156 -0
- package/templates/mongoose/src/app/modules/account/account.interface.ts +65 -0
- package/templates/mongoose/src/app/modules/account/account.route.ts +101 -0
- package/templates/mongoose/src/app/modules/account/account.schema.ts +97 -0
- package/templates/mongoose/src/app/modules/account/account.service.ts +422 -0
- package/templates/mongoose/src/app/modules/account/account.swagger.ts +278 -0
- package/templates/mongoose/src/app/modules/account/account.validation.ts +63 -0
- package/templates/mongoose/src/app/modules/profile/profile.controller.ts +17 -0
- package/templates/mongoose/src/app/modules/profile/profile.interface.ts +7 -0
- package/templates/mongoose/src/app/modules/profile/profile.route.ts +28 -0
- package/templates/mongoose/src/app/modules/profile/profile.schema.ts +13 -0
- package/templates/mongoose/src/app/modules/profile/profile.service.ts +28 -0
- package/templates/mongoose/src/app/modules/profile/profile.swagger.ts +34 -0
- package/templates/mongoose/src/app/modules/profile/profile.validation.ts +8 -0
- package/templates/mongoose/src/app/passport-js/index.ts +87 -0
- package/templates/mongoose/src/app/passport-js/oauth-state.ts +150 -0
- package/templates/mongoose/src/app/passport-js/providers.ts +258 -0
- package/templates/mongoose/src/app/passport-js/social-account.ts +141 -0
- package/templates/mongoose/src/app/queues/agenda.ts +24 -0
- package/templates/mongoose/src/app/queues/email.queue.ts +53 -0
- package/templates/mongoose/src/app/queues/index.ts +13 -0
- package/templates/mongoose/src/app/templates/otpEmailTemplate.ts +185 -0
- package/templates/mongoose/src/app/templates/resetPasswordEmailTemplate.ts +157 -0
- package/templates/mongoose/src/app/types/error.d.ts +7 -7
- package/templates/mongoose/src/app/types/express.d.ts +11 -0
- package/templates/mongoose/src/app/types/passport-oauth1.d.ts +51 -0
- package/templates/mongoose/src/app/utils/JWT.ts +38 -18
- package/templates/mongoose/src/app/utils/app_error.ts +10 -10
- package/templates/mongoose/src/app/utils/auth_cookie.ts +27 -0
- package/templates/mongoose/src/app/utils/catch_async.ts +8 -8
- package/templates/mongoose/src/app/utils/cloudinary.ts +26 -59
- package/templates/mongoose/src/app/utils/mail_sender.ts +26 -92
- package/templates/mongoose/src/app/utils/manage_response.ts +19 -19
- package/templates/mongoose/src/app/utils/otp.ts +20 -0
- package/templates/mongoose/src/app/utils/session.ts +55 -0
- package/templates/mongoose/src/app.ts +73 -42
- package/templates/mongoose/src/routes.ts +13 -13
- package/templates/mongoose/src/server.ts +38 -18
- package/templates/mongoose/src/swaggerOptions.ts +23 -23
- package/templates/mongoose/tests/app.test.ts +97 -0
- package/templates/mongoose/tests/global-setup.ts +15 -0
- package/templates/mongoose/tests/helpers/fixtures.ts +42 -0
- package/templates/mongoose/tests/routes/account.test.ts +614 -0
- package/templates/mongoose/tests/routes/profile.test.ts +95 -0
- package/templates/mongoose/tests/routes/social.test.ts +310 -0
- package/templates/mongoose/tests/setup.ts +25 -0
- package/templates/mongoose/tsconfig.json +16 -20
- package/templates/mongoose/vitest.config.ts +43 -0
- package/templates/prisma/.dockerignore +2 -0
- package/templates/prisma/.env.example +62 -6
- package/templates/prisma/.prettierignore +3 -0
- package/templates/prisma/.prettierrc +7 -0
- package/templates/prisma/.projectrc.json +1 -1
- package/templates/prisma/Dockerfile +21 -7
- package/templates/prisma/_gitignore +35 -0
- package/templates/prisma/docker-compose.yml +8 -7
- package/templates/prisma/eslint.config.js +35 -0
- package/templates/prisma/package-lock.json +7327 -0
- package/templates/prisma/package.json +47 -9
- package/templates/prisma/prisma/schema/account.schema.prisma +92 -10
- package/templates/prisma/prisma/schema/profile.schema.prisma +8 -3
- package/templates/prisma/prisma/schema/schema.prisma +1 -2
- package/templates/prisma/prisma.config.ts +5 -5
- package/templates/prisma/readme.md +81 -0
- package/templates/prisma/src/app/configs/index.ts +175 -26
- package/templates/prisma/src/app/errors/zodError.ts +16 -16
- package/templates/prisma/src/app/lib/logger.ts +12 -0
- package/templates/prisma/src/app/lib/prisma.ts +4 -6
- package/templates/prisma/src/app/middlewares/auth.ts +37 -16
- package/templates/prisma/src/app/middlewares/global_error_handler.ts +42 -35
- package/templates/prisma/src/app/middlewares/not_found_api.ts +7 -7
- package/templates/prisma/src/app/middlewares/rate_limiter.ts +124 -0
- package/templates/prisma/src/app/middlewares/request_validator.ts +4 -3
- package/templates/prisma/src/app/middlewares/uploader.ts +17 -13
- package/templates/prisma/src/app/modules/account/account.controller.ts +74 -34
- package/templates/prisma/src/app/modules/account/account.route.ts +68 -22
- package/templates/prisma/src/app/modules/account/account.service.ts +329 -309
- package/templates/prisma/src/app/modules/account/account.swagger.ts +167 -76
- package/templates/prisma/src/app/modules/account/account.validation.ts +41 -19
- package/templates/prisma/src/app/modules/profile/profile.controller.ts +4 -4
- package/templates/prisma/src/app/modules/profile/profile.route.ts +18 -12
- package/templates/prisma/src/app/modules/profile/profile.service.ts +11 -18
- package/templates/prisma/src/app/modules/profile/profile.swagger.ts +11 -11
- package/templates/prisma/src/app/modules/profile/profile.validation.ts +2 -2
- package/templates/prisma/src/app/passport-js/index.ts +87 -0
- package/templates/prisma/src/app/passport-js/oauth-state.ts +150 -0
- package/templates/prisma/src/app/passport-js/providers.ts +263 -0
- package/templates/prisma/src/app/passport-js/social-account.ts +147 -0
- package/templates/prisma/src/app/queues/boss.ts +8 -0
- package/templates/prisma/src/app/queues/email.queue.ts +56 -0
- package/templates/prisma/src/app/queues/index.ts +14 -0
- package/templates/prisma/src/app/queues/maintenance.queue.ts +30 -0
- package/templates/prisma/src/app/templates/otpEmailTemplate.ts +185 -0
- package/templates/prisma/src/app/templates/resetPasswordEmailTemplate.ts +157 -0
- package/templates/prisma/src/app/types/error.d.ts +7 -7
- package/templates/prisma/src/app/types/express.d.ts +11 -0
- package/templates/prisma/src/app/types/passport-oauth1.d.ts +51 -0
- package/templates/prisma/src/app/utils/JWT.ts +36 -17
- package/templates/prisma/src/app/utils/app_error.ts +10 -10
- package/templates/prisma/src/app/utils/auth_cookie.ts +27 -0
- package/templates/prisma/src/app/utils/catch_async.ts +8 -8
- package/templates/prisma/src/app/utils/cloudinary.ts +26 -59
- package/templates/prisma/src/app/utils/mail_sender.ts +26 -92
- package/templates/prisma/src/app/utils/manage_response.ts +19 -19
- package/templates/prisma/src/app/utils/otp.ts +20 -0
- package/templates/prisma/src/app/utils/session.ts +57 -0
- package/templates/prisma/src/app.ts +73 -42
- package/templates/prisma/src/routes.ts +12 -10
- package/templates/prisma/src/server.ts +37 -19
- package/templates/prisma/src/swaggerOptions.ts +22 -26
- package/templates/prisma/tests/app.test.ts +86 -0
- package/templates/prisma/tests/helpers/fixtures.ts +35 -0
- package/templates/prisma/tests/helpers/prisma.ts +32 -0
- package/templates/prisma/tests/routes/account.test.ts +627 -0
- package/templates/prisma/tests/routes/profile.test.ts +91 -0
- package/templates/prisma/tests/routes/social.test.ts +317 -0
- package/templates/prisma/tests/setup.ts +10 -0
- package/templates/prisma/tsconfig.json +16 -23
- package/templates/prisma/vitest.config.ts +38 -0
- package/bin/cli.js +0 -41
- package/src/createProject.js +0 -61
- package/src/generateModule.js +0 -93
- package/src/utils/getProjectType.js +0 -13
- package/src/utils/mongoose/controllerGenerator.js +0 -70
- package/src/utils/mongoose/routeGenerator.js +0 -27
- package/src/utils/mongoose/schemaGenerator.js +0 -11
- package/src/utils/mongoose/serviceGenerator.js +0 -49
- package/src/utils/mongoose/swaggerGenerator.js +0 -112
- package/src/utils/mongoose/validationGenerator.js +0 -13
- package/src/utils/prisma/prismaSchemaGenerator.js +0 -10
- package/src/utils/prisma/prismaServiceGenerator.js +0 -47
- package/src/utils/routeInjector.js +0 -40
- package/src/utils/swaggerInjector.js +0 -52
- package/src/utils/validateModuleName.js +0 -17
- package/src/utils/validateProjectName.js +0 -15
- package/src/utils.js +0 -26
- package/templates/mongoose/src/app/errors/castError.ts +0 -23
- package/templates/mongoose/src/app/errors/duplicateError.ts +0 -26
- package/templates/mongoose/src/app/errors/validationError.ts +0 -25
- package/templates/mongoose/src/app/modules/auth/auth.controller.ts +0 -127
- package/templates/mongoose/src/app/modules/auth/auth.interface.ts +0 -24
- package/templates/mongoose/src/app/modules/auth/auth.route.ts +0 -46
- package/templates/mongoose/src/app/modules/auth/auth.schema.ts +0 -19
- package/templates/mongoose/src/app/modules/auth/auth.service.ts +0 -324
- package/templates/mongoose/src/app/modules/auth/auth.swagger.ts +0 -214
- package/templates/mongoose/src/app/modules/auth/auth.validation.ts +0 -37
- package/templates/mongoose/src/app/modules/user/user.controller.ts +0 -17
- package/templates/mongoose/src/app/modules/user/user.interface.ts +0 -15
- package/templates/mongoose/src/app/modules/user/user.route.ts +0 -20
- package/templates/mongoose/src/app/modules/user/user.schema.ts +0 -22
- package/templates/mongoose/src/app/modules/user/user.service.ts +0 -22
- package/templates/mongoose/src/app/modules/user/user.swagger.ts +0 -75
- package/templates/mongoose/src/app/modules/user/user.validation.ts +0 -18
- package/templates/mongoose/src/app/types/index.d.ts +0 -12
- package/templates/mongoose/src/app/utils/isAccountExist.ts +0 -31
- package/templates/prisma/src/app/types/index.d.ts +0 -12
- package/templates/prisma/src/app/utils/otpGenerator.ts +0 -29
package/src/generateModule.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { createDir, createFile } from "./utils.js";
|
|
4
|
-
import { getProjectType } from './utils/getProjectType.js';
|
|
5
|
-
import { controllerGenerator } from "./utils/mongoose/controllerGenerator.js";
|
|
6
|
-
import { routeGenerator } from "./utils/mongoose/routeGenerator.js";
|
|
7
|
-
import { schemaGenerator } from "./utils/mongoose/schemaGenerator.js";
|
|
8
|
-
import { serviceGenerator } from "./utils/mongoose/serviceGenerator.js";
|
|
9
|
-
import { swaggerGenerator } from "./utils/mongoose/swaggerGenerator.js";
|
|
10
|
-
import { validationGenerator } from "./utils/mongoose/validationGenerator.js";
|
|
11
|
-
import { prismaSchemaGenerator } from "./utils/prisma/prismaSchemaGenerator.js";
|
|
12
|
-
import { prismaServiceGenerator } from "./utils/prisma/prismaServiceGenerator.js";
|
|
13
|
-
import { injectRoute } from "./utils/routeInjector.js";
|
|
14
|
-
import { injectSwagger } from "./utils/swaggerInjector.js";
|
|
15
|
-
|
|
16
|
-
export async function generateModule(name) {
|
|
17
|
-
|
|
18
|
-
const type = getProjectType();
|
|
19
|
-
|
|
20
|
-
const base = path.join(
|
|
21
|
-
process.cwd(),
|
|
22
|
-
"src/app/modules",
|
|
23
|
-
name
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
createDir(base);
|
|
27
|
-
|
|
28
|
-
createFile(
|
|
29
|
-
path.join(base, `${name}.controller.ts`),
|
|
30
|
-
controllerGenerator(name)
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
createFile(
|
|
34
|
-
path.join(base, `${name}.route.ts`),
|
|
35
|
-
routeGenerator(name)
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
createFile(
|
|
39
|
-
path.join(base, `${name}.validation.ts`),
|
|
40
|
-
validationGenerator(name)
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
createFile(
|
|
44
|
-
path.join(base, `${name}.swagger.ts`),
|
|
45
|
-
swaggerGenerator(name)
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
injectRoute(name);
|
|
49
|
-
injectSwagger(name);
|
|
50
|
-
|
|
51
|
-
//condition based generation
|
|
52
|
-
if (type === "mongoose") {
|
|
53
|
-
|
|
54
|
-
createFile(
|
|
55
|
-
path.join(base, `${name}.schema.ts`),
|
|
56
|
-
schemaGenerator(name)
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
createFile(
|
|
60
|
-
path.join(base, `${name}.interface.ts`),
|
|
61
|
-
`export type T_${name} = {}`
|
|
62
|
-
);
|
|
63
|
-
createFile(
|
|
64
|
-
path.join(base, `${name}.service.ts`),
|
|
65
|
-
serviceGenerator(name)
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
} else if (type === "prisma") {
|
|
69
|
-
|
|
70
|
-
// prisma schema file
|
|
71
|
-
const prismaDir = path.join(
|
|
72
|
-
process.cwd(),
|
|
73
|
-
"prisma/schema"
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
createFile(
|
|
77
|
-
path.join(prismaDir, `${name}.prisma`),
|
|
78
|
-
prismaSchemaGenerator(name)
|
|
79
|
-
);
|
|
80
|
-
createFile(
|
|
81
|
-
path.join(base, `${name}.service.ts`),
|
|
82
|
-
prismaServiceGenerator(name)
|
|
83
|
-
);
|
|
84
|
-
console.log(
|
|
85
|
-
chalk.blue("\n Run This Commands: \n")
|
|
86
|
-
);
|
|
87
|
-
console.log(
|
|
88
|
-
chalk.yellow(" npx prisma generate && npx prisma migrate dev\n")
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
console.log(chalk.green(`\nModule '${name}' created successfully`));
|
|
93
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
export function getProjectType() {
|
|
5
|
-
const configPath = path.join(process.cwd(), ".projectrc.json");
|
|
6
|
-
|
|
7
|
-
if (!fs.existsSync(configPath)) {
|
|
8
|
-
throw new Error("❌ .projectrc.json not found");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
12
|
-
return config.database;
|
|
13
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
export const controllerGenerator = (name) => {
|
|
2
|
-
return `
|
|
3
|
-
import catchAsync from "../../utils/catch_async";
|
|
4
|
-
import manageResponse from "../../utils/manage_response";
|
|
5
|
-
import { ${name}_service } from "./${name}.service";
|
|
6
|
-
|
|
7
|
-
const get_all_${name} = catchAsync(async (req, res) => {
|
|
8
|
-
const result = await ${name}_service.get_all_${name}_from_db(req);
|
|
9
|
-
manageResponse(res, {
|
|
10
|
-
success: true,
|
|
11
|
-
statusCode: 200,
|
|
12
|
-
message: "All ${name} fetched successfully.",
|
|
13
|
-
data: result,
|
|
14
|
-
meta: {},
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const get_single_${name} = catchAsync(async (req, res) => {
|
|
19
|
-
const result = await ${name}_service.get_single_${name}_from_db(req);
|
|
20
|
-
manageResponse(res, {
|
|
21
|
-
success: true,
|
|
22
|
-
statusCode: 200,
|
|
23
|
-
message: "Single ${name} fetched successfully.",
|
|
24
|
-
data: result,
|
|
25
|
-
meta: {},
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const create_${name} = catchAsync(async (req, res) => {
|
|
30
|
-
const result = await ${name}_service.create_${name}_into_db(req);
|
|
31
|
-
manageResponse(res, {
|
|
32
|
-
success: true,
|
|
33
|
-
statusCode: 200,
|
|
34
|
-
message: "${name} created successfully.",
|
|
35
|
-
data: result,
|
|
36
|
-
meta: {},
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const update_${name} = catchAsync(async (req, res) => {
|
|
41
|
-
const result = await ${name}_service.update_${name}_into_db(req);
|
|
42
|
-
manageResponse(res, {
|
|
43
|
-
success: true,
|
|
44
|
-
statusCode: 200,
|
|
45
|
-
message: "${name} updated successfully.",
|
|
46
|
-
data: result,
|
|
47
|
-
meta: {},
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const delete_${name} = catchAsync(async (req, res) => {
|
|
52
|
-
const result = await ${name}_service.delete_${name}_from_db(req);
|
|
53
|
-
manageResponse(res, {
|
|
54
|
-
success: true,
|
|
55
|
-
statusCode: 200,
|
|
56
|
-
message: "${name} deleted successfully.",
|
|
57
|
-
data: result,
|
|
58
|
-
meta: {},
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
export const ${name}_controller = {
|
|
63
|
-
get_all_${name},
|
|
64
|
-
get_single_${name},
|
|
65
|
-
create_${name},
|
|
66
|
-
update_${name},
|
|
67
|
-
delete_${name},
|
|
68
|
-
};
|
|
69
|
-
`
|
|
70
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const routeGenerator = (name) => {
|
|
2
|
-
|
|
3
|
-
return `
|
|
4
|
-
import { Router } from "express";
|
|
5
|
-
import RequestValidator from "../../middlewares/request_validator";
|
|
6
|
-
import { ${name}_controller } from "./${name}.controller";
|
|
7
|
-
import { ${name}_validations } from "./${name}.validation";
|
|
8
|
-
|
|
9
|
-
const router = Router();
|
|
10
|
-
|
|
11
|
-
router.get("/", ${name}_controller.get_all_${name});
|
|
12
|
-
router.post(
|
|
13
|
-
"/",
|
|
14
|
-
RequestValidator(${name}_validations.create_${name}),
|
|
15
|
-
${name}_controller.create_${name},
|
|
16
|
-
);
|
|
17
|
-
router.get("/:id", ${name}_controller.get_single_${name});
|
|
18
|
-
router.patch(
|
|
19
|
-
"/:id",
|
|
20
|
-
RequestValidator(${name}_validations.update_${name}),
|
|
21
|
-
${name}_controller.update_${name},
|
|
22
|
-
);
|
|
23
|
-
router.delete("/:id", ${name}_controller.delete_${name});
|
|
24
|
-
|
|
25
|
-
export default router;
|
|
26
|
-
`
|
|
27
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const schemaGenerator = (name) => {
|
|
2
|
-
return `
|
|
3
|
-
import { Schema, model } from "mongoose";
|
|
4
|
-
import { T_${name} } from "./${name}.interface";
|
|
5
|
-
|
|
6
|
-
const schema = new Schema<T_${name}>({},{timestamps: true, versionKey: false});
|
|
7
|
-
|
|
8
|
-
export const ${name}_model = model("${name}", schema);
|
|
9
|
-
|
|
10
|
-
`
|
|
11
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export const serviceGenerator = (name) => {
|
|
2
|
-
return `
|
|
3
|
-
import { Request } from "express";
|
|
4
|
-
import { ${name}_model } from "./${name}.schema";
|
|
5
|
-
|
|
6
|
-
const get_all_${name}_from_db = async (req: Request) => {
|
|
7
|
-
// define your own login here
|
|
8
|
-
const result = await ${name}_model.find().lean();
|
|
9
|
-
return result;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const get_single_${name}_from_db = async (req: Request) => {
|
|
13
|
-
// define your own login here
|
|
14
|
-
const { id } = req.params;
|
|
15
|
-
const result = await ${name}_model.findById(id).lean();
|
|
16
|
-
return result;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const create_${name}_into_db = async (req: Request) => {
|
|
20
|
-
// define your own login here
|
|
21
|
-
const result = await ${name}_model.create(req.body);
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const update_${name}_into_db = async (req: Request) => {
|
|
26
|
-
// define your own login here
|
|
27
|
-
const { id } = req.params;
|
|
28
|
-
const result = await ${name}_model.findByIdAndUpdate(id, req.body, {
|
|
29
|
-
new: true,
|
|
30
|
-
});
|
|
31
|
-
return result;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const delete_${name}_from_db = async (req: Request) => {
|
|
35
|
-
// define your own login here
|
|
36
|
-
const { id } = req.params;
|
|
37
|
-
const result = await ${name}_model.findByIdAndDelete(id);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const ${name}_service = {
|
|
42
|
-
get_all_${name}_from_db,
|
|
43
|
-
get_single_${name}_from_db,
|
|
44
|
-
create_${name}_into_db,
|
|
45
|
-
update_${name}_into_db,
|
|
46
|
-
delete_${name}_from_db,
|
|
47
|
-
};
|
|
48
|
-
`
|
|
49
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
export const swaggerGenerator = (name) => {
|
|
2
|
-
return `
|
|
3
|
-
export const ${name}SwaggerDocs = {
|
|
4
|
-
"/api/${name}": {
|
|
5
|
-
post: {
|
|
6
|
-
tags: ["${name}"],
|
|
7
|
-
summary: "Create new ${name}",
|
|
8
|
-
description: "",
|
|
9
|
-
requestBody: {
|
|
10
|
-
required: true,
|
|
11
|
-
content: {
|
|
12
|
-
"application/json": {
|
|
13
|
-
example: JSON.stringify({}), // put your request body
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
responses: {
|
|
18
|
-
201: { description: "${name} created successfully" },
|
|
19
|
-
500: { description: "Validation error or internal server error" },
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
get: {
|
|
23
|
-
tags: ["${name}"],
|
|
24
|
-
summary: "Get all ${name}",
|
|
25
|
-
description: "",
|
|
26
|
-
parameters: [
|
|
27
|
-
{
|
|
28
|
-
name: "page",
|
|
29
|
-
in: "query",
|
|
30
|
-
required: false,
|
|
31
|
-
schema: { type: "number" },
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: "limit",
|
|
35
|
-
in: "query",
|
|
36
|
-
required: false,
|
|
37
|
-
schema: { type: "number" },
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
responses: {
|
|
41
|
-
200: { description: "${name} fetched successfully" },
|
|
42
|
-
401: { description: "unauthorized" },
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
"/api/${name}/{id}": {
|
|
48
|
-
get: {
|
|
49
|
-
tags: ["${name}"],
|
|
50
|
-
summary: "Get single ${name}",
|
|
51
|
-
description: "",
|
|
52
|
-
parameters: [
|
|
53
|
-
{
|
|
54
|
-
name: "id",
|
|
55
|
-
in: "path",
|
|
56
|
-
required: true,
|
|
57
|
-
schema: { type: "string" },
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
responses: {
|
|
61
|
-
200: { description: "${name} fetched successfully" },
|
|
62
|
-
401: { description: "unauthorized" },
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
patch: {
|
|
66
|
-
tags: ["${name}"],
|
|
67
|
-
summary: "Update ${name}",
|
|
68
|
-
description: "",
|
|
69
|
-
parameters: [
|
|
70
|
-
{
|
|
71
|
-
name: "id",
|
|
72
|
-
in: "path",
|
|
73
|
-
required: true,
|
|
74
|
-
schema: { type: "string" },
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
requestBody: {
|
|
78
|
-
required: true,
|
|
79
|
-
content: {
|
|
80
|
-
"application/json": {
|
|
81
|
-
example: JSON.stringify({}), // put your request body
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
responses: {
|
|
86
|
-
200: { description: "${name} updated successfully" },
|
|
87
|
-
500: { description: "Validation error or internal server error" },
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
delete: {
|
|
91
|
-
tags: ["${name}"],
|
|
92
|
-
summary: "Delete ${name}",
|
|
93
|
-
description: "",
|
|
94
|
-
parameters: [
|
|
95
|
-
{
|
|
96
|
-
name: "id",
|
|
97
|
-
in: "path",
|
|
98
|
-
required: true,
|
|
99
|
-
schema: { type: "string" },
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
responses: {
|
|
103
|
-
200: { description: "${name} delete successfully" },
|
|
104
|
-
401: { description: "unauthorized" },
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
`
|
|
112
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const validationGenerator = (name) => {
|
|
2
|
-
return `
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
|
|
5
|
-
const create_${name} = z.object({});
|
|
6
|
-
const update_${name} = z.object({});
|
|
7
|
-
|
|
8
|
-
export const ${name}_validations = {
|
|
9
|
-
create_${name},
|
|
10
|
-
update_${name},
|
|
11
|
-
};
|
|
12
|
-
`
|
|
13
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export const prismaServiceGenerator = (name) => {
|
|
2
|
-
return `
|
|
3
|
-
import { Request } from "express";
|
|
4
|
-
import { prisma } from "../../lib/prisma";
|
|
5
|
-
|
|
6
|
-
const get_all_${name}_from_db = async (req: Request) => {
|
|
7
|
-
// define your own login here
|
|
8
|
-
const result = await prisma.${name}.findMany();
|
|
9
|
-
return result;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const get_single_${name}_from_db = async (req: Request) => {
|
|
13
|
-
// define your own login here
|
|
14
|
-
const { id } = req.params;
|
|
15
|
-
const result = await prisma.${name}.findUnique({where:{id}});
|
|
16
|
-
return result;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const create_${name}_into_db = async (req: Request) => {
|
|
20
|
-
// define your own login here
|
|
21
|
-
const result = await prisma.${name}.create({data:req.body});
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const update_${name}_into_db = async (req: Request) => {
|
|
26
|
-
// define your own login here
|
|
27
|
-
const { id } = req.params;
|
|
28
|
-
const result = await prisma.${name}.update({where:{id},data:req.body});
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const delete_${name}_from_db = async (req: Request) => {
|
|
33
|
-
// define your own login here
|
|
34
|
-
const { id } = req.params;
|
|
35
|
-
const result = await prisma.${name}.delete({where:{id}});
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const ${name}_service = {
|
|
40
|
-
get_all_${name}_from_db,
|
|
41
|
-
get_single_${name}_from_db,
|
|
42
|
-
create_${name}_into_db,
|
|
43
|
-
update_${name}_into_db,
|
|
44
|
-
delete_${name}_from_db,
|
|
45
|
-
};
|
|
46
|
-
`
|
|
47
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
export function injectRoute(name) {
|
|
6
|
-
const routeFile = path.join(process.cwd(), "src/routes.ts");
|
|
7
|
-
|
|
8
|
-
if (!fs.existsSync(routeFile)) {
|
|
9
|
-
console.log(chalk.yellow("routes.ts not found"));
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let content = fs.readFileSync(routeFile, "utf-8");
|
|
14
|
-
|
|
15
|
-
const importLine = `import ${name}Route from "./app/modules/${name}/${name}.route";`;
|
|
16
|
-
const routeEntry = `{ path: "/${name}", route: ${name}Route },`;
|
|
17
|
-
|
|
18
|
-
// add import
|
|
19
|
-
if (!content.includes(importLine)) {
|
|
20
|
-
const lastImportIndex = content.lastIndexOf("import ");
|
|
21
|
-
const nextLine = content.indexOf("\n", lastImportIndex);
|
|
22
|
-
|
|
23
|
-
content =
|
|
24
|
-
content.slice(0, nextLine + 1) +
|
|
25
|
-
importLine +
|
|
26
|
-
"\n" +
|
|
27
|
-
content.slice(nextLine + 1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// add route entry
|
|
31
|
-
if (!content.includes(routeEntry)) {
|
|
32
|
-
content = content.replace(
|
|
33
|
-
/const moduleRoutes = \[/,
|
|
34
|
-
`const moduleRoutes = [\n ${routeEntry}`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fs.writeFileSync(routeFile, content);
|
|
39
|
-
console.log(chalk.green(`Route registered for ${name}`));
|
|
40
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
export function injectSwagger(name) {
|
|
6
|
-
|
|
7
|
-
const swaggerFile = path.join(process.cwd(), "src/swaggerOptions.ts");
|
|
8
|
-
|
|
9
|
-
if (!fs.existsSync(swaggerFile)) {
|
|
10
|
-
console.log(chalk.yellow("⚠️ swaggerOptions.ts not found"));
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let content = fs.readFileSync(swaggerFile, "utf-8");
|
|
15
|
-
|
|
16
|
-
const importLine = `import { ${name}SwaggerDocs } from "./app/modules/${name}/${name}.swagger";`;
|
|
17
|
-
const spreadLine = ` ...${name}SwaggerDocs,`;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!content.includes(importLine)) {
|
|
21
|
-
|
|
22
|
-
const lastImportIndex = content.lastIndexOf("import ");
|
|
23
|
-
const nextLine = content.indexOf("\n", lastImportIndex);
|
|
24
|
-
|
|
25
|
-
content =
|
|
26
|
-
content.slice(0, nextLine + 1) +
|
|
27
|
-
importLine +
|
|
28
|
-
"\n" +
|
|
29
|
-
content.slice(nextLine + 1);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (!content.includes(spreadLine)) {
|
|
33
|
-
|
|
34
|
-
const match = content.match(/paths:\s*{([\s\S]*?)}/);
|
|
35
|
-
|
|
36
|
-
if (match) {
|
|
37
|
-
|
|
38
|
-
const pathsBlock = match[0];
|
|
39
|
-
|
|
40
|
-
const updatedBlock = pathsBlock.replace(
|
|
41
|
-
/}$/,
|
|
42
|
-
`${spreadLine}\n }`
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
content = content.replace(pathsBlock, updatedBlock);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
fs.writeFileSync(swaggerFile, content);
|
|
50
|
-
|
|
51
|
-
console.log(chalk.green(`✔ Swagger registered for ${name}`));
|
|
52
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export function validateModuleName(name) {
|
|
2
|
-
|
|
3
|
-
if (!name) return null;
|
|
4
|
-
|
|
5
|
-
// convert space / dash → underscore
|
|
6
|
-
const normalized = name
|
|
7
|
-
.trim()
|
|
8
|
-
.toLowerCase()
|
|
9
|
-
.replace(/[-\s]+/g, "_");
|
|
10
|
-
|
|
11
|
-
// allow only a-z and underscore
|
|
12
|
-
const isValid = /^[a-z_]+$/.test(normalized);
|
|
13
|
-
|
|
14
|
-
if (!isValid) return null;
|
|
15
|
-
|
|
16
|
-
return normalized;
|
|
17
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function validateProjectName(name) {
|
|
2
|
-
|
|
3
|
-
if (!name) return null;
|
|
4
|
-
|
|
5
|
-
const normalized = name
|
|
6
|
-
.trim()
|
|
7
|
-
.toLowerCase()
|
|
8
|
-
.replace(/\s+/g, "-");
|
|
9
|
-
|
|
10
|
-
const isValid = /^[a-z0-9-]+$/.test(normalized);
|
|
11
|
-
|
|
12
|
-
if (!isValid) return null;
|
|
13
|
-
|
|
14
|
-
return normalized;
|
|
15
|
-
}
|
package/src/utils.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import ora from "ora";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
export const createDir = (dir) => {
|
|
6
|
-
if (!fs.existsSync(dir)) {
|
|
7
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const createFile = (file, content) => {
|
|
12
|
-
const spinner = ora(`Creating ${path.basename(file)}...`).start();
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
fs.writeFileSync(file, content);
|
|
16
|
-
spinner.succeed(`${path.basename(file)} created`);
|
|
17
|
-
} catch {
|
|
18
|
-
spinner.fail(`${path.basename(file)} failed`);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const toSnakeCase = (str) =>
|
|
23
|
-
str.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
24
|
-
|
|
25
|
-
export const toPascalCase = (str) =>
|
|
26
|
-
str.charAt(0).toUpperCase() + str.slice(1);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import mongoose from 'mongoose'
|
|
2
|
-
import { TErrorSources, TGenericErrorResponse } from '../types/error'
|
|
3
|
-
|
|
4
|
-
const handleCastError = (
|
|
5
|
-
err: mongoose.Error.CastError
|
|
6
|
-
): TGenericErrorResponse => {
|
|
7
|
-
const errorSources: TErrorSources= [
|
|
8
|
-
{
|
|
9
|
-
path: err.path,
|
|
10
|
-
message: err.message
|
|
11
|
-
}
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
const statusCode = 400
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
statusCode,
|
|
18
|
-
message: 'Invalid ID',
|
|
19
|
-
errorSources
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default handleCastError
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { TErrorSources, TGenericErrorResponse } from '../types/error'
|
|
2
|
-
|
|
3
|
-
const handleDuplicateError = (err: any): TGenericErrorResponse => {
|
|
4
|
-
// Extract value within double quotes using regex
|
|
5
|
-
const match = err.message.match(/"([^"]*)"/)
|
|
6
|
-
|
|
7
|
-
// The extracted value will be in the first capturing group
|
|
8
|
-
const extractedMessage = match && match[1]
|
|
9
|
-
|
|
10
|
-
const errorSources: TErrorSources = [
|
|
11
|
-
{
|
|
12
|
-
path: '',
|
|
13
|
-
message: `${extractedMessage} is already exists`
|
|
14
|
-
}
|
|
15
|
-
]
|
|
16
|
-
|
|
17
|
-
const statusCode = 400
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
statusCode,
|
|
21
|
-
message: 'Invalid ID',
|
|
22
|
-
errorSources
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default handleDuplicateError
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import mongoose from 'mongoose'
|
|
2
|
-
import { TErrorSources, TGenericErrorResponse } from '../types/error'
|
|
3
|
-
|
|
4
|
-
const handleValidationError = (
|
|
5
|
-
err: mongoose.Error.ValidationError
|
|
6
|
-
): TGenericErrorResponse => {
|
|
7
|
-
const errorSources: TErrorSources = Object.values(err.errors).map(
|
|
8
|
-
(val: mongoose.Error.ValidatorError | mongoose.Error.CastError) => {
|
|
9
|
-
return {
|
|
10
|
-
path: val?.path,
|
|
11
|
-
message: val?.message
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
const statusCode = 400
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
statusCode,
|
|
20
|
-
message: 'Validation Error',
|
|
21
|
-
errorSources
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default handleValidationError
|