create-charcole 2.2.0 → 2.2.2
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/.github/workflows/release.yml +26 -26
- package/CHANGELOG.md +301 -301
- package/LICENSE +21 -21
- package/README.md +357 -354
- package/bin/index.js +494 -444
- package/bin/lib/pkgManager.js +49 -49
- package/bin/lib/templateHandler.js +33 -33
- package/package.json +42 -27
- package/packages/swagger/BACKWARD_COMPATIBILITY.md +1 -1
- package/packages/swagger/CHANGELOG.md +1 -1
- package/packages/swagger/README.md +3 -3
- package/packages/swagger/package.json +57 -44
- package/packages/swagger/src/index.d.ts +126 -126
- package/packages/swagger/src/index.js +12 -12
- package/packages/swagger/src/setup.js +100 -100
- package/template/js/.env.example +16 -15
- package/template/js/README.md +982 -978
- package/template/js/basePackage.json +26 -26
- package/template/js/src/app.js +81 -81
- package/template/js/src/config/constants.js +20 -20
- package/template/js/src/config/env.js +26 -26
- package/template/js/src/config/swagger.config.js +15 -15
- package/template/js/src/lib/swagger/SWAGGER_GUIDE.md +3 -3
- package/template/js/src/middlewares/errorHandler.js +180 -180
- package/template/js/src/middlewares/requestLogger.js +33 -33
- package/template/js/src/middlewares/validateRequest.js +42 -42
- package/template/js/src/modules/auth/auth.constants.js +3 -3
- package/template/js/src/modules/auth/auth.controller.js +29 -29
- package/template/js/src/modules/auth/auth.middlewares.js +19 -19
- package/template/js/src/modules/auth/auth.routes.js +131 -131
- package/template/js/src/modules/auth/auth.schemas.js +60 -60
- package/template/js/src/modules/auth/auth.service.js +67 -67
- package/template/js/src/modules/auth/package.json +6 -6
- package/template/js/src/modules/health/controller.js +151 -151
- package/template/js/src/modules/swagger/package.json +5 -5
- package/template/js/src/repositories/user.repo.js +19 -19
- package/template/js/src/routes/index.js +25 -25
- package/template/js/src/routes/protected.js +57 -57
- package/template/js/src/server.js +38 -38
- package/template/js/src/utils/AppError.js +182 -182
- package/template/js/src/utils/logger.js +73 -73
- package/template/js/src/utils/response.js +51 -51
- package/template/ts/.env.example +16 -15
- package/template/ts/README.md +982 -978
- package/template/ts/basePackage.json +36 -36
- package/template/ts/build.js +46 -46
- package/template/ts/src/app.ts +71 -71
- package/template/ts/src/config/constants.ts +27 -27
- package/template/ts/src/config/env.ts +40 -40
- package/template/ts/src/config/swagger.config.ts +30 -30
- package/template/ts/src/lib/swagger/SWAGGER_GUIDE.md +2 -2
- package/template/ts/src/middlewares/errorHandler.ts +201 -201
- package/template/ts/src/middlewares/requestLogger.ts +38 -38
- package/template/ts/src/middlewares/validateRequest.ts +46 -46
- package/template/ts/src/modules/auth/auth.constants.ts +6 -6
- package/template/ts/src/modules/auth/auth.controller.ts +32 -32
- package/template/ts/src/modules/auth/auth.middlewares.ts +46 -46
- package/template/ts/src/modules/auth/auth.routes.ts +52 -52
- package/template/ts/src/modules/auth/auth.schemas.ts +73 -73
- package/template/ts/src/modules/auth/auth.service.ts +106 -106
- package/template/ts/src/modules/auth/package.json +10 -10
- package/template/ts/src/modules/health/controller.ts +80 -80
- package/template/ts/src/modules/swagger/package.json +5 -5
- package/template/ts/src/repositories/user.repo.ts +33 -33
- package/template/ts/src/routes/index.ts +24 -24
- package/template/ts/src/routes/protected.ts +46 -46
- package/template/ts/src/server.ts +41 -41
- package/template/ts/src/types/express.d.ts +9 -9
- package/template/ts/src/utils/AppError.ts +220 -220
- package/template/ts/src/utils/logger.ts +55 -55
- package/template/ts/src/utils/response.ts +100 -100
- package/template/ts/tsconfig.json +26 -26
- package/packages/swagger/package-lock.json +0 -1715
- package/tmpclaude-1049-cwd +0 -1
- package/tmpclaude-3e37-cwd +0 -1
- package/tmpclaude-4d73-cwd +0 -1
- package/tmpclaude-8a8e-cwd +0 -1
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import swaggerUi from "swagger-ui-express";
|
|
2
|
-
import swaggerJSDoc from "swagger-jsdoc";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import { registerSchemas, getCommonResponses } from "./helpers.js";
|
|
6
|
-
|
|
7
|
-
export function setupSwagger(app, options = {}) {
|
|
8
|
-
const defaultOptions = {
|
|
9
|
-
title: "Charcole API",
|
|
10
|
-
version: "1.0.
|
|
11
|
-
description: "Auto-generated API documentation",
|
|
12
|
-
path: "/api-docs",
|
|
13
|
-
servers: [{ url: "http://localhost:3000", description: "Local server" }],
|
|
14
|
-
// NEW: Auto-register Zod schemas
|
|
15
|
-
schemas: {},
|
|
16
|
-
// NEW: Include common response templates
|
|
17
|
-
includeCommonResponses: true,
|
|
18
|
-
// NEW: Custom response schemas
|
|
19
|
-
customResponses: {},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const config = { ...defaultOptions, ...options };
|
|
23
|
-
|
|
24
|
-
// Detect if running TypeScript or JavaScript by checking if src directory has .ts files
|
|
25
|
-
const srcPath = path.join(process.cwd(), "src");
|
|
26
|
-
const hasSrcDir = fs.existsSync(srcPath);
|
|
27
|
-
|
|
28
|
-
let isTypeScript = false;
|
|
29
|
-
if (hasSrcDir) {
|
|
30
|
-
// Check if there are any .ts files in src directory
|
|
31
|
-
const files = fs.readdirSync(srcPath);
|
|
32
|
-
isTypeScript = files.some((file) => file.endsWith(".ts"));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Determine file extensions to scan
|
|
36
|
-
const fileExtension = isTypeScript ? "ts" : "js";
|
|
37
|
-
|
|
38
|
-
// Build API paths based on project structure
|
|
39
|
-
const apiPaths = [
|
|
40
|
-
`${process.cwd()}/src/modules/**/*.${fileExtension}`,
|
|
41
|
-
`${process.cwd()}/src/routes/**/*.${fileExtension}`,
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
// NEW: Build components with auto-registered schemas
|
|
45
|
-
const components = {
|
|
46
|
-
securitySchemes: {
|
|
47
|
-
bearerAuth: {
|
|
48
|
-
type: "http",
|
|
49
|
-
scheme: "bearer",
|
|
50
|
-
bearerFormat: "JWT",
|
|
51
|
-
description: "Enter your JWT token in the format: your-token-here",
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
schemas: {},
|
|
55
|
-
responses: {},
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// NEW: Register Zod schemas if provided
|
|
59
|
-
if (config.schemas && Object.keys(config.schemas).length > 0) {
|
|
60
|
-
try {
|
|
61
|
-
const registeredSchemas = registerSchemas(config.schemas);
|
|
62
|
-
components.schemas = { ...registeredSchemas };
|
|
63
|
-
console.log(
|
|
64
|
-
`✅ Auto-registered ${Object.keys(registeredSchemas).length} Zod schemas`,
|
|
65
|
-
);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
console.warn("⚠️ Failed to register some Zod schemas:", error.message);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// NEW: Add common response templates
|
|
72
|
-
if (config.includeCommonResponses) {
|
|
73
|
-
components.responses = {
|
|
74
|
-
...getCommonResponses(),
|
|
75
|
-
...config.customResponses,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const openApiSpec = swaggerJSDoc({
|
|
80
|
-
definition: {
|
|
81
|
-
openapi: "3.0.0",
|
|
82
|
-
info: {
|
|
83
|
-
title: config.title,
|
|
84
|
-
version: config.version,
|
|
85
|
-
description: config.description,
|
|
86
|
-
},
|
|
87
|
-
servers: config.servers,
|
|
88
|
-
components,
|
|
89
|
-
},
|
|
90
|
-
apis: apiPaths,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
app.use(config.path, swaggerUi.serve, swaggerUi.setup(openApiSpec));
|
|
94
|
-
|
|
95
|
-
console.log(
|
|
96
|
-
`✅ Swagger UI available at http://localhost:${process.env.PORT || 3000}${config.path}`,
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
return openApiSpec;
|
|
100
|
-
}
|
|
1
|
+
import swaggerUi from "swagger-ui-express";
|
|
2
|
+
import swaggerJSDoc from "swagger-jsdoc";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { registerSchemas, getCommonResponses } from "./helpers.js";
|
|
6
|
+
|
|
7
|
+
export function setupSwagger(app, options = {}) {
|
|
8
|
+
const defaultOptions = {
|
|
9
|
+
title: "Charcole API",
|
|
10
|
+
version: "1.0.1",
|
|
11
|
+
description: "Auto-generated API documentation",
|
|
12
|
+
path: "/api-docs",
|
|
13
|
+
servers: [{ url: "http://localhost:3000", description: "Local server" }],
|
|
14
|
+
// NEW: Auto-register Zod schemas
|
|
15
|
+
schemas: {},
|
|
16
|
+
// NEW: Include common response templates
|
|
17
|
+
includeCommonResponses: true,
|
|
18
|
+
// NEW: Custom response schemas
|
|
19
|
+
customResponses: {},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const config = { ...defaultOptions, ...options };
|
|
23
|
+
|
|
24
|
+
// Detect if running TypeScript or JavaScript by checking if src directory has .ts files
|
|
25
|
+
const srcPath = path.join(process.cwd(), "src");
|
|
26
|
+
const hasSrcDir = fs.existsSync(srcPath);
|
|
27
|
+
|
|
28
|
+
let isTypeScript = false;
|
|
29
|
+
if (hasSrcDir) {
|
|
30
|
+
// Check if there are any .ts files in src directory
|
|
31
|
+
const files = fs.readdirSync(srcPath);
|
|
32
|
+
isTypeScript = files.some((file) => file.endsWith(".ts"));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Determine file extensions to scan
|
|
36
|
+
const fileExtension = isTypeScript ? "ts" : "js";
|
|
37
|
+
|
|
38
|
+
// Build API paths based on project structure
|
|
39
|
+
const apiPaths = [
|
|
40
|
+
`${process.cwd()}/src/modules/**/*.${fileExtension}`,
|
|
41
|
+
`${process.cwd()}/src/routes/**/*.${fileExtension}`,
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
// NEW: Build components with auto-registered schemas
|
|
45
|
+
const components = {
|
|
46
|
+
securitySchemes: {
|
|
47
|
+
bearerAuth: {
|
|
48
|
+
type: "http",
|
|
49
|
+
scheme: "bearer",
|
|
50
|
+
bearerFormat: "JWT",
|
|
51
|
+
description: "Enter your JWT token in the format: your-token-here",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
schemas: {},
|
|
55
|
+
responses: {},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// NEW: Register Zod schemas if provided
|
|
59
|
+
if (config.schemas && Object.keys(config.schemas).length > 0) {
|
|
60
|
+
try {
|
|
61
|
+
const registeredSchemas = registerSchemas(config.schemas);
|
|
62
|
+
components.schemas = { ...registeredSchemas };
|
|
63
|
+
console.log(
|
|
64
|
+
`✅ Auto-registered ${Object.keys(registeredSchemas).length} Zod schemas`,
|
|
65
|
+
);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.warn("⚠️ Failed to register some Zod schemas:", error.message);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// NEW: Add common response templates
|
|
72
|
+
if (config.includeCommonResponses) {
|
|
73
|
+
components.responses = {
|
|
74
|
+
...getCommonResponses(),
|
|
75
|
+
...config.customResponses,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const openApiSpec = swaggerJSDoc({
|
|
80
|
+
definition: {
|
|
81
|
+
openapi: "3.0.0",
|
|
82
|
+
info: {
|
|
83
|
+
title: config.title,
|
|
84
|
+
version: config.version,
|
|
85
|
+
description: config.description,
|
|
86
|
+
},
|
|
87
|
+
servers: config.servers,
|
|
88
|
+
components,
|
|
89
|
+
},
|
|
90
|
+
apis: apiPaths,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
app.use(config.path, swaggerUi.serve, swaggerUi.setup(openApiSpec));
|
|
94
|
+
|
|
95
|
+
console.log(
|
|
96
|
+
`✅ Swagger UI available at http://localhost:${process.env.PORT || 3000}${config.path}`,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return openApiSpec;
|
|
100
|
+
}
|
package/template/js/.env.example
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
# Server Configuration
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
# Server Configuration
|
|
2
|
+
APP_NAME=CHARCOLE API
|
|
3
|
+
NODE_ENV=development
|
|
4
|
+
PORT=3000
|
|
5
|
+
|
|
6
|
+
# Logging
|
|
7
|
+
LOG_LEVEL=info
|
|
8
|
+
|
|
9
|
+
# CORS
|
|
10
|
+
CORS_ORIGIN=*
|
|
11
|
+
|
|
12
|
+
# Request
|
|
13
|
+
REQUEST_TIMEOUT=30000
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Authentication
|
|
16
17
|
JWT_SECRET=your-secret-key-here
|