@tsed/cli 6.6.3 → 7.0.0-alpha.10

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 (259) hide show
  1. package/lib/esm/bin/tsed.js +23 -2
  2. package/lib/esm/commands/add/AddCmd.js +16 -16
  3. package/lib/esm/commands/generate/GenerateCmd.js +72 -224
  4. package/lib/esm/commands/generate/mappers/mapGenerateContext.js +29 -0
  5. package/lib/esm/commands/index.js +2 -1
  6. package/lib/esm/commands/init/InitCmd.js +193 -172
  7. package/lib/esm/commands/init/config/FeaturesPrompt.js +106 -9
  8. package/lib/esm/commands/init/mappers/mapToContext.js +8 -3
  9. package/lib/esm/commands/init/prompts/getFeaturesPrompt.js +0 -12
  10. package/lib/esm/commands/init/utils/hasFeature.js +3 -0
  11. package/lib/esm/commands/run/RunCmd.js +22 -26
  12. package/lib/esm/commands/template/CreateTemplateCommand.js +101 -0
  13. package/lib/esm/commands/update/UpdateCmd.js +9 -13
  14. package/lib/esm/fn/exec.js +5 -0
  15. package/lib/esm/fn/render.js +5 -0
  16. package/lib/esm/fn/taskOutput.js +7 -0
  17. package/lib/esm/index.js +10 -5
  18. package/lib/esm/interfaces/AlterPackageJson.js +1 -0
  19. package/lib/esm/interfaces/AlterProjectFiles.js +1 -0
  20. package/lib/esm/interfaces/AlterRenderFiles.js +1 -0
  21. package/lib/esm/interfaces/CliCommandHooks.js +1 -0
  22. package/lib/esm/interfaces/GenerateCmdContext.js +1 -0
  23. package/lib/esm/interfaces/InitCmdOptions.js +1 -0
  24. package/lib/esm/interfaces/RenderDataContext.js +1 -0
  25. package/lib/esm/interfaces/RuntimeTypes.js +1 -0
  26. package/lib/esm/interfaces/index.js +9 -0
  27. package/lib/esm/pipes/OutputFilePathPipe.js +40 -18
  28. package/lib/esm/pipes/RoutePipe.js +4 -8
  29. package/lib/esm/pipes/{ClassNamePipe.js → SymbolNamePipe.js} +14 -11
  30. package/lib/esm/pipes/index.js +1 -1
  31. package/lib/esm/platforms/{InitPlatformsModule.js → PlatformsModule.js} +4 -10
  32. package/lib/esm/platforms/supports/InitExpressPlatform.js +27 -10
  33. package/lib/esm/platforms/supports/InitFastifyPlatform.js +27 -10
  34. package/lib/esm/platforms/supports/InitKoaPlatform.js +16 -10
  35. package/lib/esm/processors/__fixtures__/createFakeProject.js +35 -0
  36. package/lib/esm/processors/transformBinFile.js +47 -0
  37. package/lib/esm/processors/transformConfigFile.js +105 -0
  38. package/lib/esm/processors/transformIndexFile.js +23 -0
  39. package/lib/esm/processors/transformServerFile.js +60 -0
  40. package/lib/esm/runtimes/RuntimesModule.js +7 -17
  41. package/lib/esm/runtimes/supports/BabelRuntime.js +5 -11
  42. package/lib/esm/runtimes/supports/BunRuntime.js +4 -10
  43. package/lib/esm/runtimes/supports/NodeRuntime.js +1 -1
  44. package/lib/esm/runtimes/supports/WebpackRuntime.js +1 -1
  45. package/lib/esm/services/CliProjectService.js +95 -0
  46. package/lib/esm/services/CliRunScript.js +4 -8
  47. package/lib/esm/services/CliTemplatesService.js +119 -0
  48. package/lib/esm/services/ProjectClient.js +162 -0
  49. package/lib/esm/services/mappers/addContextMethods.js +17 -0
  50. package/lib/esm/services/mappers/mapDefaultTemplateOptions.js +36 -0
  51. package/lib/esm/templates/asyncFactory.template.js +38 -0
  52. package/lib/esm/templates/barrels.template.js +27 -0
  53. package/lib/esm/templates/command.template.js +56 -0
  54. package/lib/esm/templates/config.template.js +27 -0
  55. package/lib/esm/templates/controller.template.js +44 -0
  56. package/lib/esm/templates/decorator.template.js +184 -0
  57. package/lib/esm/templates/docker-compose.template.js +25 -0
  58. package/lib/esm/templates/dockerfile.template.js +236 -0
  59. package/lib/esm/templates/exception-filter.template.js +19 -0
  60. package/lib/esm/templates/factory.template.js +37 -0
  61. package/lib/esm/templates/index.command.template.js +22 -0
  62. package/lib/esm/templates/index.config.utils.template.js +17 -0
  63. package/{templates/init/src/controllers/pages/IndexController.ts.hbs → lib/esm/templates/index.controller.template.js} +14 -3
  64. package/lib/esm/templates/index.js +32 -0
  65. package/lib/esm/templates/index.logger.template.js +41 -0
  66. package/{templates/init/src/index.ts.hbs → lib/esm/templates/index.template.js} +17 -5
  67. package/lib/esm/templates/interceptor.template.js +31 -0
  68. package/lib/esm/templates/interface.template.js +13 -0
  69. package/lib/esm/templates/middleware.template.js +36 -0
  70. package/lib/esm/templates/model.template.js +16 -0
  71. package/lib/esm/templates/module.template.js +16 -0
  72. package/lib/esm/templates/new-template.template.js +67 -0
  73. package/lib/esm/templates/pipe.template.js +19 -0
  74. package/lib/esm/templates/pm2.template.js +111 -0
  75. package/lib/esm/templates/prisma.service.template.js +23 -0
  76. package/{templates/init/README.md.hbs → lib/esm/templates/readme.template.js} +28 -13
  77. package/lib/esm/templates/repository.template.js +16 -0
  78. package/lib/esm/templates/response-filter.template.js +19 -0
  79. package/lib/esm/templates/server.template.js +37 -0
  80. package/lib/esm/templates/service.template.js +16 -0
  81. package/lib/esm/templates/tsconfig.spec.template.js +35 -0
  82. package/lib/esm/templates/value.template.js +13 -0
  83. package/lib/esm/utils/defineTemplate.js +13 -0
  84. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  85. package/lib/types/bin/tsed.d.ts +1 -1
  86. package/lib/types/commands/add/AddCmd.d.ts +2 -2
  87. package/lib/types/commands/generate/GenerateCmd.d.ts +9 -98
  88. package/lib/types/commands/generate/mappers/mapGenerateContext.d.ts +2 -0
  89. package/lib/types/commands/index.d.ts +2 -1
  90. package/lib/types/commands/init/InitCmd.d.ts +18 -20
  91. package/lib/types/commands/init/config/FeaturesPrompt.d.ts +19 -3
  92. package/lib/types/commands/init/mappers/mapToContext.d.ts +2 -2
  93. package/lib/types/commands/init/mappers/mapUniqFeatures.d.ts +1 -1
  94. package/lib/types/commands/init/prompts/getFeaturesPrompt.d.ts +1 -7
  95. package/lib/types/commands/init/utils/hasFeature.d.ts +1 -0
  96. package/lib/types/commands/template/CreateTemplateCommand.d.ts +62 -0
  97. package/lib/types/commands/update/UpdateCmd.d.ts +2 -2
  98. package/lib/types/fn/exec.d.ts +1 -0
  99. package/lib/types/fn/render.d.ts +2 -0
  100. package/lib/types/fn/taskOutput.d.ts +1 -0
  101. package/lib/types/index.d.ts +10 -5
  102. package/lib/types/interfaces/AlterGenerateTasks.d.ts +5 -0
  103. package/lib/types/interfaces/AlterInitSubTasks.d.ts +5 -0
  104. package/lib/types/interfaces/AlterPackageJson.d.ts +5 -0
  105. package/lib/types/interfaces/AlterProjectFiles.d.ts +5 -0
  106. package/lib/types/interfaces/AlterRenderFiles.d.ts +10 -0
  107. package/lib/types/interfaces/CliCommandHooks.d.ts +11 -0
  108. package/lib/types/interfaces/GenerateCmdContext.d.ts +21 -0
  109. package/lib/types/interfaces/InitCmdOptions.d.ts +8 -0
  110. package/lib/types/interfaces/PlatformType.d.ts +7 -0
  111. package/lib/types/interfaces/RenderDataContext.d.ts +62 -0
  112. package/lib/types/interfaces/RuntimeTypes.d.ts +8 -0
  113. package/lib/types/interfaces/index.d.ts +9 -0
  114. package/lib/types/pipes/OutputFilePathPipe.d.ts +7 -4
  115. package/lib/types/pipes/{ClassNamePipe.d.ts → SymbolNamePipe.d.ts} +4 -4
  116. package/lib/types/pipes/index.d.ts +1 -1
  117. package/lib/types/platforms/{InitPlatformsModule.d.ts → PlatformsModule.d.ts} +1 -1
  118. package/lib/types/platforms/supports/InitBasePlatform.d.ts +3 -0
  119. package/lib/types/platforms/supports/InitExpressPlatform.d.ts +2 -0
  120. package/lib/types/platforms/supports/InitFastifyPlatform.d.ts +2 -0
  121. package/lib/types/platforms/supports/InitKoaPlatform.d.ts +2 -0
  122. package/lib/types/processors/__fixtures__/createFakeProject.d.ts +5 -0
  123. package/lib/types/processors/transformBinFile.d.ts +3 -0
  124. package/lib/types/processors/transformConfigFile.d.ts +3 -0
  125. package/lib/types/processors/transformIndexFile.d.ts +3 -0
  126. package/lib/types/processors/transformServerFile.d.ts +3 -0
  127. package/lib/types/runtimes/RuntimesModule.d.ts +5 -5
  128. package/lib/types/services/CliProjectService.d.ts +16 -0
  129. package/lib/types/services/CliTemplatesService.d.ts +35 -0
  130. package/lib/types/services/ProjectClient.d.ts +40 -0
  131. package/lib/types/services/mappers/addContextMethods.d.ts +12 -0
  132. package/lib/types/services/mappers/mapDefaultTemplateOptions.d.ts +11 -0
  133. package/lib/types/templates/asyncFactory.template.d.ts +16 -0
  134. package/lib/types/templates/barrels.template.d.ts +16 -0
  135. package/lib/types/templates/command.template.d.ts +16 -0
  136. package/lib/types/templates/config.template.d.ts +16 -0
  137. package/lib/types/templates/controller.template.d.ts +17 -0
  138. package/lib/types/templates/decorator.template.d.ts +17 -0
  139. package/lib/types/templates/docker-compose.template.d.ts +16 -0
  140. package/lib/types/templates/dockerfile.template.d.ts +1 -0
  141. package/lib/types/templates/exception-filter.template.d.ts +16 -0
  142. package/lib/types/templates/factory.template.d.ts +16 -0
  143. package/lib/types/templates/index.command.template.d.ts +16 -0
  144. package/lib/types/templates/index.config.utils.template.d.ts +16 -0
  145. package/lib/types/templates/index.controller.template.d.ts +16 -0
  146. package/lib/types/templates/index.d.ts +31 -0
  147. package/lib/types/templates/index.logger.template.d.ts +16 -0
  148. package/lib/types/templates/index.template.d.ts +16 -0
  149. package/lib/types/templates/interceptor.template.d.ts +16 -0
  150. package/lib/types/templates/interface.template.d.ts +16 -0
  151. package/lib/types/templates/middleware.template.d.ts +17 -0
  152. package/lib/types/templates/model.template.d.ts +16 -0
  153. package/lib/types/templates/module.template.d.ts +16 -0
  154. package/lib/types/templates/new-template.template.d.ts +9 -0
  155. package/lib/types/templates/pipe.template.d.ts +16 -0
  156. package/lib/types/templates/pm2.template.d.ts +1 -0
  157. package/lib/types/templates/prisma.service.template.d.ts +16 -0
  158. package/lib/types/templates/readme.template.d.ts +16 -0
  159. package/lib/types/templates/repository.template.d.ts +16 -0
  160. package/lib/types/templates/response-filter.template.d.ts +16 -0
  161. package/lib/types/templates/server.template.d.ts +16 -0
  162. package/lib/types/templates/service.template.d.ts +16 -0
  163. package/lib/types/templates/tsconfig.spec.template.d.ts +16 -0
  164. package/lib/types/templates/value.template.d.ts +16 -0
  165. package/lib/types/utils/defineTemplate.d.ts +67 -0
  166. package/package.json +14 -12
  167. package/templates/{init/tsconfig.json.hbs → tsconfig.json} +2 -7
  168. package/templates/tsconfig.node.json +14 -0
  169. package/templates/webpack.config.js +55 -0
  170. package/lib/esm/Cli.js +0 -57
  171. package/lib/esm/commands/generate/ProviderTypes.js +0 -103
  172. package/lib/esm/commands/init/interfaces/InitOptions.js +0 -5
  173. package/lib/esm/services/ProvidersInfoService.js +0 -46
  174. package/lib/esm/services/Renderer.js +0 -162
  175. package/lib/esm/utils/fillImports.js +0 -38
  176. package/lib/esm/utils/hbs/array.js +0 -515
  177. package/lib/esm/utils/hbs/collection.js +0 -60
  178. package/lib/esm/utils/hbs/comparison.js +0 -431
  179. package/lib/esm/utils/hbs/index.js +0 -11
  180. package/lib/esm/utils/hbs/object.js +0 -236
  181. package/lib/esm/utils/hbs/switch.js +0 -10
  182. package/lib/esm/utils/renderer/insertAfter.js +0 -12
  183. package/lib/esm/utils/renderer/insertImport.js +0 -11
  184. package/lib/types/Cli.d.ts +0 -26
  185. package/lib/types/commands/generate/ProviderTypes.d.ts +0 -11
  186. package/lib/types/commands/init/interfaces/InitCmdContext.d.ts +0 -6
  187. package/lib/types/commands/init/interfaces/InitOptions.d.ts +0 -20
  188. package/lib/types/services/ProvidersInfoService.d.ts +0 -21
  189. package/lib/types/services/Renderer.d.ts +0 -44
  190. package/lib/types/utils/fillImports.d.ts +0 -1
  191. package/lib/types/utils/hbs/array.d.ts +0 -1
  192. package/lib/types/utils/hbs/collection.d.ts +0 -1
  193. package/lib/types/utils/hbs/comparison.d.ts +0 -1
  194. package/lib/types/utils/hbs/object.d.ts +0 -1
  195. package/lib/types/utils/hbs/switch.d.ts +0 -1
  196. package/lib/types/utils/renderer/insertAfter.d.ts +0 -1
  197. package/lib/types/utils/renderer/insertImport.d.ts +0 -1
  198. package/templates/generate/async.factory.hbs +0 -35
  199. package/templates/generate/command.hbs +0 -45
  200. package/templates/generate/controller.hbs +0 -10
  201. package/templates/generate/decorator.class.hbs +0 -14
  202. package/templates/generate/decorator.endpoint.hbs +0 -15
  203. package/templates/generate/decorator.generic.hbs +0 -19
  204. package/templates/generate/decorator.method.hbs +0 -16
  205. package/templates/generate/decorator.middleware.hbs +0 -26
  206. package/templates/generate/decorator.param.hbs +0 -15
  207. package/templates/generate/decorator.parameters.hbs +0 -9
  208. package/templates/generate/decorator.prop.hbs +0 -14
  209. package/templates/generate/decorator.property.hbs +0 -5
  210. package/templates/generate/exception-filter.hbs +0 -9
  211. package/templates/generate/factory.hbs +0 -11
  212. package/templates/generate/injectable.hbs +0 -6
  213. package/templates/generate/interceptor.hbs +0 -21
  214. package/templates/generate/interface.hbs +0 -3
  215. package/templates/generate/middleware.hbs +0 -9
  216. package/templates/generate/model.hbs +0 -6
  217. package/templates/generate/module.hbs +0 -6
  218. package/templates/generate/pipe.hbs +0 -9
  219. package/templates/generate/prisma.service.hbs +0 -13
  220. package/templates/generate/repository.hbs +0 -6
  221. package/templates/generate/response-filter.hbs +0 -9
  222. package/templates/generate/server/_partials/server-footer.hbs +0 -10
  223. package/templates/generate/server/_partials/server-header.hbs +0 -34
  224. package/templates/generate/server/express/server.hbs +0 -10
  225. package/templates/generate/server/fastify/server.hbs +0 -14
  226. package/templates/generate/server/koa/server.hbs +0 -8
  227. package/templates/generate/service.hbs +0 -6
  228. package/templates/generate/value.hbs +0 -3
  229. package/templates/init/.barrels.json.hbs +0 -9
  230. package/templates/init/.gitignore.hbs +0 -57
  231. package/templates/init/.npmrc.hbs +0 -2
  232. package/templates/init/docker/_partials/docker-body.hbs +0 -5
  233. package/templates/init/docker/_partials/docker-dev-tools.hbs +0 -2
  234. package/templates/init/docker/_partials/docker-header.hbs +0 -16
  235. package/templates/init/docker/bun/Dockerfile.hbs +0 -36
  236. package/templates/init/docker/npm/Dockerfile.hbs +0 -28
  237. package/templates/init/docker/pnpm/Dockerfile.hbs +0 -28
  238. package/templates/init/docker/yarn/Dockerfile.hbs +0 -28
  239. package/templates/init/docker/yarn_berry/Dockerfile.hbs +0 -31
  240. package/templates/init/docker-compose.yml.hbs +0 -14
  241. package/templates/init/pm2/bun/processes.config.cjs.hbs +0 -23
  242. package/templates/init/pm2/node-compiled/processes.config.cjs.hbs +0 -22
  243. package/templates/init/pm2/node-loader/processes.config.cjs.hbs +0 -24
  244. package/templates/init/src/bin/index.ts.hbs +0 -9
  245. package/templates/init/src/config/envs/index.ts.hbs +0 -7
  246. package/templates/init/src/config/index.ts.hbs +0 -38
  247. package/templates/init/src/config/logger/index.ts.hbs +0 -25
  248. package/templates/init/tsconfig.node.json.hbs +0 -20
  249. package/templates/init/tsconfig.spec.json.hbs +0 -25
  250. package/templates/init/webpack.config.js.hbs +0 -65
  251. /package/lib/esm/{commands/init/interfaces/InitCmdContext.js → interfaces/AlterGenerateTasks.js} +0 -0
  252. /package/lib/{types/utils/hbs/index.d.ts → esm/interfaces/AlterInitSubTasks.js} +0 -0
  253. /package/templates/{init/.babelrc.hbs → .babelrc} +0 -0
  254. /package/templates/{init/.dockerignore.hbs → .dockerignore} +0 -0
  255. /package/templates/{init/.swcrc.hbs → .swcrc} +0 -0
  256. /package/templates/{init/.yarnrc.hbs → .yarnrc} +0 -0
  257. /package/templates/{init/nodemon.json.hbs → nodemon.json} +0 -0
  258. /package/templates/{init/tsconfig.base.json.hbs → tsconfig.base.json} +0 -0
  259. /package/templates/{init/views/swagger.ejs.hbs → views/swagger.ejs} +0 -0
@@ -0,0 +1,236 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ function dockerHeader() {
3
+ return `###############################################################################
4
+ ###############################################################################
5
+ ## _______ _____ ______ _____ ##
6
+ ## |__ __/ ____| ____| __ \\ ##
7
+ ## | | | (___ | |__ | | | | ##
8
+ ## | | \\___ \\| __| | | | | ##
9
+ ## | | ____) | |____| |__| | ##
10
+ ## |_| |_____/|______|_____/ ##
11
+ ## ##
12
+ ## description : Dockerfile for TsED Application ##
13
+ ## author : TsED team ##
14
+ ## date : 2023-12-11 ##
15
+ ## version : 3.0 ##
16
+ ## ##
17
+ ###############################################################################
18
+ ###############################################################################
19
+ `;
20
+ }
21
+ function dockerDevTools() {
22
+ return `RUN apk update && apk add build-base git curl
23
+ RUN npm install -g pm2
24
+ `;
25
+ }
26
+ function dockerBody() {
27
+ return `COPY . .
28
+
29
+ EXPOSE 8081
30
+ ENV PORT 8081
31
+ ENV NODE_ENV production`;
32
+ }
33
+ defineTemplate({
34
+ id: "dockerfile.yarn",
35
+ label: "Dockerfile (Yarn classic)",
36
+ fileName: "Dockerfile",
37
+ outputDir: ".",
38
+ ext: null,
39
+ preserveCase: true,
40
+ render() {
41
+ return `${dockerHeader()}
42
+
43
+ ARG NODE_VERSION=20.11.0
44
+
45
+ FROM node:\${NODE_VERSION}-alpine AS build
46
+ WORKDIR /opt
47
+
48
+ COPY package.json yarn.lock tsconfig.json tsconfig.base.json tsconfig.node.json tsconfig.spec.json .barrels.json .swcrc ./
49
+
50
+ RUN yarn install --pure-lockfile
51
+
52
+ COPY ./src ./src
53
+
54
+ RUN yarn build
55
+
56
+ FROM node:\${NODE_VERSION}-alpine AS runtime
57
+ ENV WORKDIR /opt
58
+ WORKDIR $WORKDIR
59
+
60
+ ${dockerDevTools()}
61
+
62
+ COPY --from=build /opt .
63
+
64
+ RUN yarn install --pure-lockfile --production
65
+
66
+ ${dockerBody()}
67
+
68
+ CMD ["pm2-runtime", "start", "processes.config.cjs", "--env", "production"]
69
+ `;
70
+ }
71
+ });
72
+ defineTemplate({
73
+ id: "dockerfile.yarn_berry",
74
+ label: "Dockerfile (Yarn Berry)",
75
+ fileName: "Dockerfile",
76
+ outputDir: ".",
77
+ ext: null,
78
+ preserveCase: true,
79
+ render() {
80
+ return `${dockerHeader()}
81
+
82
+ ARG NODE_VERSION=20.11.0
83
+
84
+ FROM node:\${NODE_VERSION}-alpine AS build
85
+ WORKDIR /opt
86
+
87
+ COPY package.json yarn.lock tsconfig.json tsconfig.base.json tsconfig.node.json tsconfig.spec.json .barrels.json .swcrc ./
88
+
89
+ RUN yarn set version berry
90
+ RUN yarn install --immutable
91
+
92
+ COPY ./src ./src
93
+
94
+ RUN yarn build
95
+
96
+ FROM node:\${NODE_VERSION}-alpine AS runtime
97
+ ENV WORKDIR /opt
98
+ WORKDIR $WORKDIR
99
+
100
+ ${dockerDevTools()}
101
+
102
+ COPY --from=build /opt .
103
+
104
+ RUN yarn set version berry
105
+ RUN yarn install --immutable
106
+ ## RUN yarn workspaces focus --all --production
107
+
108
+ ${dockerBody()}
109
+
110
+ CMD ["pm2-runtime", "start", "processes.config.cjs", "--env", "production"]
111
+ `;
112
+ }
113
+ });
114
+ defineTemplate({
115
+ id: "dockerfile.npm",
116
+ label: "Dockerfile (NPM)",
117
+ fileName: "Dockerfile",
118
+ outputDir: ".",
119
+ ext: null,
120
+ preserveCase: true,
121
+ render() {
122
+ return `${dockerHeader()}
123
+
124
+ ARG NODE_VERSION=20.11.0
125
+
126
+ FROM node:\${NODE_VERSION}-alpine AS build
127
+ WORKDIR /opt
128
+
129
+ COPY package.json package-lock.json tsconfig.json tsconfig.base.json tsconfig.node.json tsconfig.spec.json .barrels.json .swcrc ./
130
+
131
+ RUN npm ci
132
+
133
+ COPY ./src ./src
134
+
135
+ RUN npm run build
136
+
137
+ FROM node:\${NODE_VERSION}-alpine AS runtime
138
+ ENV WORKDIR /opt
139
+ WORKDIR $WORKDIR
140
+
141
+ ${dockerDevTools()}
142
+
143
+ COPY --from=build /opt .
144
+
145
+ RUN npm ci --omit=dev --ignore-scripts
146
+
147
+ ${dockerBody()}
148
+
149
+ CMD ["pm2-runtime", "start", "processes.config.cjs", "--env", "production"]`;
150
+ }
151
+ });
152
+ defineTemplate({
153
+ id: "dockerfile.pnpm",
154
+ label: "Dockerfile (PNPM)",
155
+ fileName: "Dockerfile",
156
+ outputDir: ".",
157
+ ext: null,
158
+ preserveCase: true,
159
+ render() {
160
+ return `${dockerHeader()}
161
+
162
+ ARG NODE_VERSION=20.11.0
163
+
164
+ FROM node:\${NODE_VERSION}-alpine AS build
165
+ WORKDIR /opt
166
+
167
+ COPY package.json pnpm-lock.yaml tsconfig.json tsconfig.base.json tsconfig.node.json tsconfig.spec.json .barrels.json .swcrc ./
168
+
169
+ RUN pnpm install --frozen-lockfile
170
+
171
+ COPY ./src ./src
172
+
173
+ RUN pnpm run build
174
+
175
+ FROM node:\${NODE_VERSION}-alpine AS runtime
176
+ ENV WORKDIR /opt
177
+ WORKDIR $WORKDIR
178
+
179
+ ${dockerDevTools()}
180
+
181
+ COPY --from=build /opt .
182
+
183
+ RUN pnpm install --frozen-lockfile --prod
184
+
185
+ ${dockerBody()}
186
+
187
+ CMD ["pm2-runtime", "start", "processes.config.cjs", "--env", "production"]
188
+ `;
189
+ }
190
+ });
191
+ defineTemplate({
192
+ id: "dockerfile.bun",
193
+ label: "Dockerfile (Bun)",
194
+ fileName: "Dockerfile",
195
+ outputDir: ".",
196
+ ext: null,
197
+ preserveCase: true,
198
+ render() {
199
+ return `
200
+ ARG BUN_VERSION=1
201
+
202
+ FROM oven/bun:\${BUN_VERSION} AS base
203
+ WORKDIR /opt
204
+
205
+ FROM base AS install
206
+ RUN mkdir -p /temp/dev
207
+ COPY package.json bun.lockb /temp/dev/
208
+ RUN cd /temp/dev && bun install --frozen-lockfile
209
+
210
+ # install with --production (exclude devDependencies)
211
+ RUN mkdir -p /temp/prod
212
+ COPY package.json bun.lockb /temp/prod/
213
+ RUN cd /temp/prod && bun install --frozen-lockfile --production
214
+
215
+ # copy node_modules from temp directory
216
+ # then copy all (non-ignored) project files into the image
217
+ FROM base AS prerelease
218
+ COPY --from=install /temp/dev/node_modules node_modules
219
+ COPY . .
220
+
221
+ RUN bun run build
222
+
223
+ # copy production dependencies and source code into final image
224
+ FROM base AS release
225
+ COPY --from=install /temp/prod/node_modules node_modules
226
+ COPY --from=prerelease /opt/dist/index.js .
227
+ COPY --from=prerelease /opt/package.json .
228
+
229
+ USER bun
230
+
231
+ ${dockerBody()}
232
+
233
+ CMD ["pm2-runtime", "start", "processes.config.cjs", "--env", "production", "--interpreter", "~/.bun/bin/bun"]
234
+ `;
235
+ }
236
+ });
@@ -0,0 +1,19 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "exception-filter",
4
+ label: "Exception Filter",
5
+ fileName: "{{symbolName}}.exception-filter",
6
+ outputDir: "{{srcDir}}/filters",
7
+ render(symbolName) {
8
+ return `import {BaseContext} from "@tsed/di";
9
+ import {Catch, ExceptionFilterMethods} from "@tsed/platform-exceptions";
10
+
11
+ @Catch(Error)
12
+ export class ${symbolName} implements ExceptionFilterMethods {
13
+ catch(exception: Exception, ctx: BaseContext) {
14
+
15
+ }
16
+ }
17
+ `;
18
+ }
19
+ });
@@ -0,0 +1,37 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ import { camelCase, pascalCase } from "change-case";
3
+ export default defineTemplate({
4
+ id: "factory",
5
+ label: "Factory",
6
+ fileName: "{{symbolName}}.factory?",
7
+ outputDir: "{{srcDir}}/services",
8
+ render(symbolName) {
9
+ const camelName = camelCase(symbolName);
10
+ const optName = pascalCase(symbolName + "Options");
11
+ return `import {injectable} from "@tsed/di";
12
+
13
+ interface ${optName} {
14
+
15
+ }
16
+
17
+ declare global {
18
+ namespace TsED {
19
+ interface Configuration extends Record<string, any> {
20
+ ${camelName}: Options;
21
+ }
22
+ }
23
+ }
24
+
25
+ export const ${symbolName} = injectable(Symbol.for("${symbolName}"))
26
+ .factory(() => {
27
+ const myConstant = constant<${optName}>("${camelName}");
28
+
29
+ // do something
30
+
31
+ return {};
32
+ })
33
+ .token();
34
+
35
+ export type {{symbolName}} = typeof ${symbolName};`;
36
+ }
37
+ });
@@ -0,0 +1,22 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "index.command",
4
+ label: "CLI Entry Point",
5
+ description: "Create a new CLI entry point file",
6
+ outputDir: "{{srcDir}}/bin",
7
+ fileName: "index",
8
+ hidden: true,
9
+ preserveCase: true,
10
+ render() {
11
+ return `#!/usr/bin/env node
12
+ import {CliCore} from "@tsed/cli-core";
13
+ import {config} from "@/config/config.js";
14
+ import * commands from "@/bin/commands/index.js";
15
+
16
+ CliCore.bootstrap({
17
+ ...config,
18
+ commands: [...Object.values(commands)]
19
+ }).catch(console.error);
20
+ `;
21
+ }
22
+ });
@@ -0,0 +1,17 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "index.config.util",
4
+ label: "Is Production utility",
5
+ type: "util",
6
+ description: "Create a utility to check if the environment is production",
7
+ fileName: "index",
8
+ outputDir: "{{srcDir}}/config/utils",
9
+ preserveCase: true,
10
+ hidden: true,
11
+ render() {
12
+ return `process.env.NODE_ENV = process.env.NODE_ENV || "development";
13
+
14
+ export const isProduction = process.env.NODE_ENV === "production";
15
+ `;
16
+ }
17
+ });
@@ -1,4 +1,13 @@
1
- import {Constant, Controller} from "@tsed/di";
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "index.controller",
4
+ label: "Index Controller",
5
+ description: "Create a new index controller file",
6
+ outputDir: "{{srcDir}}/controllers/pages",
7
+ fileName: "index.controller",
8
+ hidden: true,
9
+ render() {
10
+ return `import {Constant, Controller} from "@tsed/di";
2
11
  import {HeaderParams} from "@tsed/platform-params";
3
12
  import {View} from "@tsed/platform-views";
4
13
  import {SwaggerSettings} from "@tsed/swagger";
@@ -14,7 +23,7 @@ export class IndexController {
14
23
  @View("swagger.ejs")
15
24
  @(Returns(200, String).ContentType("text/html"))
16
25
  get(@HeaderParams("x-forwarded-proto") protocol: string, @HeaderParams("host") host: string) {
17
- const hostUrl = `${protocol || "http"}://${host}`;
26
+ const hostUrl = \`\${protocol || "http"}://\${host}\`;
18
27
 
19
28
  return {
20
29
  BASE_URL: hostUrl,
@@ -26,4 +35,6 @@ export class IndexController {
26
35
  })
27
36
  };
28
37
  }
29
- }
38
+ }`;
39
+ }
40
+ });
@@ -0,0 +1,32 @@
1
+ // Import all templates to register them with the DI container
2
+ import "./asyncFactory.template.js";
3
+ import "./command.template.js";
4
+ import "./controller.template.js";
5
+ import "./decorator.template.js";
6
+ import "./exception-filter.template.js";
7
+ import "./factory.template.js";
8
+ import "./interface.template.js";
9
+ import "./interceptor.template.js";
10
+ import "./middleware.template.js";
11
+ import "./model.template.js";
12
+ import "./module.template.js";
13
+ import "./pipe.template.js";
14
+ import "./prisma.service.template.js";
15
+ import "./repository.template.js";
16
+ import "./response-filter.template.js";
17
+ import "./service.template.js";
18
+ import "./value.template.js";
19
+ import "./barrels.template.js";
20
+ import "./server.template.js";
21
+ import "./config.template.js";
22
+ import "./index.template.js";
23
+ import "./index.controller.template.js";
24
+ import "./index.command.template.js";
25
+ import "./index.logger.template.js";
26
+ import "./index.config.utils.template.js";
27
+ import "./tsconfig.spec.template.js";
28
+ import "./docker-compose.template.js";
29
+ import "./dockerfile.template.js";
30
+ import "./pm2.template.js";
31
+ import "./readme.template.js";
32
+ import "./new-template.template.js";
@@ -0,0 +1,41 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ import { ProjectConvention } from "../interfaces/index.js";
3
+ export default defineTemplate({
4
+ id: "index.logger",
5
+ label: "Logger",
6
+ description: "Create a new logger configuration file",
7
+ outputDir: "{{srcDir}}/config/logger",
8
+ fileName: "index",
9
+ preserveCase: true,
10
+ hidden: true,
11
+ render() {
12
+ return `import "@tsed/logger-std";
13
+ import "@tsed/logger/layouts/JsonLayout.js";
14
+ import {DILoggerOptions} from "@tsed/di";
15
+ import {$log} from "@tsed/logger";
16
+ import {isProduction} from "../utils/index.js";
17
+
18
+ if (isProduction) {
19
+ $log.appenders.set("stdout", {
20
+ type: "stdout",
21
+ levels: ["info", "debug"],
22
+ layout: {
23
+ type: "json"
24
+ }
25
+ });
26
+
27
+ $log.appenders.set("stderr", {
28
+ levels: ["trace", "fatal", "error", "warn"],
29
+ type: "stderr",
30
+ layout: {
31
+ type: "json"
32
+ }
33
+ });
34
+ }
35
+
36
+ export default <DILoggerOptions>{
37
+ disableRoutesSummary: isProduction
38
+ };
39
+ `;
40
+ }
41
+ });
@@ -1,6 +1,15 @@
1
- import {$log} from "@tsed/logger";
2
- import { {{platformSymbol}} } from "@tsed/platform-{{platform}}";
3
- import {Server} from "./{{entryServer}}.js";
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "index",
4
+ label: "Main index application file",
5
+ description: "Create a new main index application file",
6
+ outputDir: "{{srcDir}}",
7
+ fileName: "index",
8
+ hidden: true,
9
+ preserveCase: true,
10
+ render() {
11
+ return `import {$log} from "@tsed/logger";
12
+ import {PlatformBuilder} from "@tsed/platform-http";
4
13
 
5
14
  const SIG_EVENTS = [
6
15
  "beforeExit",
@@ -19,7 +28,8 @@ const SIG_EVENTS = [
19
28
  ];
20
29
 
21
30
  try {
22
- const platform = await {{platformSymbol}}.bootstrap(Server);
31
+ const platform = await PlatformBuilder.bootstrap(Server);
32
+
23
33
  await platform.listen();
24
34
 
25
35
  SIG_EVENTS.forEach((evt) => process.on(evt, () => platform.stop()));
@@ -33,4 +43,6 @@ try {
33
43
  } catch (error) {
34
44
  $log.error({event: "SERVER_BOOTSTRAP_ERROR", message: error.message, stack: error.stack});
35
45
  }
36
-
46
+ `;
47
+ }
48
+ });
@@ -0,0 +1,31 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "interceptor",
4
+ label: "Interceptor",
5
+ fileName: "{{symbolName}}.interceptor",
6
+ outputDir: "{{srcDir}}/interceptors",
7
+ render(symbolName) {
8
+ return `import {InterceptorMethods, InterceptorContext, InterceptorMethods, Interceptor} from "@tsed/di";
9
+
10
+ @Interceptor()
11
+ export class ${symbolName} implements InterceptorMethods {
12
+ /**
13
+ * ctx: The context that holds the dynamic data related to the method execution and the proceed method
14
+ * to proceed with the original method execution
15
+ *
16
+ * opts: Static params that can be provided when the interceptor is attached to a specific method
17
+ */
18
+ async intercept(context: InterceptorContext<any>, next: InterceptorMethods) {
19
+ console.log(\`the method \${context.propertyKey} will be executed with args \${context.args} and static data \${context.options}\`);
20
+ // let the original method by calling next function
21
+ const result = await next();
22
+
23
+ console.log(\`the method was executed, and returned \${result}\`);
24
+
25
+ // must return the returned value back to the caller
26
+ return result;
27
+ }
28
+ }
29
+ `;
30
+ }
31
+ });
@@ -0,0 +1,13 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "interface",
4
+ label: "Interface",
5
+ fileName: "{{symbolName}}.interface",
6
+ outputDir: "{{srcDir}}/interfaces",
7
+ render(symbolName) {
8
+ return `export interface ${symbolName} {
9
+
10
+ }
11
+ `;
12
+ }
13
+ });
@@ -0,0 +1,36 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "middleware",
4
+ label: "Middleware",
5
+ fileName: "{{symbolName}}.middleware",
6
+ outputDir: "{{srcDir}}/middlewares",
7
+ prompts(context) {
8
+ return [
9
+ {
10
+ type: "list",
11
+ name: "middlewarePosition",
12
+ message: () => `The middleware should be called:`,
13
+ choices: [
14
+ { name: "Before the endpoint", value: "before" },
15
+ { name: "After the endpoint", value: "after" }
16
+ ],
17
+ when(state) {
18
+ return !!((["decorator"].includes(state.type || context.type) && ["middleware"].includes(state.templateType)) ||
19
+ context.middlewarePosition);
20
+ }
21
+ }
22
+ ];
23
+ },
24
+ render(symbolName) {
25
+ return `import {Middleware, MiddlewareMethods} from "@tsed/platform-middlewares";
26
+ import {Context} from "@tsed/platform-params";
27
+
28
+ @Middleware()
29
+ export class ${symbolName} implements MiddlewareMethods {
30
+ use(@Context() ctx: Context) {
31
+
32
+ }
33
+ }
34
+ `;
35
+ }
36
+ });
@@ -0,0 +1,16 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "model",
4
+ label: "Model",
5
+ fileName: "{{symbolName}}.model",
6
+ outputDir: "{{srcDir}}/models",
7
+ render(symbolName) {
8
+ return `import {Property} from "@tsed/schema";
9
+
10
+ export class ${symbolName} {
11
+ @Property()
12
+ id: string;
13
+ }
14
+ `;
15
+ }
16
+ });
@@ -0,0 +1,16 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "module",
4
+ label: "Module",
5
+ fileName: "{{symbolName}}.module",
6
+ outputDir: "{{srcDir}}",
7
+ render(symbolName) {
8
+ return `import {Module} from "@tsed/di";
9
+
10
+ @Module()
11
+ export class ${symbolName} {
12
+
13
+ }
14
+ `;
15
+ }
16
+ });
@@ -0,0 +1,67 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ defineTemplate({
3
+ id: "new-template",
4
+ label: "New Template",
5
+ fileName: "{{symbolName}}.template",
6
+ preserveCase: true,
7
+ outputDir: "./.templates",
8
+ hidden: true,
9
+ render(_, context) {
10
+ if (context.from === "new") {
11
+ return `import {defineTemplate} from "@tsed/cli";
12
+
13
+ export default defineTemplate({
14
+ id: "${context.templateId}",
15
+ label: "${context.name}",
16
+ fileName: "{{symbolName}}.services",
17
+ outputDir: "{{srcDir}}/services",
18
+ render(symbolName, context) {
19
+ return \`export class \${symbolName} {}\`
20
+ }
21
+ });`;
22
+ }
23
+ if (context.template) {
24
+ const { id, ...props } = context.template;
25
+ const render = props.render.toString();
26
+ if (render.includes(""))
27
+ return `import {defineTemplate} from "@tsed/cli";
28
+
29
+ defineTemplate({
30
+ id: "${context.override ? id : context.templateId}",
31
+ label: "${context.name}",
32
+ fileName: "${props.fileName}",
33
+ outputDir: "${props.outputDir}",
34
+ ${props.prompts ? `${props.prompts.toString()},` : ""}
35
+ ${props.render.toString()}
36
+ });`;
37
+ }
38
+ },
39
+ hooks: {
40
+ $afterCreateSourceFile(sourceFile) {
41
+ const sourceFileText = sourceFile.getFullText();
42
+ if (sourceFileText.includes("camelCase")) {
43
+ sourceFile.addImportDeclaration({
44
+ namedImports: ["camelCase"],
45
+ moduleSpecifier: "change-case"
46
+ });
47
+ }
48
+ if (sourceFileText.includes("pascalCase")) {
49
+ sourceFile.addImportDeclaration({
50
+ namedImports: ["pascalCase"],
51
+ moduleSpecifier: "change-case"
52
+ });
53
+ }
54
+ if (sourceFileText.includes("kebabCase")) {
55
+ sourceFile.addImportDeclaration({
56
+ namedImports: ["kebabCase"],
57
+ moduleSpecifier: "change-case"
58
+ });
59
+ }
60
+ sourceFile.formatText({
61
+ indentSize: 2
62
+ });
63
+ sourceFile.saveSync();
64
+ return sourceFile;
65
+ }
66
+ }
67
+ });
@@ -0,0 +1,19 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "pipe",
4
+ label: "Pipe",
5
+ fileName: "{{symbolName}}.pipe",
6
+ outputDir: "{{srcDir}}/pipes",
7
+ render(symbolName) {
8
+ return `import {Injectable} from "@tsed/di";
9
+ import {PipeMethods, ParamMetadata} from "@tsed/platform-params";
10
+
11
+ @Injectable()
12
+ export class ${symbolName} extends PipeMethods {
13
+ transform(value: any, param: ParamMetadata) {
14
+ return null;
15
+ }
16
+ }
17
+ `;
18
+ }
19
+ });