nestjs-ddd-cli 2.2.0 → 3.2.1

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 (254) hide show
  1. package/README.md +247 -408
  2. package/ddd.schema.json +111 -0
  3. package/dist/commands/aggregate-validator.d.ts +9 -0
  4. package/dist/commands/aggregate-validator.js +953 -0
  5. package/dist/commands/aggregate-validator.js.map +1 -0
  6. package/dist/commands/ai-assist.d.ts +8 -0
  7. package/dist/commands/ai-assist.js +337 -0
  8. package/dist/commands/ai-assist.js.map +1 -0
  9. package/dist/commands/api-contracts.d.ts +9 -0
  10. package/dist/commands/api-contracts.js +1368 -0
  11. package/dist/commands/api-contracts.js.map +1 -0
  12. package/dist/commands/api-docs.d.ts +8 -0
  13. package/dist/commands/api-docs.js +408 -0
  14. package/dist/commands/api-docs.js.map +1 -0
  15. package/dist/commands/api-versioning.d.ts +11 -0
  16. package/dist/commands/api-versioning.js +643 -0
  17. package/dist/commands/api-versioning.js.map +1 -0
  18. package/dist/commands/audit-logging.d.ts +9 -0
  19. package/dist/commands/audit-logging.js +1129 -0
  20. package/dist/commands/audit-logging.js.map +1 -0
  21. package/dist/commands/batch-generate.d.ts +10 -0
  22. package/dist/commands/batch-generate.js +405 -0
  23. package/dist/commands/batch-generate.js.map +1 -0
  24. package/dist/commands/caching-strategies.d.ts +9 -0
  25. package/dist/commands/caching-strategies.js +874 -0
  26. package/dist/commands/caching-strategies.js.map +1 -0
  27. package/dist/commands/code-analyzer.d.ts +42 -0
  28. package/dist/commands/code-analyzer.js +474 -0
  29. package/dist/commands/code-analyzer.js.map +1 -0
  30. package/dist/commands/database-seeding.d.ts +6 -0
  31. package/dist/commands/database-seeding.js +621 -0
  32. package/dist/commands/database-seeding.js.map +1 -0
  33. package/dist/commands/db-optimization.d.ts +7 -0
  34. package/dist/commands/db-optimization.js +687 -0
  35. package/dist/commands/db-optimization.js.map +1 -0
  36. package/dist/commands/dependency-graph.d.ts +6 -0
  37. package/dist/commands/dependency-graph.js +329 -0
  38. package/dist/commands/dependency-graph.js.map +1 -0
  39. package/dist/commands/doctor-enhanced.d.ts +22 -0
  40. package/dist/commands/doctor-enhanced.js +543 -0
  41. package/dist/commands/doctor-enhanced.js.map +1 -0
  42. package/dist/commands/doctor.d.ts +4 -0
  43. package/dist/commands/doctor.js +151 -0
  44. package/dist/commands/doctor.js.map +1 -0
  45. package/dist/commands/env-manager.d.ts +6 -0
  46. package/dist/commands/env-manager.js +419 -0
  47. package/dist/commands/env-manager.js.map +1 -0
  48. package/dist/commands/event-sourcing-full.d.ts +10 -0
  49. package/dist/commands/event-sourcing-full.js +1107 -0
  50. package/dist/commands/event-sourcing-full.js.map +1 -0
  51. package/dist/commands/feature-flags.d.ts +9 -0
  52. package/dist/commands/feature-flags.js +824 -0
  53. package/dist/commands/feature-flags.js.map +1 -0
  54. package/dist/commands/filter-dsl.d.ts +10 -0
  55. package/dist/commands/filter-dsl.js +1407 -0
  56. package/dist/commands/filter-dsl.js.map +1 -0
  57. package/dist/commands/generate-all.js +485 -32
  58. package/dist/commands/generate-all.js.map +1 -1
  59. package/dist/commands/generate-deployment.d.ts +8 -0
  60. package/dist/commands/generate-deployment.js +746 -0
  61. package/dist/commands/generate-deployment.js.map +1 -0
  62. package/dist/commands/generate-domain-service.d.ts +14 -0
  63. package/dist/commands/generate-domain-service.js +796 -0
  64. package/dist/commands/generate-domain-service.js.map +1 -0
  65. package/dist/commands/generate-entity.js +82 -24
  66. package/dist/commands/generate-entity.js.map +1 -1
  67. package/dist/commands/generate-from-schema.d.ts +56 -0
  68. package/dist/commands/generate-from-schema.js +222 -0
  69. package/dist/commands/generate-from-schema.js.map +1 -0
  70. package/dist/commands/generate-orchestrator.d.ts +14 -0
  71. package/dist/commands/generate-orchestrator.js +887 -0
  72. package/dist/commands/generate-orchestrator.js.map +1 -0
  73. package/dist/commands/generate-repository.d.ts +14 -0
  74. package/dist/commands/generate-repository.js +1019 -0
  75. package/dist/commands/generate-repository.js.map +1 -0
  76. package/dist/commands/generate-shared.d.ts +4 -0
  77. package/dist/commands/generate-shared.js +388 -0
  78. package/dist/commands/generate-shared.js.map +1 -0
  79. package/dist/commands/generate-value-object.d.ts +32 -0
  80. package/dist/commands/generate-value-object.js +700 -0
  81. package/dist/commands/generate-value-object.js.map +1 -0
  82. package/dist/commands/graphql-subscriptions.d.ts +6 -0
  83. package/dist/commands/graphql-subscriptions.js +607 -0
  84. package/dist/commands/graphql-subscriptions.js.map +1 -0
  85. package/dist/commands/graphql-types.d.ts +5 -0
  86. package/dist/commands/graphql-types.js +423 -0
  87. package/dist/commands/graphql-types.js.map +1 -0
  88. package/dist/commands/health-probes-advanced.d.ts +6 -0
  89. package/dist/commands/health-probes-advanced.js +655 -0
  90. package/dist/commands/health-probes-advanced.js.map +1 -0
  91. package/dist/commands/i18n-setup.d.ts +10 -0
  92. package/dist/commands/i18n-setup.js +677 -0
  93. package/dist/commands/i18n-setup.js.map +1 -0
  94. package/dist/commands/init-config.d.ts +6 -0
  95. package/dist/commands/init-config.js +370 -0
  96. package/dist/commands/init-config.js.map +1 -0
  97. package/dist/commands/init-project.js +56 -6
  98. package/dist/commands/init-project.js.map +1 -1
  99. package/dist/commands/interactive-scaffold.d.ts +5 -0
  100. package/dist/commands/interactive-scaffold.js +271 -0
  101. package/dist/commands/interactive-scaffold.js.map +1 -0
  102. package/dist/commands/metrics-prometheus.d.ts +6 -0
  103. package/dist/commands/metrics-prometheus.js +681 -0
  104. package/dist/commands/metrics-prometheus.js.map +1 -0
  105. package/dist/commands/migration-engine.d.ts +6 -0
  106. package/dist/commands/migration-engine.js +446 -0
  107. package/dist/commands/migration-engine.js.map +1 -0
  108. package/dist/commands/migration.d.ts +12 -0
  109. package/dist/commands/migration.js +484 -0
  110. package/dist/commands/migration.js.map +1 -0
  111. package/dist/commands/monorepo.d.ts +8 -0
  112. package/dist/commands/monorepo.js +483 -0
  113. package/dist/commands/monorepo.js.map +1 -0
  114. package/dist/commands/multi-database.d.ts +5 -0
  115. package/dist/commands/multi-database.js +439 -0
  116. package/dist/commands/multi-database.js.map +1 -0
  117. package/dist/commands/observability-tracing.d.ts +10 -0
  118. package/dist/commands/observability-tracing.js +740 -0
  119. package/dist/commands/observability-tracing.js.map +1 -0
  120. package/dist/commands/openapi-export.d.ts +8 -0
  121. package/dist/commands/openapi-export.js +359 -0
  122. package/dist/commands/openapi-export.js.map +1 -0
  123. package/dist/commands/perf-analyzer.d.ts +8 -0
  124. package/dist/commands/perf-analyzer.js +423 -0
  125. package/dist/commands/perf-analyzer.js.map +1 -0
  126. package/dist/commands/rate-limiting.d.ts +10 -0
  127. package/dist/commands/rate-limiting.js +953 -0
  128. package/dist/commands/rate-limiting.js.map +1 -0
  129. package/dist/commands/recipe-plugin.d.ts +56 -0
  130. package/dist/commands/recipe-plugin.js +315 -0
  131. package/dist/commands/recipe-plugin.js.map +1 -0
  132. package/dist/commands/recipe.d.ts +6 -0
  133. package/dist/commands/recipe.js +3941 -0
  134. package/dist/commands/recipe.js.map +1 -0
  135. package/dist/commands/recipes/elasticsearch.recipe.d.ts +1 -0
  136. package/dist/commands/recipes/elasticsearch.recipe.js +761 -0
  137. package/dist/commands/recipes/elasticsearch.recipe.js.map +1 -0
  138. package/dist/commands/recipes/event-sourcing.recipe.d.ts +1 -0
  139. package/dist/commands/recipes/event-sourcing.recipe.js +889 -0
  140. package/dist/commands/recipes/event-sourcing.recipe.js.map +1 -0
  141. package/dist/commands/recipes/index.d.ts +7 -0
  142. package/dist/commands/recipes/index.js +24 -0
  143. package/dist/commands/recipes/index.js.map +1 -0
  144. package/dist/commands/recipes/message-queue.recipe.d.ts +1 -0
  145. package/dist/commands/recipes/message-queue.recipe.js +706 -0
  146. package/dist/commands/recipes/message-queue.recipe.js.map +1 -0
  147. package/dist/commands/recipes/middleware.recipe.d.ts +1 -0
  148. package/dist/commands/recipes/middleware.recipe.js +383 -0
  149. package/dist/commands/recipes/middleware.recipe.js.map +1 -0
  150. package/dist/commands/recipes/multi-tenancy.recipe.d.ts +1 -0
  151. package/dist/commands/recipes/multi-tenancy.recipe.js +520 -0
  152. package/dist/commands/recipes/multi-tenancy.recipe.js.map +1 -0
  153. package/dist/commands/recipes/oauth2.recipe.d.ts +1 -0
  154. package/dist/commands/recipes/oauth2.recipe.js +472 -0
  155. package/dist/commands/recipes/oauth2.recipe.js.map +1 -0
  156. package/dist/commands/recipes/websocket.recipe.d.ts +1 -0
  157. package/dist/commands/recipes/websocket.recipe.js +453 -0
  158. package/dist/commands/recipes/websocket.recipe.js.map +1 -0
  159. package/dist/commands/resilience-patterns.d.ts +13 -0
  160. package/dist/commands/resilience-patterns.js +1029 -0
  161. package/dist/commands/resilience-patterns.js.map +1 -0
  162. package/dist/commands/security-patterns.d.ts +11 -0
  163. package/dist/commands/security-patterns.js +2233 -0
  164. package/dist/commands/security-patterns.js.map +1 -0
  165. package/dist/commands/template-debug.d.ts +27 -0
  166. package/dist/commands/template-debug.js +388 -0
  167. package/dist/commands/template-debug.js.map +1 -0
  168. package/dist/commands/test-factory-full.d.ts +9 -0
  169. package/dist/commands/test-factory-full.js +1570 -0
  170. package/dist/commands/test-factory-full.js.map +1 -0
  171. package/dist/commands/test-scaffold.d.ts +7 -0
  172. package/dist/commands/test-scaffold.js +621 -0
  173. package/dist/commands/test-scaffold.js.map +1 -0
  174. package/dist/index.js +1088 -0
  175. package/dist/index.js.map +1 -1
  176. package/dist/templates/ai-context/CLAUDE.md.hbs +158 -0
  177. package/dist/templates/ai-context/conventions.md.hbs +154 -0
  178. package/dist/templates/command/create-command.hbs +6 -14
  179. package/dist/templates/command/delete-command.hbs +19 -0
  180. package/dist/templates/command/update-command.hbs +24 -0
  181. package/dist/templates/controller/controller.hbs +64 -17
  182. package/dist/templates/dto/create-dto.hbs +29 -5
  183. package/dist/templates/dto/filter-dto.hbs +52 -0
  184. package/dist/templates/dto/filter-query.dto.hbs +148 -0
  185. package/dist/templates/dto/paginated-response.dto.hbs +29 -0
  186. package/dist/templates/dto/pagination-query.dto.hbs +30 -0
  187. package/dist/templates/dto/response-dto.hbs +38 -0
  188. package/dist/templates/dto/update-dto.hbs +11 -0
  189. package/dist/templates/entity/entity.hbs +32 -1
  190. package/dist/templates/event/domain-event.hbs +33 -7
  191. package/dist/templates/event/event-handler.hbs +40 -0
  192. package/dist/templates/exception/base-exceptions.hbs +69 -0
  193. package/dist/templates/exception/entity-not-found.exception.hbs +7 -0
  194. package/dist/templates/mapper/mapper.hbs +49 -24
  195. package/dist/templates/module/module.hbs +34 -10
  196. package/dist/templates/orm-entity/orm-entity.hbs +63 -12
  197. package/dist/templates/prisma/prisma-mapper.hbs +71 -0
  198. package/dist/templates/prisma/prisma-repository.hbs +114 -0
  199. package/dist/templates/prisma/prisma-schema.hbs +20 -0
  200. package/dist/templates/prisma/prisma-service.hbs +51 -0
  201. package/dist/templates/query/get-all.query.hbs +50 -0
  202. package/dist/templates/query/get-by-id.query.hbs +31 -0
  203. package/dist/templates/repository/repository.hbs +55 -13
  204. package/dist/templates/resolver/graphql-input.hbs +54 -0
  205. package/dist/templates/resolver/graphql-type.hbs +58 -0
  206. package/dist/templates/resolver/pagination-args.hbs +33 -0
  207. package/dist/templates/resolver/resolver.hbs +62 -0
  208. package/dist/templates/shared/prisma-query-builder.util.hbs +189 -0
  209. package/dist/templates/shared/query-builder.util.hbs +218 -0
  210. package/dist/templates/test/controller.spec.hbs +124 -0
  211. package/dist/templates/test/repository.spec.hbs +158 -0
  212. package/dist/templates/test/usecase.spec.hbs +116 -0
  213. package/dist/templates/usecase/create-usecase.hbs +19 -7
  214. package/dist/templates/usecase/delete-usecase.hbs +17 -0
  215. package/dist/templates/usecase/update-usecase.hbs +31 -0
  216. package/dist/utils/config.utils.d.ts +45 -0
  217. package/dist/utils/config.utils.js +211 -0
  218. package/dist/utils/config.utils.js.map +1 -0
  219. package/dist/utils/error.utils.d.ts +145 -0
  220. package/dist/utils/error.utils.js +422 -0
  221. package/dist/utils/error.utils.js.map +1 -0
  222. package/dist/utils/field.utils.d.ts +54 -0
  223. package/dist/utils/field.utils.js +389 -0
  224. package/dist/utils/field.utils.js.map +1 -0
  225. package/dist/utils/file.utils.d.ts +19 -8
  226. package/dist/utils/file.utils.js +135 -4
  227. package/dist/utils/file.utils.js.map +1 -1
  228. package/dist/utils/idempotency.utils.d.ts +123 -0
  229. package/dist/utils/idempotency.utils.js +444 -0
  230. package/dist/utils/idempotency.utils.js.map +1 -0
  231. package/dist/utils/naming.utils.js +26 -3
  232. package/dist/utils/naming.utils.js.map +1 -1
  233. package/dist/utils/performance.utils.d.ts +37 -0
  234. package/dist/utils/performance.utils.js +158 -0
  235. package/dist/utils/performance.utils.js.map +1 -0
  236. package/dist/utils/relation.utils.d.ts +92 -0
  237. package/dist/utils/relation.utils.js +388 -0
  238. package/dist/utils/relation.utils.js.map +1 -0
  239. package/dist/utils/rollback.utils.d.ts +49 -0
  240. package/dist/utils/rollback.utils.js +306 -0
  241. package/dist/utils/rollback.utils.js.map +1 -0
  242. package/dist/utils/schema.utils.d.ts +123 -0
  243. package/dist/utils/schema.utils.js +419 -0
  244. package/dist/utils/schema.utils.js.map +1 -0
  245. package/dist/utils/security.utils.d.ts +57 -0
  246. package/dist/utils/security.utils.js +315 -0
  247. package/dist/utils/security.utils.js.map +1 -0
  248. package/dist/utils/template-engine.utils.d.ts +80 -0
  249. package/dist/utils/template-engine.utils.js +463 -0
  250. package/dist/utils/template-engine.utils.js.map +1 -0
  251. package/dist/utils/validation-registry.utils.d.ts +160 -0
  252. package/dist/utils/validation-registry.utils.js +526 -0
  253. package/dist/utils/validation-registry.utils.js.map +1 -0
  254. package/package.json +3 -1
@@ -0,0 +1,746 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.generateDeployment = generateDeployment;
40
+ const path = __importStar(require("path"));
41
+ const chalk_1 = __importDefault(require("chalk"));
42
+ const file_utils_1 = require("../utils/file.utils");
43
+ async function generateDeployment(options) {
44
+ console.log(chalk_1.default.blue('\n🚀 Generating deployment configurations...\n'));
45
+ const basePath = options.path || process.cwd();
46
+ // Generate Dockerfile
47
+ if (options.docker !== false) {
48
+ await generateDockerfile(basePath);
49
+ }
50
+ // Generate docker-compose
51
+ if (options.compose !== false) {
52
+ await generateDockerCompose(basePath);
53
+ }
54
+ // Generate CI/CD pipeline
55
+ if (options.ci && options.ci !== 'none') {
56
+ await generateCIPipeline(basePath, options.ci);
57
+ }
58
+ // Generate Kubernetes manifests
59
+ if (options.kubernetes) {
60
+ await generateKubernetesManifests(basePath);
61
+ }
62
+ // Generate .dockerignore
63
+ await generateDockerIgnore(basePath);
64
+ // Generate .env.example
65
+ await generateEnvExample(basePath);
66
+ console.log(chalk_1.default.green('\n✅ Deployment configurations generated successfully!'));
67
+ console.log(chalk_1.default.yellow('\n📋 Next steps:'));
68
+ console.log(' 1. Review and customize the generated files');
69
+ console.log(' 2. Update environment variables in .env');
70
+ console.log(` 3. Build: ${chalk_1.default.cyan('docker build -t my-app .')}`);
71
+ console.log(` 4. Run: ${chalk_1.default.cyan('docker-compose up -d')}`);
72
+ }
73
+ async function generateDockerfile(basePath) {
74
+ const dockerfilePath = path.join(basePath, 'Dockerfile');
75
+ if (await (0, file_utils_1.fileExists)(dockerfilePath)) {
76
+ console.log(chalk_1.default.yellow(' Dockerfile already exists. Skipping...'));
77
+ return;
78
+ }
79
+ const content = `# Stage 1: Build
80
+ FROM node:20-alpine AS builder
81
+
82
+ WORKDIR /app
83
+
84
+ # Copy package files
85
+ COPY package*.json ./
86
+ COPY tsconfig*.json ./
87
+
88
+ # Install dependencies
89
+ RUN npm ci
90
+
91
+ # Copy source code
92
+ COPY src ./src
93
+ COPY prisma ./prisma 2>/dev/null || true
94
+
95
+ # Generate Prisma client if prisma folder exists
96
+ RUN if [ -d "prisma" ]; then npx prisma generate; fi
97
+
98
+ # Build the application
99
+ RUN npm run build
100
+
101
+ # Remove dev dependencies
102
+ RUN npm prune --production
103
+
104
+ # Stage 2: Production
105
+ FROM node:20-alpine AS production
106
+
107
+ WORKDIR /app
108
+
109
+ # Add non-root user for security
110
+ RUN addgroup -g 1001 -S nodejs && \\
111
+ adduser -S nestjs -u 1001
112
+
113
+ # Copy built assets from builder
114
+ COPY --from=builder --chown=nestjs:nodejs /app/node_modules ./node_modules
115
+ COPY --from=builder --chown=nestjs:nodejs /app/dist ./dist
116
+ COPY --from=builder --chown=nestjs:nodejs /app/package*.json ./
117
+
118
+ # Copy Prisma files if they exist
119
+ COPY --from=builder --chown=nestjs:nodejs /app/prisma ./prisma 2>/dev/null || true
120
+
121
+ # Set environment variables
122
+ ENV NODE_ENV=production
123
+ ENV PORT=3000
124
+
125
+ # Expose port
126
+ EXPOSE 3000
127
+
128
+ # Switch to non-root user
129
+ USER nestjs
130
+
131
+ # Health check
132
+ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \\
133
+ CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
134
+
135
+ # Start the application
136
+ CMD ["node", "dist/main"]
137
+ `;
138
+ await (0, file_utils_1.writeFile)(dockerfilePath, content);
139
+ console.log(chalk_1.default.green(' ✓ Dockerfile'));
140
+ }
141
+ async function generateDockerCompose(basePath) {
142
+ const composePath = path.join(basePath, 'docker-compose.yml');
143
+ if (await (0, file_utils_1.fileExists)(composePath)) {
144
+ console.log(chalk_1.default.yellow(' docker-compose.yml already exists. Skipping...'));
145
+ return;
146
+ }
147
+ const content = `version: "3.8"
148
+
149
+ services:
150
+ app:
151
+ build:
152
+ context: .
153
+ dockerfile: Dockerfile
154
+ container_name: nestjs-app
155
+ restart: unless-stopped
156
+ ports:
157
+ - "\${PORT:-3000}:3000"
158
+ environment:
159
+ - NODE_ENV=production
160
+ - DATABASE_URL=\${DATABASE_URL}
161
+ - JWT_SECRET=\${JWT_SECRET}
162
+ - REDIS_URL=redis://redis:6379
163
+ depends_on:
164
+ - postgres
165
+ - redis
166
+ networks:
167
+ - app-network
168
+ healthcheck:
169
+ test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/health"]
170
+ interval: 30s
171
+ timeout: 10s
172
+ retries: 3
173
+ start_period: 40s
174
+
175
+ postgres:
176
+ image: postgres:15-alpine
177
+ container_name: postgres
178
+ restart: unless-stopped
179
+ environment:
180
+ - POSTGRES_USER=\${DB_USER:-postgres}
181
+ - POSTGRES_PASSWORD=\${DB_PASSWORD:-postgres}
182
+ - POSTGRES_DB=\${DB_NAME:-nestjs_db}
183
+ volumes:
184
+ - postgres_data:/var/lib/postgresql/data
185
+ ports:
186
+ - "\${DB_PORT:-5432}:5432"
187
+ networks:
188
+ - app-network
189
+ healthcheck:
190
+ test: ["CMD-SHELL", "pg_isready -U postgres"]
191
+ interval: 10s
192
+ timeout: 5s
193
+ retries: 5
194
+
195
+ redis:
196
+ image: redis:7-alpine
197
+ container_name: redis
198
+ restart: unless-stopped
199
+ command: redis-server --appendonly yes
200
+ volumes:
201
+ - redis_data:/data
202
+ ports:
203
+ - "\${REDIS_PORT:-6379}:6379"
204
+ networks:
205
+ - app-network
206
+ healthcheck:
207
+ test: ["CMD", "redis-cli", "ping"]
208
+ interval: 10s
209
+ timeout: 5s
210
+ retries: 5
211
+
212
+ # Optional: pgAdmin for database management
213
+ pgadmin:
214
+ image: dpage/pgadmin4:latest
215
+ container_name: pgadmin
216
+ restart: unless-stopped
217
+ environment:
218
+ - PGADMIN_DEFAULT_EMAIL=\${PGADMIN_EMAIL:-admin@admin.com}
219
+ - PGADMIN_DEFAULT_PASSWORD=\${PGADMIN_PASSWORD:-admin}
220
+ ports:
221
+ - "\${PGADMIN_PORT:-5050}:80"
222
+ depends_on:
223
+ - postgres
224
+ networks:
225
+ - app-network
226
+ profiles:
227
+ - tools
228
+
229
+ volumes:
230
+ postgres_data:
231
+ redis_data:
232
+
233
+ networks:
234
+ app-network:
235
+ driver: bridge
236
+ `;
237
+ await (0, file_utils_1.writeFile)(composePath, content);
238
+ console.log(chalk_1.default.green(' ✓ docker-compose.yml'));
239
+ }
240
+ async function generateCIPipeline(basePath, ciType) {
241
+ if (ciType === 'github') {
242
+ await generateGitHubActions(basePath);
243
+ }
244
+ else if (ciType === 'gitlab') {
245
+ await generateGitLabCI(basePath);
246
+ }
247
+ }
248
+ async function generateGitHubActions(basePath) {
249
+ const workflowsPath = path.join(basePath, '.github/workflows');
250
+ await (0, file_utils_1.ensureDir)(workflowsPath);
251
+ // CI Pipeline
252
+ const ciContent = `name: CI
253
+
254
+ on:
255
+ push:
256
+ branches: [main, develop]
257
+ pull_request:
258
+ branches: [main, develop]
259
+
260
+ jobs:
261
+ test:
262
+ runs-on: ubuntu-latest
263
+
264
+ services:
265
+ postgres:
266
+ image: postgres:15-alpine
267
+ env:
268
+ POSTGRES_USER: postgres
269
+ POSTGRES_PASSWORD: postgres
270
+ POSTGRES_DB: test_db
271
+ ports:
272
+ - 5432:5432
273
+ options: >-
274
+ --health-cmd pg_isready
275
+ --health-interval 10s
276
+ --health-timeout 5s
277
+ --health-retries 5
278
+
279
+ redis:
280
+ image: redis:7-alpine
281
+ ports:
282
+ - 6379:6379
283
+ options: >-
284
+ --health-cmd "redis-cli ping"
285
+ --health-interval 10s
286
+ --health-timeout 5s
287
+ --health-retries 5
288
+
289
+ steps:
290
+ - name: Checkout code
291
+ uses: actions/checkout@v4
292
+
293
+ - name: Setup Node.js
294
+ uses: actions/setup-node@v4
295
+ with:
296
+ node-version: "20"
297
+ cache: "npm"
298
+
299
+ - name: Install dependencies
300
+ run: npm ci
301
+
302
+ - name: Run linter
303
+ run: npm run lint
304
+
305
+ - name: Run type check
306
+ run: npm run typecheck
307
+
308
+ - name: Run tests
309
+ run: npm test -- --coverage
310
+ env:
311
+ DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test_db
312
+ REDIS_URL: redis://localhost:6379
313
+ JWT_SECRET: test-secret
314
+
315
+ - name: Upload coverage
316
+ uses: codecov/codecov-action@v3
317
+ with:
318
+ files: ./coverage/lcov.info
319
+ fail_ci_if_error: false
320
+
321
+ build:
322
+ needs: test
323
+ runs-on: ubuntu-latest
324
+
325
+ steps:
326
+ - name: Checkout code
327
+ uses: actions/checkout@v4
328
+
329
+ - name: Setup Node.js
330
+ uses: actions/setup-node@v4
331
+ with:
332
+ node-version: "20"
333
+ cache: "npm"
334
+
335
+ - name: Install dependencies
336
+ run: npm ci
337
+
338
+ - name: Build application
339
+ run: npm run build
340
+
341
+ - name: Upload build artifacts
342
+ uses: actions/upload-artifact@v4
343
+ with:
344
+ name: dist
345
+ path: dist/
346
+ `;
347
+ await (0, file_utils_1.writeFile)(path.join(workflowsPath, 'ci.yml'), ciContent);
348
+ console.log(chalk_1.default.green(' ✓ .github/workflows/ci.yml'));
349
+ // CD Pipeline
350
+ const cdContent = `name: CD
351
+
352
+ on:
353
+ push:
354
+ branches: [main]
355
+ tags:
356
+ - "v*"
357
+
358
+ env:
359
+ REGISTRY: ghcr.io
360
+ IMAGE_NAME: \${{ github.repository }}
361
+
362
+ jobs:
363
+ build-and-push:
364
+ runs-on: ubuntu-latest
365
+ permissions:
366
+ contents: read
367
+ packages: write
368
+
369
+ steps:
370
+ - name: Checkout code
371
+ uses: actions/checkout@v4
372
+
373
+ - name: Set up Docker Buildx
374
+ uses: docker/setup-buildx-action@v3
375
+
376
+ - name: Log in to Container Registry
377
+ uses: docker/login-action@v3
378
+ with:
379
+ registry: \${{ env.REGISTRY }}
380
+ username: \${{ github.actor }}
381
+ password: \${{ secrets.GITHUB_TOKEN }}
382
+
383
+ - name: Extract metadata
384
+ id: meta
385
+ uses: docker/metadata-action@v5
386
+ with:
387
+ images: \${{ env.REGISTRY }}/\${{ env.IMAGE_NAME }}
388
+ tags: |
389
+ type=ref,event=branch
390
+ type=ref,event=pr
391
+ type=semver,pattern={{version}}
392
+ type=semver,pattern={{major}}.{{minor}}
393
+ type=sha
394
+
395
+ - name: Build and push Docker image
396
+ uses: docker/build-push-action@v5
397
+ with:
398
+ context: .
399
+ push: true
400
+ tags: \${{ steps.meta.outputs.tags }}
401
+ labels: \${{ steps.meta.outputs.labels }}
402
+ cache-from: type=gha
403
+ cache-to: type=gha,mode=max
404
+ `;
405
+ await (0, file_utils_1.writeFile)(path.join(workflowsPath, 'cd.yml'), cdContent);
406
+ console.log(chalk_1.default.green(' ✓ .github/workflows/cd.yml'));
407
+ }
408
+ async function generateGitLabCI(basePath) {
409
+ const gitlabCIPath = path.join(basePath, '.gitlab-ci.yml');
410
+ if (await (0, file_utils_1.fileExists)(gitlabCIPath)) {
411
+ console.log(chalk_1.default.yellow(' .gitlab-ci.yml already exists. Skipping...'));
412
+ return;
413
+ }
414
+ const content = `stages:
415
+ - test
416
+ - build
417
+ - deploy
418
+
419
+ variables:
420
+ DOCKER_DRIVER: overlay2
421
+ DOCKER_TLS_CERTDIR: ""
422
+
423
+ .node_template: &node_template
424
+ image: node:20-alpine
425
+ cache:
426
+ key: \${CI_COMMIT_REF_SLUG}
427
+ paths:
428
+ - node_modules/
429
+
430
+ test:
431
+ <<: *node_template
432
+ stage: test
433
+ services:
434
+ - postgres:15-alpine
435
+ - redis:7-alpine
436
+ variables:
437
+ POSTGRES_DB: test_db
438
+ POSTGRES_USER: postgres
439
+ POSTGRES_PASSWORD: postgres
440
+ DATABASE_URL: postgresql://postgres:postgres@postgres:5432/test_db
441
+ REDIS_URL: redis://redis:6379
442
+ JWT_SECRET: test-secret
443
+ script:
444
+ - npm ci
445
+ - npm run lint
446
+ - npm run typecheck
447
+ - npm test -- --coverage
448
+ coverage: /All files[^|]*\\|[^|]*\\s+([\\d\\.]+)/
449
+ artifacts:
450
+ reports:
451
+ coverage_report:
452
+ coverage_format: cobertura
453
+ path: coverage/cobertura-coverage.xml
454
+
455
+ build:
456
+ <<: *node_template
457
+ stage: build
458
+ script:
459
+ - npm ci
460
+ - npm run build
461
+ artifacts:
462
+ paths:
463
+ - dist/
464
+ expire_in: 1 week
465
+ only:
466
+ - main
467
+ - develop
468
+
469
+ docker:
470
+ stage: build
471
+ image: docker:24-dind
472
+ services:
473
+ - docker:24-dind
474
+ before_script:
475
+ - docker login -u \$CI_REGISTRY_USER -p \$CI_REGISTRY_PASSWORD \$CI_REGISTRY
476
+ script:
477
+ - docker build -t \$CI_REGISTRY_IMAGE:\$CI_COMMIT_SHA .
478
+ - docker push \$CI_REGISTRY_IMAGE:\$CI_COMMIT_SHA
479
+ - |
480
+ if [ "\$CI_COMMIT_BRANCH" == "main" ]; then
481
+ docker tag \$CI_REGISTRY_IMAGE:\$CI_COMMIT_SHA \$CI_REGISTRY_IMAGE:latest
482
+ docker push \$CI_REGISTRY_IMAGE:latest
483
+ fi
484
+ only:
485
+ - main
486
+ - tags
487
+ `;
488
+ await (0, file_utils_1.writeFile)(gitlabCIPath, content);
489
+ console.log(chalk_1.default.green(' ✓ .gitlab-ci.yml'));
490
+ }
491
+ async function generateKubernetesManifests(basePath) {
492
+ const k8sPath = path.join(basePath, 'k8s');
493
+ await (0, file_utils_1.ensureDir)(k8sPath);
494
+ // Deployment
495
+ const deploymentContent = `apiVersion: apps/v1
496
+ kind: Deployment
497
+ metadata:
498
+ name: nestjs-app
499
+ labels:
500
+ app: nestjs-app
501
+ spec:
502
+ replicas: 3
503
+ selector:
504
+ matchLabels:
505
+ app: nestjs-app
506
+ template:
507
+ metadata:
508
+ labels:
509
+ app: nestjs-app
510
+ spec:
511
+ containers:
512
+ - name: nestjs-app
513
+ image: your-registry/nestjs-app:latest
514
+ ports:
515
+ - containerPort: 3000
516
+ envFrom:
517
+ - configMapRef:
518
+ name: nestjs-app-config
519
+ - secretRef:
520
+ name: nestjs-app-secrets
521
+ resources:
522
+ requests:
523
+ memory: "256Mi"
524
+ cpu: "250m"
525
+ limits:
526
+ memory: "512Mi"
527
+ cpu: "500m"
528
+ livenessProbe:
529
+ httpGet:
530
+ path: /health
531
+ port: 3000
532
+ initialDelaySeconds: 30
533
+ periodSeconds: 10
534
+ readinessProbe:
535
+ httpGet:
536
+ path: /health
537
+ port: 3000
538
+ initialDelaySeconds: 5
539
+ periodSeconds: 5
540
+ `;
541
+ await (0, file_utils_1.writeFile)(path.join(k8sPath, 'deployment.yaml'), deploymentContent);
542
+ // Service
543
+ const serviceContent = `apiVersion: v1
544
+ kind: Service
545
+ metadata:
546
+ name: nestjs-app
547
+ spec:
548
+ selector:
549
+ app: nestjs-app
550
+ ports:
551
+ - protocol: TCP
552
+ port: 80
553
+ targetPort: 3000
554
+ type: ClusterIP
555
+ `;
556
+ await (0, file_utils_1.writeFile)(path.join(k8sPath, 'service.yaml'), serviceContent);
557
+ // ConfigMap
558
+ const configMapContent = `apiVersion: v1
559
+ kind: ConfigMap
560
+ metadata:
561
+ name: nestjs-app-config
562
+ data:
563
+ NODE_ENV: "production"
564
+ PORT: "3000"
565
+ `;
566
+ await (0, file_utils_1.writeFile)(path.join(k8sPath, 'configmap.yaml'), configMapContent);
567
+ // Ingress
568
+ const ingressContent = `apiVersion: networking.k8s.io/v1
569
+ kind: Ingress
570
+ metadata:
571
+ name: nestjs-app
572
+ annotations:
573
+ kubernetes.io/ingress.class: nginx
574
+ cert-manager.io/cluster-issuer: letsencrypt-prod
575
+ spec:
576
+ tls:
577
+ - hosts:
578
+ - api.example.com
579
+ secretName: nestjs-app-tls
580
+ rules:
581
+ - host: api.example.com
582
+ http:
583
+ paths:
584
+ - path: /
585
+ pathType: Prefix
586
+ backend:
587
+ service:
588
+ name: nestjs-app
589
+ port:
590
+ number: 80
591
+ `;
592
+ await (0, file_utils_1.writeFile)(path.join(k8sPath, 'ingress.yaml'), ingressContent);
593
+ // HPA
594
+ const hpaContent = `apiVersion: autoscaling/v2
595
+ kind: HorizontalPodAutoscaler
596
+ metadata:
597
+ name: nestjs-app
598
+ spec:
599
+ scaleTargetRef:
600
+ apiVersion: apps/v1
601
+ kind: Deployment
602
+ name: nestjs-app
603
+ minReplicas: 2
604
+ maxReplicas: 10
605
+ metrics:
606
+ - type: Resource
607
+ resource:
608
+ name: cpu
609
+ target:
610
+ type: Utilization
611
+ averageUtilization: 70
612
+ - type: Resource
613
+ resource:
614
+ name: memory
615
+ target:
616
+ type: Utilization
617
+ averageUtilization: 80
618
+ `;
619
+ await (0, file_utils_1.writeFile)(path.join(k8sPath, 'hpa.yaml'), hpaContent);
620
+ console.log(chalk_1.default.green(' ✓ k8s/deployment.yaml'));
621
+ console.log(chalk_1.default.green(' ✓ k8s/service.yaml'));
622
+ console.log(chalk_1.default.green(' ✓ k8s/configmap.yaml'));
623
+ console.log(chalk_1.default.green(' ✓ k8s/ingress.yaml'));
624
+ console.log(chalk_1.default.green(' ✓ k8s/hpa.yaml'));
625
+ }
626
+ async function generateDockerIgnore(basePath) {
627
+ const dockerignorePath = path.join(basePath, '.dockerignore');
628
+ if (await (0, file_utils_1.fileExists)(dockerignorePath)) {
629
+ console.log(chalk_1.default.yellow(' .dockerignore already exists. Skipping...'));
630
+ return;
631
+ }
632
+ const content = `# Dependencies
633
+ node_modules
634
+ npm-debug.log
635
+
636
+ # Build outputs
637
+ dist
638
+
639
+ # Environment files
640
+ .env
641
+ .env.*
642
+ !.env.example
643
+
644
+ # IDE
645
+ .idea
646
+ .vscode
647
+ *.swp
648
+ *.swo
649
+
650
+ # OS
651
+ .DS_Store
652
+ Thumbs.db
653
+
654
+ # Testing
655
+ coverage
656
+ .nyc_output
657
+
658
+ # Docker
659
+ Dockerfile*
660
+ docker-compose*
661
+ .docker
662
+
663
+ # Git
664
+ .git
665
+ .gitignore
666
+
667
+ # Documentation
668
+ *.md
669
+ docs
670
+
671
+ # Misc
672
+ *.log
673
+ tmp
674
+ temp
675
+ `;
676
+ await (0, file_utils_1.writeFile)(dockerignorePath, content);
677
+ console.log(chalk_1.default.green(' ✓ .dockerignore'));
678
+ }
679
+ async function generateEnvExample(basePath) {
680
+ const envExamplePath = path.join(basePath, '.env.example');
681
+ if (await (0, file_utils_1.fileExists)(envExamplePath)) {
682
+ console.log(chalk_1.default.yellow(' .env.example already exists. Skipping...'));
683
+ return;
684
+ }
685
+ const content = `# Application
686
+ NODE_ENV=development
687
+ PORT=3000
688
+ API_PREFIX=api
689
+ API_VERSION=v1
690
+
691
+ # Database
692
+ DATABASE_URL=postgresql://postgres:postgres@localhost:5432/nestjs_db
693
+ DB_HOST=localhost
694
+ DB_PORT=5432
695
+ DB_USER=postgres
696
+ DB_PASSWORD=postgres
697
+ DB_NAME=nestjs_db
698
+
699
+ # Redis
700
+ REDIS_URL=redis://localhost:6379
701
+ REDIS_HOST=localhost
702
+ REDIS_PORT=6379
703
+
704
+ # JWT
705
+ JWT_SECRET=your-super-secret-jwt-key-change-in-production
706
+ JWT_EXPIRES_IN=7d
707
+
708
+ # CORS
709
+ CORS_ORIGIN=http://localhost:3000
710
+
711
+ # Rate Limiting
712
+ THROTTLE_TTL=60
713
+ THROTTLE_LIMIT=100
714
+
715
+ # File Upload
716
+ STORAGE_TYPE=local
717
+ UPLOAD_DIR=./uploads
718
+ UPLOAD_BASE_URL=http://localhost:3000/uploads
719
+ MAX_FILE_SIZE=10485760
720
+
721
+ # AWS (if using S3)
722
+ AWS_REGION=us-east-1
723
+ AWS_ACCESS_KEY_ID=
724
+ AWS_SECRET_ACCESS_KEY=
725
+ AWS_S3_BUCKET=
726
+
727
+ # Email (SMTP)
728
+ SMTP_HOST=smtp.example.com
729
+ SMTP_PORT=587
730
+ SMTP_SECURE=false
731
+ SMTP_USER=
732
+ SMTP_PASS=
733
+ SMTP_FROM=noreply@example.com
734
+
735
+ # Logging
736
+ LOG_LEVEL=debug
737
+
738
+ # Docker (for docker-compose)
739
+ PGADMIN_EMAIL=admin@admin.com
740
+ PGADMIN_PASSWORD=admin
741
+ PGADMIN_PORT=5050
742
+ `;
743
+ await (0, file_utils_1.writeFile)(envExamplePath, content);
744
+ console.log(chalk_1.default.green(' ✓ .env.example'));
745
+ }
746
+ //# sourceMappingURL=generate-deployment.js.map