create-backlist 6.1.5 → 6.1.7

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.
Files changed (36) hide show
  1. package/package.json +1 -1
  2. package/src/analyzer.js +410 -99
  3. package/src/generators/dotnet.js +1 -1
  4. package/src/generators/java.js +154 -97
  5. package/src/generators/node.js +213 -211
  6. package/src/templates/java-spring/partials/ApplicationSeeder.java.ejs +29 -7
  7. package/src/templates/java-spring/partials/AuthController.java.ejs +45 -14
  8. package/src/templates/java-spring/partials/Controller.java.ejs +25 -11
  9. package/src/templates/java-spring/partials/Dockerfile.ejs +25 -3
  10. package/src/templates/java-spring/partials/Entity.java.ejs +28 -3
  11. package/src/templates/java-spring/partials/JwtAuthFilter.java.ejs +41 -7
  12. package/src/templates/java-spring/partials/JwtService.java.ejs +47 -12
  13. package/src/templates/java-spring/partials/Repository.java.ejs +8 -1
  14. package/src/templates/java-spring/partials/Service.java.ejs +30 -6
  15. package/src/templates/java-spring/partials/User.java.ejs +26 -3
  16. package/src/templates/java-spring/partials/UserDetailsServiceImpl.java.ejs +10 -4
  17. package/src/templates/java-spring/partials/UserRepository.java.ejs +6 -0
  18. package/src/templates/java-spring/partials/docker-compose.yml.ejs +27 -5
  19. package/src/templates/node-ts-express/base/server.ts +63 -9
  20. package/src/templates/node-ts-express/base/tsconfig.json +19 -4
  21. package/src/templates/node-ts-express/partials/ApiDocs.ts.ejs +24 -9
  22. package/src/templates/node-ts-express/partials/App.test.ts.ejs +47 -27
  23. package/src/templates/node-ts-express/partials/Auth.controller.ts.ejs +68 -45
  24. package/src/templates/node-ts-express/partials/Auth.middleware.ts.ejs +45 -14
  25. package/src/templates/node-ts-express/partials/Auth.routes.ts.ejs +44 -5
  26. package/src/templates/node-ts-express/partials/Controller.ts.ejs +30 -16
  27. package/src/templates/node-ts-express/partials/Dockerfile.ejs +33 -11
  28. package/src/templates/node-ts-express/partials/Model.cs.ejs +38 -5
  29. package/src/templates/node-ts-express/partials/Model.ts.ejs +42 -12
  30. package/src/templates/node-ts-express/partials/PrismaController.ts.ejs +57 -23
  31. package/src/templates/node-ts-express/partials/PrismaSchema.prisma.ejs +33 -10
  32. package/src/templates/node-ts-express/partials/README.md.ejs +8 -10
  33. package/src/templates/node-ts-express/partials/Seeder.ts.ejs +99 -56
  34. package/src/templates/node-ts-express/partials/docker-compose.yml.ejs +30 -3
  35. package/src/templates/node-ts-express/partials/package.json.ejs +12 -7
  36. package/src/templates/node-ts-express/partials/routes.ts.ejs +31 -18
@@ -4,20 +4,25 @@
4
4
  "private": true,
5
5
  "main": "dist/server.js",
6
6
  "scripts": {
7
- "build": "tsc",
7
+ "clean": "rimraf dist",
8
+ "build": "npm run clean && tsc",
8
9
  "start": "node dist/server.js",
9
10
  "dev": "ts-node-dev --respawn --transpile-only src/server.ts"
10
11
  },
11
12
  "dependencies": {
12
13
  "cors": "^2.8.5",
13
- "dotenv": "^16.3.1",
14
- "express": "^4.18.2"
14
+ "dotenv": "^16.4.1",
15
+ "express": "^4.18.2",
16
+ "helmet": "^7.1.0",
17
+ "morgan": "^1.10.0"
15
18
  },
16
19
  "devDependencies": {
17
- "@types/cors": "^2.8.13",
18
- "@types/express": "^4.17.17",
19
- "@types/node": "^20.4.2",
20
+ "@types/cors": "^2.8.17",
21
+ "@types/express": "^4.17.21",
22
+ "@types/morgan": "^1.9.9",
23
+ "@types/node": "^20.11.0",
24
+ "rimraf": "^6.0.1",
20
25
  "ts-node-dev": "^2.0.0",
21
- "typescript": "^5.1.6"
26
+ "typescript": "^5.3.3"
22
27
  }
23
28
  }
@@ -1,16 +1,18 @@
1
1
  // Auto-generated by create-backlist on <%= new Date().toISOString() %>
2
2
  import { Router, Request, Response } from 'express';
3
- <%
4
- // Build unique controller list safely
3
+
4
+ <%
5
5
  const controllers = [];
6
6
  if (Array.isArray(endpoints)) {
7
7
  endpoints.forEach((ep) => {
8
- if (ep && ep.controllerName && ep.controllerName !== 'Default' && !controllers.includes(ep.controllerName)) {
9
- controllers.push(ep.controllerName);
10
- }
8
+ if (!ep) return;
9
+ const c = ep.controllerName;
10
+ if (!c || c === 'Default' || c === 'Auth') return;
11
+ if (!controllers.includes(c)) controllers.push(c);
11
12
  });
12
13
  }
13
14
  %>
15
+
14
16
  <% controllers.forEach((ctrl) => { %>
15
17
  import * as <%= ctrl %>Controller from './controllers/<%= ctrl %>.controller';
16
18
  <% }) %>
@@ -21,35 +23,46 @@ import { protect } from './middleware/Auth.middleware';
21
23
 
22
24
  const router = Router();
23
25
 
24
- // If no endpoints detected, emit a basic route so file is valid
25
26
  <% if (!Array.isArray(endpoints) || endpoints.length === 0) { %>
26
27
  router.get('/health', (_req: Request, res: Response) => {
27
28
  res.status(200).json({ ok: true, message: 'Auto-generated routes alive' });
28
29
  });
29
30
  <% } %>
30
31
 
31
- <%
32
+ <%
32
33
  if (Array.isArray(endpoints)) {
33
- endpoints.forEach((ep) => {
34
- const rawPath = (ep && ep.path) ? ep.path : '/';
35
- const expressPath = (rawPath.replace(/^\/api/, '') || '/').replace(/{(\w+)}/g, ':$1');
36
- const method = ((ep && ep.method) ? ep.method : 'GET').toLowerCase();
37
- const ctrl = (ep && ep.controllerName) ? ep.controllerName : 'Default';
34
+ endpoints.forEach((ep) => {
35
+ if (!ep) return;
36
+
37
+ const ctrl = ep.controllerName || 'Default';
38
+ if (ctrl === 'Default' || ctrl === 'Auth') return;
39
+
40
+ const raw = (ep.route || ep.path || '/');
41
+ const expressPath = String(raw).replace(/^\/api/, '').replace(/{(\w+)}/g, ':$1') || '/';
42
+
43
+ const method = String(ep.method || 'GET').toLowerCase();
44
+ const fnName = ep.functionName; // preferred if generator computed it
45
+
46
+ // fallback (if fnName not present)
38
47
  const hasId = expressPath.includes(':');
39
48
  let handler = '';
40
-
41
- if (ctrl !== 'Default') {
49
+ if (fnName) {
50
+ handler = `${ctrl}Controller.${fnName}`;
51
+ } else {
42
52
  if (method === 'post' && !hasId) handler = `${ctrl}Controller.create${ctrl}`;
43
53
  else if (method === 'get' && !hasId) handler = `${ctrl}Controller.getAll${ctrl}s`;
44
54
  else if (method === 'get' && hasId) handler = `${ctrl}Controller.get${ctrl}ById`;
45
- else if (method === 'put' && hasId) handler = `${ctrl}Controller.update${ctrl}ById`;
55
+ else if ((method === 'put' || method === 'patch') && hasId) handler = `${ctrl}Controller.update${ctrl}ById`;
46
56
  else if (method === 'delete' && hasId) handler = `${ctrl}Controller.delete${ctrl}ById`;
47
57
  }
48
58
 
49
- const needsProtect = !!addAuth && (method === 'post' || method === 'put' || method === 'delete');
50
- const middleware = needsProtect ? 'protect, ' : '';
59
+ const needsProtect = !!addAuth && (method === 'post' || method === 'put' || method === 'patch' || method === 'delete');
51
60
  %>
52
- router.<%= method %>('<%- expressPath || "/" %>', <%- middleware %><%- handler || '(req: Request, res: Response) => res.status(501).json({ message: "Not Implemented" })' %>);
61
+ router.<%= method %>(
62
+ '<%- expressPath %>',
63
+ <% if (needsProtect) { %>protect,<% } %>
64
+ <% if (handler) { %><%- handler %><% } else { %>(req: Request, res: Response) => res.status(501).json({ message: "Not Implemented" })<% } %>
65
+ );
53
66
  <%
54
67
  });
55
68
  }