@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
@@ -1,6 +1,5 @@
1
- import { __decorate } from "tslib";
2
- import { CliPlugins, Command, createSubTasks, inject, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
3
- let AddCmd = class AddCmd {
1
+ import { CliPlugins, command, createSubTasks, inject, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
2
+ export class AddCmd {
4
3
  constructor() {
5
4
  this.cliPlugins = inject(CliPlugins);
6
5
  this.packageJson = inject(ProjectPackageJson);
@@ -34,20 +33,21 @@ let AddCmd = class AddCmd {
34
33
  {
35
34
  title: "Install plugins dependencies",
36
35
  task: createSubTasks(() => this.cliPlugins.addPluginsDependencies(ctx), { ...ctx, concurrent: false })
36
+ },
37
+ {
38
+ title: "Transform files",
39
+ task: createSubTasks(() => this.cliPlugins.addPluginsDependencies(ctx), { ...ctx, concurrent: false })
37
40
  }
38
41
  ];
39
42
  }
40
- };
41
- AddCmd = __decorate([
42
- Command({
43
- name: "add",
44
- description: "Add cli plugin to the current project",
45
- args: {
46
- name: {
47
- description: "Npm package name of the cli plugin",
48
- type: String
49
- }
43
+ }
44
+ command(AddCmd, {
45
+ name: "add",
46
+ description: "Add cli plugin to the current project",
47
+ args: {
48
+ name: {
49
+ description: "Npm package name of the cli plugin",
50
+ type: String
50
51
  }
51
- })
52
- ], AddCmd);
53
- export { AddCmd };
52
+ }
53
+ });
@@ -1,250 +1,101 @@
1
- var GenerateCmd_1;
2
- import { __decorate, __metadata } from "tslib";
3
- import { basename, dirname, join } from "node:path";
4
- import { Command, Inject, inject, ProjectPackageJson } from "@tsed/cli-core";
5
- import { normalizePath } from "@tsed/normalize-path";
6
- import { kebabCase, pascalCase } from "change-case";
7
- import { globbySync } from "globby";
8
- import { ProjectConvention } from "../../interfaces/ProjectConvention.js";
9
- import { ClassNamePipe } from "../../pipes/ClassNamePipe.js";
10
- import { OutputFilePathPipe } from "../../pipes/OutputFilePathPipe.js";
11
- import { RoutePipe } from "../../pipes/RoutePipe.js";
12
- import { ProvidersInfoService } from "../../services/ProvidersInfoService.js";
13
- import { SrcRendererService } from "../../services/Renderer.js";
14
- import { fillImports } from "../../utils/fillImports.js";
15
- import { getFrameworksPrompt } from "../init/prompts/getFeaturesPrompt.js";
16
- import { PROVIDER_TYPES } from "./ProviderTypes.js";
17
- const DECORATOR_TYPES = [
18
- { name: "Class decorator", value: "class" },
19
- { name: "Ts.ED middleware and its decorator", value: "middleware" },
20
- { name: "Ts.ED endpoint decorator", value: "endpoint" },
21
- { name: "Ts.ED property decorator", value: "prop" },
22
- { name: "Ts.ED parameter decorator", value: "param" },
23
- { name: "Vanilla Method decorator", value: "method" },
24
- { name: "Vanilla Property decorator", value: "property" },
25
- { name: "Vanilla Parameter decorator", value: "parameter" },
26
- { name: "Generic decorator", value: "generic" }
27
- ];
1
+ import { command, inject, ProjectPackageJson } from "@tsed/cli-core";
2
+ import { pascalCase } from "change-case";
3
+ import { CliProjectService } from "../../services/CliProjectService.js";
4
+ import { CliTemplatesService } from "../../services/CliTemplatesService.js";
5
+ import { mapDefaultTemplateOptions } from "../../services/mappers/mapDefaultTemplateOptions.js";
28
6
  const searchFactory = (list) => {
29
- return (state, keyword) => {
7
+ return (_, keyword) => {
30
8
  if (keyword) {
31
- return list.filter((item) => item.name.toLowerCase().includes(keyword.toLowerCase()));
9
+ return list.filter((item) => item.label.toLowerCase().includes(keyword.toLowerCase()));
32
10
  }
33
11
  return list;
34
12
  };
35
13
  };
36
- let GenerateCmd = GenerateCmd_1 = class GenerateCmd {
37
- constructor(providersList) {
38
- this.providersList = providersList;
39
- this.srcRenderService = inject(SrcRendererService);
14
+ export class GenerateCmd {
15
+ constructor() {
40
16
  this.projectPackageJson = inject(ProjectPackageJson);
41
- PROVIDER_TYPES.forEach((info) => {
42
- this.providersList.add({
43
- ...info
44
- }, GenerateCmd_1);
45
- });
17
+ this.projectService = inject(CliProjectService);
18
+ this.templates = inject(CliTemplatesService);
46
19
  }
47
- $prompt(initialOptions) {
48
- const getName = (state) => initialOptions.name || pascalCase(state.name || initialOptions.name || state.type || initialOptions.type);
49
- const proposedProviders = this.providersList.findProviders(initialOptions.type);
20
+ async $prompt(data) {
21
+ data.getName = (state) => data.name || pascalCase(state.name || data.name || state.type || data.type || "");
22
+ const templates = this.templates.find();
23
+ const templatesPrompts = await Promise.all(templates
24
+ .filter((template) => template.prompts)
25
+ .map((template) => {
26
+ return template.prompts(data);
27
+ }));
50
28
  return [
51
29
  {
52
30
  type: "autocomplete",
53
31
  name: "type",
54
32
  message: "Which type of provider?",
55
- default: initialOptions.type,
56
- when: () => proposedProviders.length > 1,
57
- source: searchFactory(proposedProviders)
33
+ default: data.type,
34
+ when: () => templates.length > 1,
35
+ source: searchFactory(this.templates.find(data.type))
58
36
  },
59
37
  {
60
38
  type: "input",
61
39
  name: "name",
62
40
  message: "Which name?",
63
- default: getName,
64
- when: !initialOptions.name
65
- },
66
- {
67
- ...getFrameworksPrompt(),
68
- message: "Which platform?",
69
- type: "list",
70
- name: "platform",
71
- when(state) {
72
- return ["server"].includes(state.type || initialOptions.type);
73
- }
41
+ default: data.getName,
42
+ when: !data.name
74
43
  },
44
+ ...templatesPrompts.flat()
45
+ ];
46
+ }
47
+ $mapContext(ctx) {
48
+ return mapDefaultTemplateOptions(ctx);
49
+ }
50
+ $exec(ctx) {
51
+ const { symbolPath, type } = ctx;
52
+ return [
75
53
  {
76
- type: "input",
77
- name: "route",
78
- message: "Which route?",
79
- when(state) {
80
- return !!(["controller", "server"].includes(state.type || initialOptions.type) || initialOptions.route);
81
- },
82
- default: (state) => {
83
- return state.type === "server" ? "/rest" : this.routePipe.transform(getName(state));
54
+ title: `Generate ${ctx.type} file to '${symbolPath}.ts'`,
55
+ skip: !this.templates.get(type),
56
+ task: () => {
57
+ this.projectService.createFromTemplate(type, ctx);
84
58
  }
85
59
  },
86
60
  {
87
- type: "list",
88
- name: "directory",
89
- message: "Which directory?",
90
- when(state) {
91
- return ["controller"].includes(state.type || initialOptions.type) || initialOptions.directory;
92
- },
93
- choices: this.getDirectories("controllers")
94
- },
95
- {
96
- type: "autocomplete",
97
- name: "templateType",
98
- message: (state) => `Which type of ${state.type || initialOptions.type}?`,
99
- when(state) {
100
- return !!(["decorator"].includes(state.type || initialOptions.type) || initialOptions.templateType);
101
- },
102
- source: searchFactory(DECORATOR_TYPES)
103
- },
104
- {
105
- type: "list",
106
- name: "middlewarePosition",
107
- message: () => `The middleware should be called:`,
108
- choices: [
109
- { name: "Before the endpoint", value: "before" },
110
- { name: "After the endpoint", value: "after" }
111
- ],
112
- when(state) {
113
- return !!((["decorator"].includes(state.type || initialOptions.type) && ["middleware"].includes(state.templateType)) ||
114
- initialOptions.middlewarePosition);
61
+ title: "Transform generated files",
62
+ task: () => {
63
+ return this.projectService.transformFiles(ctx);
115
64
  }
116
65
  }
117
66
  ];
118
67
  }
119
- $mapContext(ctx) {
120
- const { name = "" } = ctx;
121
- let { type = "" } = ctx;
122
- type = type.toLowerCase();
123
- if (ctx.name === "prisma" && ctx.name) {
124
- type = "prisma.service";
125
- }
126
- const symbolName = this.classNamePipe.transform({ name, type, format: ProjectConvention.DEFAULT });
127
- const symbolParamName = kebabCase(symbolName);
128
- return fillImports({
129
- ...ctx,
130
- type,
131
- route: ctx.route ? this.routePipe.transform(ctx.route) : "",
132
- symbolName,
133
- symbolParamName,
134
- symbolPath: normalizePath(this.outputFilePathPipe.transform({
135
- name,
136
- type,
137
- subDir: ctx.directory
138
- })),
139
- symbolPathBasename: normalizePath(this.classNamePipe.transform({ name, type })),
140
- platformSymbol: ctx.platform && pascalCase(`Platform ${ctx.platform}`)
141
- });
142
- }
143
- $exec(ctx) {
144
- const { symbolPath } = ctx;
145
- if (this.providersList.isMyProvider(ctx.type, GenerateCmd_1)) {
146
- const type = [ctx.type, ctx.templateType].filter(Boolean).join(".");
147
- let template = `generate/${type}.hbs`;
148
- if (ctx.type === "server") {
149
- template = `generate/server/${ctx.platform}/server.hbs`;
150
- }
151
- return [
152
- {
153
- title: `Generate ${ctx.type} file to '${symbolPath}.ts'`,
154
- task: () => {
155
- if (ctx.type === "server") {
156
- return this.srcRenderService.render(template, ctx, {
157
- baseDir: "generate",
158
- basename: `${symbolPath}.ts`,
159
- replaces: [`server/${ctx.platform}`]
160
- });
161
- }
162
- return this.srcRenderService.render(template, ctx, {
163
- output: `${symbolPath}.ts`
164
- });
165
- }
166
- },
167
- {
168
- title: `Update bin/index`,
169
- skip() {
170
- return ctx.type !== "command";
171
- },
172
- task: () => {
173
- return this.srcRenderService.update("bin/index.ts", [
174
- {
175
- type: "import",
176
- content: `import {${ctx.symbolName}} from "./${basename(symbolPath)}.js";`
177
- },
178
- {
179
- type: "insert-after",
180
- pattern: /commands: \[/,
181
- content: ` ${ctx.symbolName}`
182
- }
183
- ]);
184
- }
185
- }
186
- ];
68
+ }
69
+ command(GenerateCmd, {
70
+ name: "generate",
71
+ alias: "g",
72
+ description: "Generate a new provider class",
73
+ args: {
74
+ type: {
75
+ description: "Type of the provider (Injectable, Controller, Pipe, etc...)",
76
+ type: String
77
+ },
78
+ name: {
79
+ description: "Name of the class",
80
+ type: String
187
81
  }
188
- return [];
189
- }
190
- getDirectories(dir) {
191
- const directories = globbySync("**/*", {
192
- cwd: join(this.srcRenderService.rootDir, dir),
193
- ignore: ["__*"]
194
- });
195
- const set = new Set(directories.map((dir) => {
196
- return dirname(dir);
197
- }));
198
- set.delete(".");
199
- return [...set];
200
- }
201
- };
202
- __decorate([
203
- Inject(),
204
- __metadata("design:type", ClassNamePipe)
205
- ], GenerateCmd.prototype, "classNamePipe", void 0);
206
- __decorate([
207
- Inject(),
208
- __metadata("design:type", OutputFilePathPipe)
209
- ], GenerateCmd.prototype, "outputFilePathPipe", void 0);
210
- __decorate([
211
- Inject(),
212
- __metadata("design:type", RoutePipe)
213
- ], GenerateCmd.prototype, "routePipe", void 0);
214
- GenerateCmd = GenerateCmd_1 = __decorate([
215
- Command({
216
- name: "generate",
217
- alias: "g",
218
- description: "Generate a new provider class",
219
- args: {
220
- type: {
221
- description: "Type of the provider (Injectable, Controller, Pipe, etc...)",
222
- type: String
223
- },
224
- name: {
225
- description: "Name of the class",
226
- type: String
227
- }
82
+ },
83
+ options: {
84
+ "--route <route>": {
85
+ type: String,
86
+ description: "The route for the controller generated file"
228
87
  },
229
- options: {
230
- "--route <route>": {
231
- type: String,
232
- description: "The route for the controller generated file"
233
- },
234
- "-d, --directory <directory>": {
235
- description: "Directory where the file must be generated",
236
- type: String
237
- },
238
- "-t, --template-type <templateType>": {
239
- description: "Directory where the file must be generated",
240
- type: String
241
- },
242
- "-m, --middleware-position <templateType>": {
243
- description: "Middleware position (before, after)",
244
- type: String
245
- }
88
+ "-d, --directory <directory>": {
89
+ description: "Directory where the file must be generated",
90
+ type: String
91
+ },
92
+ "-t, --template-type <templateType>": {
93
+ description: "Directory where the file must be generated",
94
+ type: String
95
+ },
96
+ "-m, --middleware-position <templateType>": {
97
+ description: "Middleware position (before, after)",
98
+ type: String
246
99
  }
247
- }),
248
- __metadata("design:paramtypes", [ProvidersInfoService])
249
- ], GenerateCmd);
250
- export { GenerateCmd };
100
+ }
101
+ });
@@ -0,0 +1,29 @@
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 mapGenerateContext(ctx) {
7
+ const classNamePipe = inject(SymbolNamePipe);
8
+ const outputFilePathPipe = inject(OutputFilePathPipe);
9
+ const projectPackageJson = inject(ProjectPackageJson);
10
+ const { name = "" } = ctx;
11
+ let { type = "" } = ctx;
12
+ type = type.toLowerCase();
13
+ if (ctx.name === "prisma" && ctx.name) {
14
+ type = "prisma.service";
15
+ }
16
+ const symbolName = classNamePipe.transform({ name, type, format: ProjectConvention.DEFAULT });
17
+ const symbolPath = normalizePath(outputFilePathPipe.transform({
18
+ name,
19
+ type,
20
+ subDir: ctx.directory
21
+ }));
22
+ return {
23
+ ...projectPackageJson.fillWithPreferences(ctx),
24
+ type,
25
+ symbolName,
26
+ symbolPath,
27
+ symbolPathBasename: normalizePath(classNamePipe.transform({ name, type }))
28
+ };
29
+ }