create-charcole 2.0.4 → 2.2.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/CHANGELOG.md +290 -14
- package/README.md +258 -312
- package/bin/index.js +392 -55
- package/bin/lib/pkgManager.js +8 -25
- package/bin/lib/templateHandler.js +5 -42
- package/create-charcole-2.1.0.tgz +0 -0
- package/package.json +2 -2
- package/packages/swagger/BACKWARD_COMPATIBILITY.md +145 -0
- package/packages/swagger/CHANGELOG.md +404 -0
- package/packages/swagger/README.md +578 -0
- package/packages/swagger/charcole-swagger-1.0.0.tgz +0 -0
- package/packages/swagger/package-lock.json +1715 -0
- package/packages/swagger/package.json +44 -0
- package/packages/swagger/src/helpers.js +427 -0
- package/packages/swagger/src/index.d.ts +126 -0
- package/packages/swagger/src/index.js +12 -0
- package/packages/swagger/src/setup.js +100 -0
- package/template/js/.env.example +8 -0
- package/template/js/README.md +128 -5
- package/template/js/basePackage.json +11 -13
- package/template/js/src/app.js +8 -2
- package/template/js/src/config/swagger.config.js +15 -0
- package/template/js/src/lib/swagger/SWAGGER_GUIDE.md +561 -0
- package/template/js/src/modules/auth/auth.constants.js +3 -0
- package/template/js/src/modules/auth/auth.controller.js +29 -0
- package/template/js/src/modules/auth/auth.middlewares.js +19 -0
- package/template/js/src/modules/auth/auth.routes.js +131 -0
- package/template/js/src/modules/auth/auth.schemas.js +60 -0
- package/template/js/src/modules/auth/auth.service.js +67 -0
- package/template/js/src/modules/auth/package.json +6 -0
- package/template/js/src/modules/health/controller.js +104 -3
- package/template/js/src/modules/swagger/charcole-swagger-1.0.0.tgz +0 -0
- package/template/js/src/modules/swagger/package.json +5 -0
- package/template/js/src/repositories/user.repo.js +19 -0
- package/template/js/src/routes/index.js +25 -0
- package/template/js/src/routes/protected.js +57 -0
- package/template/ts/.env.example +8 -0
- package/template/ts/README.md +128 -5
- package/template/ts/basePackage.json +19 -15
- package/template/ts/build.js +46 -0
- package/template/ts/src/app.ts +12 -7
- package/template/ts/src/config/swagger.config.ts +30 -0
- package/template/ts/src/lib/swagger/SWAGGER_GUIDE.md +561 -0
- package/template/ts/src/middlewares/errorHandler.ts +15 -23
- package/template/ts/src/middlewares/requestLogger.ts +1 -1
- package/template/ts/src/middlewares/validateRequest.ts +1 -1
- package/template/ts/src/modules/auth/auth.constants.ts +6 -0
- package/template/ts/src/modules/auth/auth.controller.ts +32 -0
- package/template/ts/src/modules/auth/auth.middlewares.ts +46 -0
- package/template/ts/src/modules/auth/auth.routes.ts +52 -0
- package/template/ts/src/modules/auth/auth.schemas.ts +73 -0
- package/template/ts/src/modules/auth/auth.service.ts +106 -0
- package/template/ts/src/modules/auth/package.json +10 -0
- package/template/ts/src/modules/health/controller.ts +61 -45
- package/template/ts/src/modules/swagger/charcole-swagger-1.0.0.tgz +0 -0
- package/template/ts/src/modules/swagger/package.json +5 -0
- package/template/ts/src/repositories/user.repo.ts +33 -0
- package/template/ts/src/routes/index.ts +24 -0
- package/template/ts/src/routes/protected.ts +46 -0
- package/template/ts/src/server.ts +3 -4
- package/template/ts/src/utils/logger.ts +1 -1
- package/template/ts/tsconfig.json +14 -7
- package/tmpclaude-1049-cwd +1 -0
- package/tmpclaude-3e37-cwd +1 -0
- package/tmpclaude-4d73-cwd +1 -0
- package/tmpclaude-8a8e-cwd +1 -0
- package/template/js/ARCHITECTURE_DIAGRAMS.md +0 -283
- package/template/js/CHECKLIST.md +0 -279
- package/template/js/COMPLETE.md +0 -405
- package/template/js/ERROR_HANDLING.md +0 -393
- package/template/js/IMPLEMENTATION.md +0 -368
- package/template/js/IMPLEMENTATION_COMPLETE.md +0 -363
- package/template/js/INDEX.md +0 -290
- package/template/js/QUICK_REFERENCE.md +0 -270
- package/template/js/package.json +0 -28
- package/template/js/src/routes.js +0 -17
- package/template/js/test-api.js +0 -100
- package/template/ts/ARCHITECTURE_DIAGRAMS.md +0 -283
- package/template/ts/CHECKLIST.md +0 -279
- package/template/ts/COMPLETE.md +0 -405
- package/template/ts/ERROR_HANDLING.md +0 -393
- package/template/ts/IMPLEMENTATION.md +0 -368
- package/template/ts/IMPLEMENTATION_COMPLETE.md +0 -363
- package/template/ts/INDEX.md +0 -290
- package/template/ts/QUICK_REFERENCE.md +0 -270
- package/template/ts/package.json +0 -32
- package/template/ts/src/app.js +0 -75
- package/template/ts/src/config/constants.js +0 -20
- package/template/ts/src/config/env.js +0 -26
- package/template/ts/src/middlewares/errorHandler.js +0 -180
- package/template/ts/src/middlewares/requestLogger.js +0 -33
- package/template/ts/src/middlewares/validateRequest.js +0 -42
- package/template/ts/src/modules/health/controller.js +0 -50
- package/template/ts/src/routes.js +0 -17
- package/template/ts/src/routes.ts +0 -16
- package/template/ts/src/server.js +0 -38
- package/template/ts/src/utils/AppError.js +0 -182
- package/template/ts/src/utils/logger.js +0 -73
- package/template/ts/src/utils/response.js +0 -51
- package/template/ts/test-api.js +0 -100
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "charcole",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Production-grade Node.js Express API",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "dist/server.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"start": "node
|
|
8
|
-
"dev": "
|
|
9
|
-
"
|
|
10
|
-
"
|
|
8
|
+
"start": "node dist/server.js",
|
|
9
|
+
"dev": "tsx watch src/server.ts",
|
|
10
|
+
"build": "node build.js",
|
|
11
|
+
"clean": "rimraf dist",
|
|
12
|
+
"prebuild": "npm run clean",
|
|
13
|
+
"lint": "echo \"Add linting here\"",
|
|
14
|
+
"test": "echo \"Add tests here\""
|
|
11
15
|
},
|
|
12
16
|
"engines": {
|
|
13
17
|
"node": ">=18.0.0"
|
|
14
18
|
},
|
|
15
|
-
"keywords": [],
|
|
16
|
-
"author": "",
|
|
17
|
-
"license": "ISC",
|
|
18
|
-
"type": "module",
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"express": "^4.18.2",
|
|
20
21
|
"cors": "^2.8.5",
|
|
21
22
|
"dotenv": "^16.3.1",
|
|
22
|
-
"
|
|
23
|
-
"zod": "^3.22.4"
|
|
23
|
+
"zod": "^3.25.76"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"@types/cors": "^2.8.19",
|
|
26
27
|
"@types/express": "^4.17.21",
|
|
27
28
|
"@types/node": "^25.0.10",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
29
|
+
"esbuild": "^0.24.2",
|
|
30
|
+
"rimraf": "^6.0.1",
|
|
31
|
+
"tsc-alias": "^1.8.8",
|
|
32
|
+
"tsx": "^4.19.2",
|
|
30
33
|
"typescript": "^5.9.3"
|
|
31
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"license": "ISC"
|
|
32
36
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { build } from "esbuild";
|
|
2
|
+
import { glob } from "glob";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
|
|
6
|
+
const entryPoints = await glob("src/**/*.ts");
|
|
7
|
+
|
|
8
|
+
// Custom plugin to rewrite .ts imports to .js
|
|
9
|
+
const rewriteImportsPlugin = {
|
|
10
|
+
name: "rewrite-imports",
|
|
11
|
+
setup(build) {
|
|
12
|
+
build.onLoad({ filter: /\.ts$/ }, async (args) => {
|
|
13
|
+
const contents = await fs.promises.readFile(args.path, "utf8");
|
|
14
|
+
|
|
15
|
+
// Replace .ts extensions with .js in imports
|
|
16
|
+
const modifiedContents = contents
|
|
17
|
+
.replace(/from\s+['"]([^'"]+)\.ts['"]/g, 'from "$1.js"')
|
|
18
|
+
.replace(/import\s+['"]([^'"]+)\.ts['"]/g, 'import "$1.js"');
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
contents: modifiedContents,
|
|
22
|
+
loader: "ts",
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
await build({
|
|
29
|
+
entryPoints,
|
|
30
|
+
outdir: "dist",
|
|
31
|
+
bundle: false,
|
|
32
|
+
platform: "node",
|
|
33
|
+
format: "esm",
|
|
34
|
+
target: "es2020",
|
|
35
|
+
sourcemap: true,
|
|
36
|
+
outExtension: { ".js": ".js" },
|
|
37
|
+
packages: "external",
|
|
38
|
+
plugins: [rewriteImportsPlugin],
|
|
39
|
+
})
|
|
40
|
+
.then(() => {
|
|
41
|
+
console.log("✅ Build completed successfully!");
|
|
42
|
+
})
|
|
43
|
+
.catch((error) => {
|
|
44
|
+
console.error("❌ Build failed:", error);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
});
|
package/template/ts/src/app.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import express, { Request, Response, NextFunction } from "express";
|
|
2
2
|
import cors from "cors";
|
|
3
|
-
|
|
4
|
-
import { env } from "./config/env.
|
|
5
|
-
import { requestLogger } from "./middlewares/requestLogger.
|
|
3
|
+
import { userRepo } from "./repositories/user.repo.ts";
|
|
4
|
+
import { env } from "./config/env.ts";
|
|
5
|
+
import { requestLogger } from "./middlewares/requestLogger.ts";
|
|
6
6
|
import {
|
|
7
7
|
errorHandler,
|
|
8
8
|
asyncHandler,
|
|
9
9
|
NotFoundError,
|
|
10
|
-
} from "./middlewares/errorHandler.
|
|
11
|
-
import { sendSuccess } from "./utils/response.
|
|
12
|
-
import { logger } from "./utils/logger.
|
|
13
|
-
import routes from "./routes.
|
|
10
|
+
} from "./middlewares/errorHandler.ts";
|
|
11
|
+
import { sendSuccess } from "./utils/response.ts";
|
|
12
|
+
import { logger } from "./utils/logger.ts";
|
|
13
|
+
import routes from "./routes/index.ts";
|
|
14
|
+
import swaggerOptions from "./config/swagger.config.ts";
|
|
15
|
+
import { setupSwagger } from "@charcoles/swagger";
|
|
14
16
|
|
|
15
17
|
export const app = express();
|
|
16
18
|
|
|
@@ -36,6 +38,8 @@ app.use((req: Request, res: Response, next: NextFunction) => {
|
|
|
36
38
|
|
|
37
39
|
app.use(requestLogger);
|
|
38
40
|
|
|
41
|
+
setupSwagger(app, swaggerOptions);
|
|
42
|
+
|
|
39
43
|
app.use("/api", routes);
|
|
40
44
|
|
|
41
45
|
app.get(
|
|
@@ -64,3 +68,4 @@ app.use((req: Request) => {
|
|
|
64
68
|
app.use(errorHandler);
|
|
65
69
|
|
|
66
70
|
logger.info("Express app configured successfully");
|
|
71
|
+
app.locals.userRepo = userRepo;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { registerSchema, loginSchema } from "../modules/auth/auth.schemas.ts";
|
|
2
|
+
import { createItemSchema } from "../modules/health/controller.ts";
|
|
3
|
+
|
|
4
|
+
const swaggerConfig = {
|
|
5
|
+
title: process.env.APP_NAME || "Charcole API",
|
|
6
|
+
version: process.env.APP_VERSION || "1.0.0",
|
|
7
|
+
description: "Production-ready Node.js Express API",
|
|
8
|
+
path: "/api-docs",
|
|
9
|
+
servers: [
|
|
10
|
+
{
|
|
11
|
+
url: process.env.APP_URL || "http://localhost:3000",
|
|
12
|
+
description:
|
|
13
|
+
process.env.NODE_ENV === "production"
|
|
14
|
+
? "Production server"
|
|
15
|
+
: "Development server",
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
// NEW: Auto-register Zod schemas - no more manual duplication!
|
|
19
|
+
schemas: {
|
|
20
|
+
registerSchema,
|
|
21
|
+
loginSchema,
|
|
22
|
+
createItemSchema,
|
|
23
|
+
},
|
|
24
|
+
// Common response templates are included by default
|
|
25
|
+
includeCommonResponses: true,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type SwaggerConfig = typeof swaggerConfig;
|
|
29
|
+
|
|
30
|
+
export default swaggerConfig;
|