@tsed/cli 6.6.2 → 7.0.0-alpha.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 (244) hide show
  1. package/lib/esm/commands/add/AddCmd.js +16 -16
  2. package/lib/esm/commands/generate/GenerateCmd.js +71 -220
  3. package/lib/esm/commands/generate/mappers/mapGenerateContext.js +29 -0
  4. package/lib/esm/commands/init/InitCmd.js +186 -168
  5. package/lib/esm/commands/init/config/FeaturesPrompt.js +79 -3
  6. package/lib/esm/commands/init/mappers/mapToContext.js +4 -3
  7. package/lib/esm/commands/run/RunCmd.js +22 -26
  8. package/lib/esm/commands/update/UpdateCmd.js +9 -13
  9. package/lib/esm/fn/exec.js +5 -0
  10. package/lib/esm/fn/render.js +5 -0
  11. package/lib/esm/index.js +7 -4
  12. package/lib/esm/interfaces/AlterPackageJson.js +1 -0
  13. package/lib/esm/interfaces/AlterProjectFiles.js +1 -0
  14. package/lib/esm/interfaces/AlterRenderFiles.js +1 -0
  15. package/lib/esm/interfaces/CliCommandHooks.js +1 -0
  16. package/lib/esm/interfaces/GenerateCmdContext.js +1 -0
  17. package/lib/esm/interfaces/InitCmdOptions.js +1 -0
  18. package/lib/esm/interfaces/RenderDataContext.js +1 -0
  19. package/lib/esm/interfaces/RuntimeTypes.js +1 -0
  20. package/lib/esm/interfaces/index.js +9 -0
  21. package/lib/esm/pipes/OutputFilePathPipe.js +40 -18
  22. package/lib/esm/pipes/RoutePipe.js +4 -8
  23. package/lib/esm/pipes/{ClassNamePipe.js → SymbolNamePipe.js} +14 -11
  24. package/lib/esm/pipes/index.js +1 -1
  25. package/lib/esm/platforms/{InitPlatformsModule.js → PlatformsModule.js} +4 -10
  26. package/lib/esm/platforms/supports/InitExpressPlatform.js +27 -10
  27. package/lib/esm/platforms/supports/InitFastifyPlatform.js +27 -10
  28. package/lib/esm/platforms/supports/InitKoaPlatform.js +16 -10
  29. package/lib/esm/processors/__fixtures__/createFakeProject.js +35 -0
  30. package/lib/esm/processors/transformBinFile.js +47 -0
  31. package/lib/esm/processors/transformConfigFile.js +26 -0
  32. package/lib/esm/processors/transformIndexFile.js +28 -0
  33. package/lib/esm/processors/transformServerFile.js +64 -0
  34. package/lib/esm/runtimes/RuntimesModule.js +7 -17
  35. package/lib/esm/runtimes/supports/BabelRuntime.js +5 -11
  36. package/lib/esm/runtimes/supports/BunRuntime.js +4 -10
  37. package/lib/esm/runtimes/supports/NodeRuntime.js +1 -1
  38. package/lib/esm/runtimes/supports/WebpackRuntime.js +1 -1
  39. package/lib/esm/services/CliProjectService.js +91 -0
  40. package/lib/esm/services/CliRunScript.js +4 -8
  41. package/lib/esm/services/CliTemplatesService.js +67 -0
  42. package/lib/esm/services/ProjectClient.js +139 -0
  43. package/lib/esm/services/mappers/mapDefaultTemplateOptions.js +30 -0
  44. package/lib/esm/templates/asyncFactory.template.js +38 -0
  45. package/lib/esm/templates/barrels.template.js +22 -0
  46. package/lib/esm/templates/command.template.js +56 -0
  47. package/lib/esm/templates/config.template.js +27 -0
  48. package/lib/esm/templates/controller.template.js +45 -0
  49. package/lib/esm/templates/decorator.template.js +182 -0
  50. package/lib/esm/templates/docker-compose.template.js +25 -0
  51. package/lib/esm/templates/dockerfile.template.js +236 -0
  52. package/lib/esm/templates/exception-filter.template.js +19 -0
  53. package/lib/esm/templates/factory.template.js +37 -0
  54. package/lib/esm/templates/index.command.template.js +18 -0
  55. package/lib/esm/templates/index.config.utils.template.js +17 -0
  56. package/{templates/init/src/controllers/pages/IndexController.ts.hbs → lib/esm/templates/index.controller.template.js} +14 -3
  57. package/lib/esm/templates/index.js +32 -0
  58. package/lib/esm/templates/index.logger.template.js +38 -0
  59. package/{templates/init/src/index.ts.hbs → lib/esm/templates/index.template.js} +17 -5
  60. package/lib/esm/templates/interceptor.template.js +31 -0
  61. package/lib/esm/templates/interface.template.js +13 -0
  62. package/lib/esm/templates/middleware.template.js +34 -0
  63. package/lib/esm/templates/model.template.js +16 -0
  64. package/lib/esm/templates/module.template.js +16 -0
  65. package/lib/esm/templates/pipe.template.js +19 -0
  66. package/lib/esm/templates/pm2.template.js +111 -0
  67. package/lib/esm/templates/prisma.service.template.js +23 -0
  68. package/{templates/init/README.md.hbs → lib/esm/templates/readme.template.js} +28 -13
  69. package/lib/esm/templates/repository.template.js +16 -0
  70. package/lib/esm/templates/response-filter.template.js +19 -0
  71. package/lib/esm/templates/server.template.js +37 -0
  72. package/lib/esm/templates/service.template.js +16 -0
  73. package/lib/esm/templates/tsconfig.spec.template.js +34 -0
  74. package/lib/esm/templates/tsconfig.template.js +31 -0
  75. package/lib/esm/templates/value.template.js +13 -0
  76. package/lib/esm/utils/defineTemplate.js +13 -0
  77. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  78. package/lib/types/commands/add/AddCmd.d.ts +2 -2
  79. package/lib/types/commands/generate/GenerateCmd.d.ts +33 -87
  80. package/lib/types/commands/generate/mappers/mapGenerateContext.d.ts +2 -0
  81. package/lib/types/commands/init/InitCmd.d.ts +18 -20
  82. package/lib/types/commands/init/config/FeaturesPrompt.d.ts +10 -2
  83. package/lib/types/commands/init/mappers/mapToContext.d.ts +2 -2
  84. package/lib/types/commands/init/mappers/mapUniqFeatures.d.ts +1 -1
  85. package/lib/types/commands/init/prompts/getFeaturesPrompt.d.ts +1 -1
  86. package/lib/types/commands/update/UpdateCmd.d.ts +2 -2
  87. package/lib/types/fn/exec.d.ts +1 -0
  88. package/lib/types/fn/render.d.ts +2 -0
  89. package/lib/types/index.d.ts +7 -4
  90. package/lib/types/interfaces/AlterGenerateTasks.d.ts +5 -0
  91. package/lib/types/interfaces/AlterInitSubTasks.d.ts +5 -0
  92. package/lib/types/interfaces/AlterPackageJson.d.ts +5 -0
  93. package/lib/types/interfaces/AlterProjectFiles.d.ts +5 -0
  94. package/lib/types/interfaces/AlterRenderFiles.d.ts +10 -0
  95. package/lib/types/interfaces/CliCommandHooks.d.ts +11 -0
  96. package/lib/types/interfaces/GenerateCmdContext.d.ts +19 -0
  97. package/lib/types/interfaces/InitCmdOptions.d.ts +8 -0
  98. package/lib/types/interfaces/PlatformType.d.ts +7 -0
  99. package/lib/types/interfaces/RenderDataContext.d.ts +60 -0
  100. package/lib/types/interfaces/RuntimeTypes.d.ts +8 -0
  101. package/lib/types/interfaces/index.d.ts +9 -0
  102. package/lib/types/pipes/OutputFilePathPipe.d.ts +7 -4
  103. package/lib/types/pipes/{ClassNamePipe.d.ts → SymbolNamePipe.d.ts} +3 -3
  104. package/lib/types/pipes/index.d.ts +1 -1
  105. package/lib/types/platforms/{InitPlatformsModule.d.ts → PlatformsModule.d.ts} +1 -1
  106. package/lib/types/platforms/supports/InitBasePlatform.d.ts +3 -0
  107. package/lib/types/platforms/supports/InitExpressPlatform.d.ts +2 -0
  108. package/lib/types/platforms/supports/InitFastifyPlatform.d.ts +2 -0
  109. package/lib/types/platforms/supports/InitKoaPlatform.d.ts +2 -0
  110. package/lib/types/processors/__fixtures__/createFakeProject.d.ts +5 -0
  111. package/lib/types/processors/transformBinFile.d.ts +3 -0
  112. package/lib/types/processors/transformConfigFile.d.ts +3 -0
  113. package/lib/types/processors/transformIndexFile.d.ts +3 -0
  114. package/lib/types/processors/transformServerFile.d.ts +3 -0
  115. package/lib/types/runtimes/RuntimesModule.d.ts +5 -5
  116. package/lib/types/services/CliProjectService.d.ts +15 -0
  117. package/lib/types/services/CliTemplatesService.d.ts +29 -0
  118. package/lib/types/services/ProjectClient.d.ts +36 -0
  119. package/lib/types/services/mappers/mapDefaultTemplateOptions.d.ts +11 -0
  120. package/lib/types/templates/asyncFactory.template.d.ts +2 -0
  121. package/lib/types/templates/barrels.template.d.ts +2 -0
  122. package/lib/types/templates/command.template.d.ts +2 -0
  123. package/lib/types/templates/config.template.d.ts +2 -0
  124. package/lib/types/templates/controller.template.d.ts +2 -0
  125. package/lib/types/templates/decorator.template.d.ts +2 -0
  126. package/lib/types/templates/docker-compose.template.d.ts +2 -0
  127. package/lib/types/templates/dockerfile.template.d.ts +1 -0
  128. package/lib/types/templates/exception-filter.template.d.ts +2 -0
  129. package/lib/types/templates/factory.template.d.ts +2 -0
  130. package/lib/types/templates/index.command.template.d.ts +2 -0
  131. package/lib/types/templates/index.config.utils.template.d.ts +2 -0
  132. package/lib/types/templates/index.controller.template.d.ts +2 -0
  133. package/lib/types/templates/index.d.ts +31 -0
  134. package/lib/types/templates/index.logger.template.d.ts +2 -0
  135. package/lib/types/templates/index.template.d.ts +2 -0
  136. package/lib/types/templates/interceptor.template.d.ts +2 -0
  137. package/lib/types/templates/interface.template.d.ts +2 -0
  138. package/lib/types/templates/middleware.template.d.ts +2 -0
  139. package/lib/types/templates/model.template.d.ts +2 -0
  140. package/lib/types/templates/module.template.d.ts +2 -0
  141. package/lib/types/templates/pipe.template.d.ts +2 -0
  142. package/lib/types/templates/pm2.template.d.ts +1 -0
  143. package/lib/types/templates/prisma.service.template.d.ts +2 -0
  144. package/lib/types/templates/readme.template.d.ts +2 -0
  145. package/lib/types/templates/repository.template.d.ts +2 -0
  146. package/lib/types/templates/response-filter.template.d.ts +2 -0
  147. package/lib/types/templates/server.template.d.ts +2 -0
  148. package/lib/types/templates/service.template.d.ts +2 -0
  149. package/lib/types/templates/tsconfig.spec.template.d.ts +2 -0
  150. package/lib/types/templates/tsconfig.template.d.ts +2 -0
  151. package/lib/types/templates/value.template.d.ts +2 -0
  152. package/lib/types/utils/defineTemplate.d.ts +39 -0
  153. package/package.json +18 -16
  154. package/templates/tsconfig.node.json +14 -0
  155. package/templates/webpack.config.js +55 -0
  156. package/lib/esm/commands/generate/ProviderTypes.js +0 -103
  157. package/lib/esm/commands/init/interfaces/InitOptions.js +0 -5
  158. package/lib/esm/services/ProvidersInfoService.js +0 -46
  159. package/lib/esm/services/Renderer.js +0 -162
  160. package/lib/esm/utils/fillImports.js +0 -38
  161. package/lib/esm/utils/hbs/array.js +0 -515
  162. package/lib/esm/utils/hbs/collection.js +0 -60
  163. package/lib/esm/utils/hbs/comparison.js +0 -431
  164. package/lib/esm/utils/hbs/index.js +0 -11
  165. package/lib/esm/utils/hbs/object.js +0 -236
  166. package/lib/esm/utils/hbs/switch.js +0 -10
  167. package/lib/esm/utils/renderer/insertAfter.js +0 -12
  168. package/lib/esm/utils/renderer/insertImport.js +0 -11
  169. package/lib/types/commands/generate/ProviderTypes.d.ts +0 -11
  170. package/lib/types/commands/init/interfaces/InitCmdContext.d.ts +0 -6
  171. package/lib/types/commands/init/interfaces/InitOptions.d.ts +0 -20
  172. package/lib/types/services/ProvidersInfoService.d.ts +0 -21
  173. package/lib/types/services/Renderer.d.ts +0 -44
  174. package/lib/types/utils/fillImports.d.ts +0 -1
  175. package/lib/types/utils/hbs/array.d.ts +0 -1
  176. package/lib/types/utils/hbs/collection.d.ts +0 -1
  177. package/lib/types/utils/hbs/comparison.d.ts +0 -1
  178. package/lib/types/utils/hbs/object.d.ts +0 -1
  179. package/lib/types/utils/hbs/switch.d.ts +0 -1
  180. package/lib/types/utils/renderer/insertAfter.d.ts +0 -1
  181. package/lib/types/utils/renderer/insertImport.d.ts +0 -1
  182. package/templates/generate/async.factory.hbs +0 -35
  183. package/templates/generate/command.hbs +0 -45
  184. package/templates/generate/controller.hbs +0 -10
  185. package/templates/generate/decorator.class.hbs +0 -14
  186. package/templates/generate/decorator.endpoint.hbs +0 -15
  187. package/templates/generate/decorator.generic.hbs +0 -19
  188. package/templates/generate/decorator.method.hbs +0 -16
  189. package/templates/generate/decorator.middleware.hbs +0 -26
  190. package/templates/generate/decorator.param.hbs +0 -15
  191. package/templates/generate/decorator.parameters.hbs +0 -9
  192. package/templates/generate/decorator.prop.hbs +0 -14
  193. package/templates/generate/decorator.property.hbs +0 -5
  194. package/templates/generate/exception-filter.hbs +0 -9
  195. package/templates/generate/factory.hbs +0 -11
  196. package/templates/generate/injectable.hbs +0 -6
  197. package/templates/generate/interceptor.hbs +0 -21
  198. package/templates/generate/interface.hbs +0 -3
  199. package/templates/generate/middleware.hbs +0 -9
  200. package/templates/generate/model.hbs +0 -6
  201. package/templates/generate/module.hbs +0 -6
  202. package/templates/generate/pipe.hbs +0 -9
  203. package/templates/generate/prisma.service.hbs +0 -13
  204. package/templates/generate/repository.hbs +0 -6
  205. package/templates/generate/response-filter.hbs +0 -9
  206. package/templates/generate/server/_partials/server-footer.hbs +0 -10
  207. package/templates/generate/server/_partials/server-header.hbs +0 -34
  208. package/templates/generate/server/express/server.hbs +0 -10
  209. package/templates/generate/server/fastify/server.hbs +0 -14
  210. package/templates/generate/server/koa/server.hbs +0 -8
  211. package/templates/generate/service.hbs +0 -6
  212. package/templates/generate/value.hbs +0 -3
  213. package/templates/init/.barrels.json.hbs +0 -9
  214. package/templates/init/.gitignore.hbs +0 -57
  215. package/templates/init/.npmrc.hbs +0 -2
  216. package/templates/init/docker/_partials/docker-body.hbs +0 -5
  217. package/templates/init/docker/_partials/docker-dev-tools.hbs +0 -2
  218. package/templates/init/docker/_partials/docker-header.hbs +0 -16
  219. package/templates/init/docker/bun/Dockerfile.hbs +0 -36
  220. package/templates/init/docker/npm/Dockerfile.hbs +0 -28
  221. package/templates/init/docker/pnpm/Dockerfile.hbs +0 -28
  222. package/templates/init/docker/yarn/Dockerfile.hbs +0 -28
  223. package/templates/init/docker/yarn_berry/Dockerfile.hbs +0 -31
  224. package/templates/init/docker-compose.yml.hbs +0 -14
  225. package/templates/init/pm2/bun/processes.config.cjs.hbs +0 -23
  226. package/templates/init/pm2/node-compiled/processes.config.cjs.hbs +0 -22
  227. package/templates/init/pm2/node-loader/processes.config.cjs.hbs +0 -24
  228. package/templates/init/src/bin/index.ts.hbs +0 -9
  229. package/templates/init/src/config/envs/index.ts.hbs +0 -7
  230. package/templates/init/src/config/index.ts.hbs +0 -38
  231. package/templates/init/src/config/logger/index.ts.hbs +0 -25
  232. package/templates/init/tsconfig.json.hbs +0 -16
  233. package/templates/init/tsconfig.node.json.hbs +0 -20
  234. package/templates/init/tsconfig.spec.json.hbs +0 -25
  235. package/templates/init/webpack.config.js.hbs +0 -65
  236. /package/lib/esm/{commands/init/interfaces/InitCmdContext.js → interfaces/AlterGenerateTasks.js} +0 -0
  237. /package/lib/{types/utils/hbs/index.d.ts → esm/interfaces/AlterInitSubTasks.js} +0 -0
  238. /package/templates/{init/.babelrc.hbs → .babelrc} +0 -0
  239. /package/templates/{init/.dockerignore.hbs → .dockerignore} +0 -0
  240. /package/templates/{init/.swcrc.hbs → .swcrc} +0 -0
  241. /package/templates/{init/.yarnrc.hbs → .yarnrc} +0 -0
  242. /package/templates/{init/nodemon.json.hbs → nodemon.json} +0 -0
  243. /package/templates/{init/tsconfig.base.json.hbs → tsconfig.base.json} +0 -0
  244. /package/templates/{init/views/swagger.ejs.hbs → views/swagger.ejs} +0 -0
@@ -0,0 +1,182 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "decorator",
4
+ label: "Decorator",
5
+ fileName: "{{symbolName}}",
6
+ outputDir: "{{srcDir}}/decorators",
7
+ prompts: (data) => [
8
+ {
9
+ type: "list",
10
+ name: "templateType",
11
+ message: "What kind of decorator do you want to create?",
12
+ when(state) {
13
+ return !!(["decorator"].includes(state.type || data.type) || data.templateType);
14
+ },
15
+ choices: [
16
+ { name: "Class Decorator", value: "class" },
17
+ { name: "Generic Decorator (class, property)", value: "generic" },
18
+ { name: "Method Decorator", value: "method" },
19
+ { name: "Parameter Decorator", value: "param" },
20
+ { name: "Property Decorator", value: "property" },
21
+ { name: "Property Decorator (with @Property)", value: "prop" },
22
+ { name: "Parameters Decorator", value: "parameters" },
23
+ { name: "Endpoint Decorator", value: "endpoint" },
24
+ { name: "Middleware Decorator", value: "middleware" }
25
+ ],
26
+ default: "class"
27
+ }
28
+ ],
29
+ render(symbolName, data) {
30
+ const type = data.templateType || "class";
31
+ switch (type) {
32
+ case "class":
33
+ return `
34
+ export interface ${symbolName}Options {
35
+
36
+ }
37
+
38
+ export function ${symbolName}(options: ${symbolName}Options): ClassDecorator {
39
+ return (target: any): any => {
40
+ return class extends target {
41
+ constructor(...args: any[]) {
42
+ super(...args);
43
+ }
44
+ };
45
+ };
46
+ }
47
+ `;
48
+ case "generic":
49
+ return `import {DecoratorTypes, UnsupportedDecoratorType, decoratorTypeOf} from "@tsed/core";
50
+
51
+ export interface ${symbolName}Options {
52
+
53
+ }
54
+
55
+ export function ${symbolName}(options: ${symbolName}Options): any {
56
+ return (...args: DecoratorParameters): any => {
57
+ switch(decoratorTypeOf(args)) {
58
+ case DecoratorTypes.CLASS:
59
+ case DecoratorTypes.PROP:
60
+ console.log("do something")
61
+ break;
62
+
63
+ default:
64
+ throw new UnsupportedDecoratorType(${symbolName}, args);
65
+ }
66
+ };
67
+ }
68
+ `;
69
+ case "method":
70
+ return `
71
+ export interface ${symbolName}Options {
72
+
73
+ }
74
+
75
+ export function ${symbolName}(options: ${symbolName}Options): MethodDecorator {
76
+ return (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> | void => {
77
+ console.log("do something");
78
+ return descriptor;
79
+ };
80
+ }
81
+ `;
82
+ case "param":
83
+ return `import {ParamTypes, useDecorators} from "@tsed/core";
84
+ import {UsePipe} from "@tsed/platform-params";
85
+
86
+ export interface ${symbolName}Options {
87
+
88
+ }
89
+
90
+ export function ${symbolName}(options: ${symbolName}Options): ParameterDecorator {
91
+ return useDecorators(
92
+ UsePipe(${symbolName}Pipe),
93
+ ParamTypes("${symbolName.toLowerCase()}")
94
+ );
95
+ }
96
+ `;
97
+ case "property":
98
+ return `
99
+ export function ${symbolName}(): PropertyDecorator {
100
+ return (target: Object, propertyKey: string | symbol): void => {
101
+ console.log("do something");
102
+ };
103
+ }
104
+ `;
105
+ case "prop":
106
+ return `import {useDecorators} from "@tsed/core";
107
+ import {Property} from "@tsed/schema";
108
+
109
+ export interface ${symbolName}Options {
110
+
111
+ }
112
+
113
+ export function ${symbolName}(options: ${symbolName}Options = {}): PropertyDecorator {
114
+ return useDecorators(
115
+ Property()
116
+ );
117
+ }
118
+ `;
119
+ case "parameters":
120
+ return `
121
+ export interface ${symbolName}Options {
122
+
123
+ }
124
+
125
+ export function ${symbolName}(options: ${symbolName}Options): ParameterDecorator {
126
+ return (target: Object, propertyKey: string | symbol, parameterIndex: number): void => {
127
+ console.log("do something");
128
+ };
129
+ }
130
+ `;
131
+ case "endpoint":
132
+ return `import {useDecorators} from "@tsed/core";
133
+ import {Get} from "@tsed/schema";
134
+
135
+ export interface ${symbolName}Options {
136
+
137
+ }
138
+
139
+ export function ${symbolName}(options: ${symbolName}Options = {}): MethodDecorator {
140
+ return useDecorators(
141
+ Get("/")
142
+ );
143
+ }
144
+ `;
145
+ case "middleware":
146
+ return `import {Context} from "@tsed/platform-params";
147
+ import {Middleware, MiddlewareMethods} from "@tsed/platform-middlewares";
148
+ import {Next} from "@tsed/common";
149
+
150
+ export interface ${symbolName}Options {
151
+
152
+ }
153
+
154
+ export function ${symbolName}(options: ${symbolName}Options = {}): ClassDecorator {
155
+ return (target: any) => {
156
+ @Middleware()
157
+ class ${symbolName}Middleware implements MiddlewareMethods {
158
+ use(@Context() ctx: Context, @Next() next: Next) {
159
+ // do something
160
+ return next();
161
+ }
162
+ }
163
+
164
+ return target;
165
+ };
166
+ }
167
+ `;
168
+ default:
169
+ return `
170
+ export interface ${symbolName}Options {
171
+
172
+ }
173
+
174
+ export function ${symbolName}(options: ${symbolName}Options): any {
175
+ return (...args: any[]): any => {
176
+ console.log("do something");
177
+ };
178
+ }
179
+ `;
180
+ }
181
+ }
182
+ });
@@ -0,0 +1,25 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "docker-compose.yml",
4
+ label: "Docker Compose",
5
+ description: "Create a docker-compose.yml file.",
6
+ fileName: "docker-compose",
7
+ outputDir: ".",
8
+ ext: "yml",
9
+ preserveCase: true,
10
+ render(_, data) {
11
+ return `services:
12
+ server:
13
+ build:
14
+ context: .
15
+ dockerfile: ./Dockerfile
16
+ args:
17
+ - http_proxy
18
+ - https_proxy
19
+ - no_proxy
20
+ image: ${data.projectName}/server:latest
21
+ ports:
22
+ - "8081:8081"
23
+ `;
24
+ }
25
+ });
@@ -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",
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",
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",
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",
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",
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,18 @@
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
+ render() {
8
+ return `#!/usr/bin/env node
9
+ import {CliCore} from "@tsed/cli-core";
10
+ import {config} from "@/config";
11
+
12
+ CliCore.bootstrap({
13
+ ...config,
14
+ commands: []
15
+ }).catch(console.error);
16
+ `;
17
+ }
18
+ });
@@ -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(_, data) {
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.template.js";
28
+ import "./tsconfig.spec.template.js";
29
+ import "./docker-compose.template.js";
30
+ import "./dockerfile.template.js";
31
+ import "./pm2.template.js";
32
+ import "./readme.template.js";
@@ -0,0 +1,38 @@
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
+ render(_, data) {
11
+ return `import {DILoggerOptions} from "@tsed/di";
12
+ import {$log} from "@tsed/logger";
13
+ import {isProduction} from "../utils/index.js";
14
+
15
+ if (isProduction) {
16
+ $log.appenders.set("stdout", {
17
+ type: "stdout",
18
+ levels: ["info", "debug"],
19
+ layout: {
20
+ type: "json"
21
+ }
22
+ });
23
+
24
+ $log.appenders.set("stderr", {
25
+ levels: ["trace", "fatal", "error", "warn"],
26
+ type: "stderr",
27
+ layout: {
28
+ type: "json"
29
+ }
30
+ });
31
+ }
32
+
33
+ export default <DILoggerOptions>{
34
+ disableRoutesSummary: isProduction
35
+ };
36
+ `;
37
+ }
38
+ });
@@ -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
+ });