@tsed/cli 6.6.3 → 7.0.0-alpha.2

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 (246) hide show
  1. package/lib/esm/commands/add/AddCmd.js +16 -16
  2. package/lib/esm/commands/generate/GenerateCmd.js +69 -222
  3. package/lib/esm/commands/generate/mappers/mapGenerateContext.js +29 -0
  4. package/lib/esm/commands/init/InitCmd.js +190 -171
  5. package/lib/esm/commands/init/config/FeaturesPrompt.js +101 -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/fn/taskOutput.js +7 -0
  12. package/lib/esm/index.js +7 -4
  13. package/lib/esm/interfaces/AlterPackageJson.js +1 -0
  14. package/lib/esm/interfaces/AlterProjectFiles.js +1 -0
  15. package/lib/esm/interfaces/AlterRenderFiles.js +1 -0
  16. package/lib/esm/interfaces/CliCommandHooks.js +1 -0
  17. package/lib/esm/interfaces/GenerateCmdContext.js +1 -0
  18. package/lib/esm/interfaces/InitCmdOptions.js +1 -0
  19. package/lib/esm/interfaces/RenderDataContext.js +1 -0
  20. package/lib/esm/interfaces/RuntimeTypes.js +1 -0
  21. package/lib/esm/interfaces/index.js +9 -0
  22. package/lib/esm/pipes/OutputFilePathPipe.js +40 -18
  23. package/lib/esm/pipes/RoutePipe.js +4 -8
  24. package/lib/esm/pipes/{ClassNamePipe.js → SymbolNamePipe.js} +14 -11
  25. package/lib/esm/pipes/index.js +1 -1
  26. package/lib/esm/platforms/{InitPlatformsModule.js → PlatformsModule.js} +4 -10
  27. package/lib/esm/platforms/supports/InitExpressPlatform.js +27 -10
  28. package/lib/esm/platforms/supports/InitFastifyPlatform.js +27 -10
  29. package/lib/esm/platforms/supports/InitKoaPlatform.js +16 -10
  30. package/lib/esm/processors/__fixtures__/createFakeProject.js +35 -0
  31. package/lib/esm/processors/transformBinFile.js +47 -0
  32. package/lib/esm/processors/transformConfigFile.js +105 -0
  33. package/lib/esm/processors/transformIndexFile.js +23 -0
  34. package/lib/esm/processors/transformServerFile.js +60 -0
  35. package/lib/esm/runtimes/RuntimesModule.js +7 -17
  36. package/lib/esm/runtimes/supports/BabelRuntime.js +5 -11
  37. package/lib/esm/runtimes/supports/BunRuntime.js +4 -10
  38. package/lib/esm/runtimes/supports/NodeRuntime.js +1 -1
  39. package/lib/esm/runtimes/supports/WebpackRuntime.js +1 -1
  40. package/lib/esm/services/CliProjectService.js +96 -0
  41. package/lib/esm/services/CliRunScript.js +4 -8
  42. package/lib/esm/services/CliTemplatesService.js +68 -0
  43. package/lib/esm/services/ProjectClient.js +161 -0
  44. package/lib/esm/services/mappers/mapDefaultTemplateOptions.js +30 -0
  45. package/lib/esm/templates/asyncFactory.template.js +38 -0
  46. package/lib/esm/templates/barrels.template.js +22 -0
  47. package/lib/esm/templates/command.template.js +56 -0
  48. package/lib/esm/templates/config.template.js +27 -0
  49. package/lib/esm/templates/controller.template.js +45 -0
  50. package/lib/esm/templates/decorator.template.js +182 -0
  51. package/lib/esm/templates/docker-compose.template.js +25 -0
  52. package/lib/esm/templates/dockerfile.template.js +236 -0
  53. package/lib/esm/templates/exception-filter.template.js +19 -0
  54. package/lib/esm/templates/factory.template.js +37 -0
  55. package/lib/esm/templates/index.command.template.js +18 -0
  56. package/lib/esm/templates/index.config.utils.template.js +17 -0
  57. package/{templates/init/src/controllers/pages/IndexController.ts.hbs → lib/esm/templates/index.controller.template.js} +14 -3
  58. package/lib/esm/templates/index.js +32 -0
  59. package/lib/esm/templates/index.logger.template.js +38 -0
  60. package/{templates/init/src/index.ts.hbs → lib/esm/templates/index.template.js} +17 -5
  61. package/lib/esm/templates/interceptor.template.js +31 -0
  62. package/lib/esm/templates/interface.template.js +13 -0
  63. package/lib/esm/templates/middleware.template.js +34 -0
  64. package/lib/esm/templates/model.template.js +16 -0
  65. package/lib/esm/templates/module.template.js +16 -0
  66. package/lib/esm/templates/pipe.template.js +19 -0
  67. package/lib/esm/templates/pm2.template.js +111 -0
  68. package/lib/esm/templates/prisma.service.template.js +23 -0
  69. package/{templates/init/README.md.hbs → lib/esm/templates/readme.template.js} +28 -13
  70. package/lib/esm/templates/repository.template.js +16 -0
  71. package/lib/esm/templates/response-filter.template.js +19 -0
  72. package/lib/esm/templates/server.template.js +37 -0
  73. package/lib/esm/templates/service.template.js +16 -0
  74. package/lib/esm/templates/tsconfig.spec.template.js +34 -0
  75. package/lib/esm/templates/tsconfig.template.js +31 -0
  76. package/lib/esm/templates/value.template.js +13 -0
  77. package/lib/esm/utils/defineTemplate.js +13 -0
  78. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  79. package/lib/types/commands/add/AddCmd.d.ts +2 -2
  80. package/lib/types/commands/generate/GenerateCmd.d.ts +33 -87
  81. package/lib/types/commands/generate/mappers/mapGenerateContext.d.ts +2 -0
  82. package/lib/types/commands/init/InitCmd.d.ts +18 -20
  83. package/lib/types/commands/init/config/FeaturesPrompt.d.ts +11 -2
  84. package/lib/types/commands/init/mappers/mapToContext.d.ts +2 -2
  85. package/lib/types/commands/init/mappers/mapUniqFeatures.d.ts +1 -1
  86. package/lib/types/commands/init/prompts/getFeaturesPrompt.d.ts +1 -1
  87. package/lib/types/commands/update/UpdateCmd.d.ts +2 -2
  88. package/lib/types/fn/exec.d.ts +1 -0
  89. package/lib/types/fn/render.d.ts +2 -0
  90. package/lib/types/fn/taskOutput.d.ts +1 -0
  91. package/lib/types/index.d.ts +7 -4
  92. package/lib/types/interfaces/AlterGenerateTasks.d.ts +5 -0
  93. package/lib/types/interfaces/AlterInitSubTasks.d.ts +5 -0
  94. package/lib/types/interfaces/AlterPackageJson.d.ts +5 -0
  95. package/lib/types/interfaces/AlterProjectFiles.d.ts +5 -0
  96. package/lib/types/interfaces/AlterRenderFiles.d.ts +10 -0
  97. package/lib/types/interfaces/CliCommandHooks.d.ts +11 -0
  98. package/lib/types/interfaces/GenerateCmdContext.d.ts +19 -0
  99. package/lib/types/interfaces/InitCmdOptions.d.ts +8 -0
  100. package/lib/types/interfaces/PlatformType.d.ts +7 -0
  101. package/lib/types/interfaces/RenderDataContext.d.ts +61 -0
  102. package/lib/types/interfaces/RuntimeTypes.d.ts +8 -0
  103. package/lib/types/interfaces/index.d.ts +9 -0
  104. package/lib/types/pipes/OutputFilePathPipe.d.ts +7 -4
  105. package/lib/types/pipes/{ClassNamePipe.d.ts → SymbolNamePipe.d.ts} +3 -3
  106. package/lib/types/pipes/index.d.ts +1 -1
  107. package/lib/types/platforms/{InitPlatformsModule.d.ts → PlatformsModule.d.ts} +1 -1
  108. package/lib/types/platforms/supports/InitBasePlatform.d.ts +3 -0
  109. package/lib/types/platforms/supports/InitExpressPlatform.d.ts +2 -0
  110. package/lib/types/platforms/supports/InitFastifyPlatform.d.ts +2 -0
  111. package/lib/types/platforms/supports/InitKoaPlatform.d.ts +2 -0
  112. package/lib/types/processors/__fixtures__/createFakeProject.d.ts +5 -0
  113. package/lib/types/processors/transformBinFile.d.ts +3 -0
  114. package/lib/types/processors/transformConfigFile.d.ts +3 -0
  115. package/lib/types/processors/transformIndexFile.d.ts +3 -0
  116. package/lib/types/processors/transformServerFile.d.ts +3 -0
  117. package/lib/types/runtimes/RuntimesModule.d.ts +5 -5
  118. package/lib/types/services/CliProjectService.d.ts +16 -0
  119. package/lib/types/services/CliTemplatesService.d.ts +29 -0
  120. package/lib/types/services/ProjectClient.d.ts +40 -0
  121. package/lib/types/services/mappers/mapDefaultTemplateOptions.d.ts +11 -0
  122. package/lib/types/templates/asyncFactory.template.d.ts +2 -0
  123. package/lib/types/templates/barrels.template.d.ts +2 -0
  124. package/lib/types/templates/command.template.d.ts +2 -0
  125. package/lib/types/templates/config.template.d.ts +2 -0
  126. package/lib/types/templates/controller.template.d.ts +2 -0
  127. package/lib/types/templates/decorator.template.d.ts +2 -0
  128. package/lib/types/templates/docker-compose.template.d.ts +2 -0
  129. package/lib/types/templates/dockerfile.template.d.ts +1 -0
  130. package/lib/types/templates/exception-filter.template.d.ts +2 -0
  131. package/lib/types/templates/factory.template.d.ts +2 -0
  132. package/lib/types/templates/index.command.template.d.ts +2 -0
  133. package/lib/types/templates/index.config.utils.template.d.ts +2 -0
  134. package/lib/types/templates/index.controller.template.d.ts +2 -0
  135. package/lib/types/templates/index.d.ts +31 -0
  136. package/lib/types/templates/index.logger.template.d.ts +2 -0
  137. package/lib/types/templates/index.template.d.ts +2 -0
  138. package/lib/types/templates/interceptor.template.d.ts +2 -0
  139. package/lib/types/templates/interface.template.d.ts +2 -0
  140. package/lib/types/templates/middleware.template.d.ts +2 -0
  141. package/lib/types/templates/model.template.d.ts +2 -0
  142. package/lib/types/templates/module.template.d.ts +2 -0
  143. package/lib/types/templates/pipe.template.d.ts +2 -0
  144. package/lib/types/templates/pm2.template.d.ts +1 -0
  145. package/lib/types/templates/prisma.service.template.d.ts +2 -0
  146. package/lib/types/templates/readme.template.d.ts +2 -0
  147. package/lib/types/templates/repository.template.d.ts +2 -0
  148. package/lib/types/templates/response-filter.template.d.ts +2 -0
  149. package/lib/types/templates/server.template.d.ts +2 -0
  150. package/lib/types/templates/service.template.d.ts +2 -0
  151. package/lib/types/templates/tsconfig.spec.template.d.ts +2 -0
  152. package/lib/types/templates/tsconfig.template.d.ts +2 -0
  153. package/lib/types/templates/value.template.d.ts +2 -0
  154. package/lib/types/utils/defineTemplate.d.ts +39 -0
  155. package/package.json +14 -12
  156. package/templates/tsconfig.node.json +14 -0
  157. package/templates/webpack.config.js +55 -0
  158. package/lib/esm/commands/generate/ProviderTypes.js +0 -103
  159. package/lib/esm/commands/init/interfaces/InitOptions.js +0 -5
  160. package/lib/esm/services/ProvidersInfoService.js +0 -46
  161. package/lib/esm/services/Renderer.js +0 -162
  162. package/lib/esm/utils/fillImports.js +0 -38
  163. package/lib/esm/utils/hbs/array.js +0 -515
  164. package/lib/esm/utils/hbs/collection.js +0 -60
  165. package/lib/esm/utils/hbs/comparison.js +0 -431
  166. package/lib/esm/utils/hbs/index.js +0 -11
  167. package/lib/esm/utils/hbs/object.js +0 -236
  168. package/lib/esm/utils/hbs/switch.js +0 -10
  169. package/lib/esm/utils/renderer/insertAfter.js +0 -12
  170. package/lib/esm/utils/renderer/insertImport.js +0 -11
  171. package/lib/types/commands/generate/ProviderTypes.d.ts +0 -11
  172. package/lib/types/commands/init/interfaces/InitCmdContext.d.ts +0 -6
  173. package/lib/types/commands/init/interfaces/InitOptions.d.ts +0 -20
  174. package/lib/types/services/ProvidersInfoService.d.ts +0 -21
  175. package/lib/types/services/Renderer.d.ts +0 -44
  176. package/lib/types/utils/fillImports.d.ts +0 -1
  177. package/lib/types/utils/hbs/array.d.ts +0 -1
  178. package/lib/types/utils/hbs/collection.d.ts +0 -1
  179. package/lib/types/utils/hbs/comparison.d.ts +0 -1
  180. package/lib/types/utils/hbs/object.d.ts +0 -1
  181. package/lib/types/utils/hbs/switch.d.ts +0 -1
  182. package/lib/types/utils/renderer/insertAfter.d.ts +0 -1
  183. package/lib/types/utils/renderer/insertImport.d.ts +0 -1
  184. package/templates/generate/async.factory.hbs +0 -35
  185. package/templates/generate/command.hbs +0 -45
  186. package/templates/generate/controller.hbs +0 -10
  187. package/templates/generate/decorator.class.hbs +0 -14
  188. package/templates/generate/decorator.endpoint.hbs +0 -15
  189. package/templates/generate/decorator.generic.hbs +0 -19
  190. package/templates/generate/decorator.method.hbs +0 -16
  191. package/templates/generate/decorator.middleware.hbs +0 -26
  192. package/templates/generate/decorator.param.hbs +0 -15
  193. package/templates/generate/decorator.parameters.hbs +0 -9
  194. package/templates/generate/decorator.prop.hbs +0 -14
  195. package/templates/generate/decorator.property.hbs +0 -5
  196. package/templates/generate/exception-filter.hbs +0 -9
  197. package/templates/generate/factory.hbs +0 -11
  198. package/templates/generate/injectable.hbs +0 -6
  199. package/templates/generate/interceptor.hbs +0 -21
  200. package/templates/generate/interface.hbs +0 -3
  201. package/templates/generate/middleware.hbs +0 -9
  202. package/templates/generate/model.hbs +0 -6
  203. package/templates/generate/module.hbs +0 -6
  204. package/templates/generate/pipe.hbs +0 -9
  205. package/templates/generate/prisma.service.hbs +0 -13
  206. package/templates/generate/repository.hbs +0 -6
  207. package/templates/generate/response-filter.hbs +0 -9
  208. package/templates/generate/server/_partials/server-footer.hbs +0 -10
  209. package/templates/generate/server/_partials/server-header.hbs +0 -34
  210. package/templates/generate/server/express/server.hbs +0 -10
  211. package/templates/generate/server/fastify/server.hbs +0 -14
  212. package/templates/generate/server/koa/server.hbs +0 -8
  213. package/templates/generate/service.hbs +0 -6
  214. package/templates/generate/value.hbs +0 -3
  215. package/templates/init/.barrels.json.hbs +0 -9
  216. package/templates/init/.gitignore.hbs +0 -57
  217. package/templates/init/.npmrc.hbs +0 -2
  218. package/templates/init/docker/_partials/docker-body.hbs +0 -5
  219. package/templates/init/docker/_partials/docker-dev-tools.hbs +0 -2
  220. package/templates/init/docker/_partials/docker-header.hbs +0 -16
  221. package/templates/init/docker/bun/Dockerfile.hbs +0 -36
  222. package/templates/init/docker/npm/Dockerfile.hbs +0 -28
  223. package/templates/init/docker/pnpm/Dockerfile.hbs +0 -28
  224. package/templates/init/docker/yarn/Dockerfile.hbs +0 -28
  225. package/templates/init/docker/yarn_berry/Dockerfile.hbs +0 -31
  226. package/templates/init/docker-compose.yml.hbs +0 -14
  227. package/templates/init/pm2/bun/processes.config.cjs.hbs +0 -23
  228. package/templates/init/pm2/node-compiled/processes.config.cjs.hbs +0 -22
  229. package/templates/init/pm2/node-loader/processes.config.cjs.hbs +0 -24
  230. package/templates/init/src/bin/index.ts.hbs +0 -9
  231. package/templates/init/src/config/envs/index.ts.hbs +0 -7
  232. package/templates/init/src/config/index.ts.hbs +0 -38
  233. package/templates/init/src/config/logger/index.ts.hbs +0 -25
  234. package/templates/init/tsconfig.json.hbs +0 -16
  235. package/templates/init/tsconfig.node.json.hbs +0 -20
  236. package/templates/init/tsconfig.spec.json.hbs +0 -25
  237. package/templates/init/webpack.config.js.hbs +0 -65
  238. /package/lib/esm/{commands/init/interfaces/InitCmdContext.js → interfaces/AlterGenerateTasks.js} +0 -0
  239. /package/lib/{types/utils/hbs/index.d.ts → esm/interfaces/AlterInitSubTasks.js} +0 -0
  240. /package/templates/{init/.babelrc.hbs → .babelrc} +0 -0
  241. /package/templates/{init/.dockerignore.hbs → .dockerignore} +0 -0
  242. /package/templates/{init/.swcrc.hbs → .swcrc} +0 -0
  243. /package/templates/{init/.yarnrc.hbs → .yarnrc} +0 -0
  244. /package/templates/{init/nodemon.json.hbs → nodemon.json} +0 -0
  245. /package/templates/{init/tsconfig.base.json.hbs → tsconfig.base.json} +0 -0
  246. /package/templates/{init/views/swagger.ejs.hbs → views/swagger.ejs} +0 -0
@@ -0,0 +1,30 @@
1
+ import { inject, ProjectPackageJson } from "@tsed/cli-core";
2
+ import { normalizePath } from "@tsed/normalize-path";
3
+ import { ProjectConvention } from "../../interfaces/ProjectConvention.js";
4
+ import { OutputFilePathPipe } from "../../pipes/OutputFilePathPipe.js";
5
+ import { SymbolNamePipe } from "../../pipes/SymbolNamePipe.js";
6
+ export function mapDefaultTemplateOptions(opts) {
7
+ const classNamePipe = inject(SymbolNamePipe);
8
+ const outputFilePathPipe = inject(OutputFilePathPipe);
9
+ const projectPackageJson = inject(ProjectPackageJson);
10
+ const { name = "" } = opts;
11
+ let { type = "" } = opts;
12
+ type = type.toLowerCase();
13
+ if (opts.name === "prisma" && opts.name) {
14
+ type = "prisma.service";
15
+ }
16
+ const symbolName = opts.symbolName || classNamePipe.transform({ name, type, format: ProjectConvention.DEFAULT });
17
+ const symbolPath = opts.symbolPath ||
18
+ normalizePath(outputFilePathPipe.transform({
19
+ name,
20
+ type,
21
+ subDir: opts.directory
22
+ }));
23
+ return {
24
+ ...projectPackageJson.fillWithPreferences(opts),
25
+ type,
26
+ symbolName,
27
+ symbolPath,
28
+ symbolPathBasename: opts.symbolPathBasename || normalizePath(classNamePipe.transform({ name, type }))
29
+ };
30
+ }
@@ -0,0 +1,38 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ import { camelCase, pascalCase } from "change-case";
3
+ export default defineTemplate({
4
+ id: "async.factory",
5
+ label: "Async 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(async () => {
27
+ const myConstant = constant<${optName}>("${camelName}");
28
+
29
+ // do something async
30
+ await Promise.resolve();
31
+
32
+ return {};
33
+ })
34
+ .token();
35
+
36
+ export type {{symbolName}} = typeof ${symbolName};`;
37
+ }
38
+ });
@@ -0,0 +1,22 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ import { $alter } from "@tsed/hooks";
3
+ export default defineTemplate({
4
+ id: "barrels",
5
+ label: "Barrels",
6
+ description: "Create barrels files (index.ts) to simplify imports.",
7
+ fileName: ".barrels",
8
+ ext: "json",
9
+ outputDir: ".",
10
+ preserveCase: true,
11
+ prompts() {
12
+ return [];
13
+ },
14
+ render(_, data) {
15
+ const barrels = $alter("$alterBarrels", {
16
+ directory: ["./src/controllers/rest", data.swagger || (data.oidc && "./src/controllers/pages")].filter(Boolean),
17
+ exclude: ["**/__mock__", "**/__mocks__", "**/*.spec.ts"],
18
+ delete: true
19
+ });
20
+ return JSON.stringify(barrels, null, 2);
21
+ }
22
+ });
@@ -0,0 +1,56 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ import { kebabCase } from "change-case";
3
+ export default defineTemplate({
4
+ id: "command",
5
+ label: "Command",
6
+ fileName: "{{symbolName}}.command",
7
+ outputDir: "{{srcDir}}/bin/commands",
8
+ render(symbolName) {
9
+ const symbolParamName = kebabCase(symbolName);
10
+ return `import {Command, CommandProvider, QuestionOptions} from "@tsed/cli-core";
11
+
12
+ export interface ${symbolName}Context {
13
+ }
14
+
15
+ @Command({
16
+ name: "${symbolParamName}",
17
+ description: "Command description",
18
+ args: {
19
+ },
20
+ options: {
21
+ },
22
+ allowUnknownOption: false
23
+ })
24
+ export class ${symbolName} implements CommandProvider {
25
+ /**
26
+ * Ask questions with Inquirer. Return an empty array or don't implement the method to skip this step
27
+ */
28
+ async $prompt(initialOptions: Partial<${symbolName}Context>): Promise<QuestionOptions> {
29
+ return [];
30
+ }
31
+
32
+ /**
33
+ * This method is called after the $prompt to create / map inputs to a proper context for the next step
34
+ */
35
+ $mapContext(ctx: Partial<${symbolName}Context>): ${symbolName}Context {
36
+ return {
37
+ ...ctx
38
+ // map something, based on ctx
39
+ };
40
+ }
41
+ /**
42
+ * This step run your tasks with Listr module
43
+ */
44
+ async $exec(ctx: ${symbolName}Context): Promise<any> {
45
+ return [
46
+ {
47
+ title: "Do something",
48
+ task: () => {
49
+ console.log('HELLO')
50
+ }
51
+ }
52
+ ];
53
+ }
54
+ }`;
55
+ }
56
+ });
@@ -0,0 +1,27 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ export default defineTemplate({
3
+ id: "config",
4
+ label: "Config",
5
+ description: "Create a new config file",
6
+ outputDir: "{{srcDir}}/config",
7
+ fileName: "config",
8
+ hidden: true,
9
+ preserveCase: true,
10
+ render() {
11
+ return `import {readFileSync} from "node:fs";
12
+ import loggerConfig from "./logger/index.js";
13
+
14
+ const pkg = JSON.parse(readFileSync("./package.json", {encoding: "utf8"}));
15
+ /**
16
+ * This is the shared configuration for the application
17
+ */
18
+ export const config: Partial<TsED.Configuration> = {
19
+ version: pkg.version,
20
+ ajv: {
21
+ returnsCoercedValues: true
22
+ },
23
+ logger: loggerConfig
24
+ };
25
+ `;
26
+ }
27
+ });
@@ -0,0 +1,45 @@
1
+ import { defineTemplate } from "../utils/defineTemplate.js";
2
+ import { RoutePipe } from "../pipes/index.js";
3
+ import { CliProjectService } from "../services/CliProjectService.js";
4
+ import { inject } from "@tsed/di";
5
+ export default defineTemplate({
6
+ id: "controller",
7
+ label: "Controller",
8
+ fileName: "{{symbolName}}.controller",
9
+ outputDir: "{{srcDir}}/controllers",
10
+ prompts: (data) => [
11
+ {
12
+ type: "list",
13
+ name: "directory",
14
+ message: "Which directory?",
15
+ when(state) {
16
+ return !!(["controller"].includes(state.type || data.type) || data.directory);
17
+ },
18
+ choices: inject(CliProjectService).getDirectories("controllers")
19
+ },
20
+ {
21
+ type: "input",
22
+ name: "route",
23
+ message: "Which route?",
24
+ when(state) {
25
+ return !!(["controller"].includes(state.type || data.type) || data.route);
26
+ },
27
+ default: (state) => {
28
+ return inject(RoutePipe).transform(data.getName(state));
29
+ }
30
+ }
31
+ ],
32
+ render(symbolName, data) {
33
+ const route = inject(RoutePipe).transform(data.route);
34
+ return `import {Controller} from "@tsed/di";
35
+ import {Get} from "@tsed/schema";
36
+
37
+ @Controller("${route}")
38
+ export class ${symbolName} {
39
+ @Get("/")
40
+ get() {
41
+ return "hello";
42
+ }
43
+ }`;
44
+ }
45
+ });
@@ -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
+ });