@tsed/cli 6.6.3 → 7.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/lib/esm/bin/tsed.js +23 -2
  2. package/lib/esm/commands/add/AddCmd.js +16 -16
  3. package/lib/esm/commands/generate/GenerateCmd.js +72 -224
  4. package/lib/esm/commands/generate/mappers/mapGenerateContext.js +29 -0
  5. package/lib/esm/commands/index.js +2 -1
  6. package/lib/esm/commands/init/InitCmd.js +193 -172
  7. package/lib/esm/commands/init/config/FeaturesPrompt.js +106 -9
  8. package/lib/esm/commands/init/mappers/mapToContext.js +8 -3
  9. package/lib/esm/commands/init/prompts/getFeaturesPrompt.js +0 -12
  10. package/lib/esm/commands/init/utils/hasFeature.js +3 -0
  11. package/lib/esm/commands/run/RunCmd.js +22 -26
  12. package/lib/esm/commands/template/CreateTemplateCommand.js +101 -0
  13. package/lib/esm/commands/update/UpdateCmd.js +9 -13
  14. package/lib/esm/fn/exec.js +5 -0
  15. package/lib/esm/fn/render.js +5 -0
  16. package/lib/esm/fn/taskOutput.js +7 -0
  17. package/lib/esm/index.js +10 -5
  18. package/lib/esm/interfaces/AlterPackageJson.js +1 -0
  19. package/lib/esm/interfaces/AlterProjectFiles.js +1 -0
  20. package/lib/esm/interfaces/AlterRenderFiles.js +1 -0
  21. package/lib/esm/interfaces/CliCommandHooks.js +1 -0
  22. package/lib/esm/interfaces/GenerateCmdContext.js +1 -0
  23. package/lib/esm/interfaces/InitCmdOptions.js +1 -0
  24. package/lib/esm/interfaces/RenderDataContext.js +1 -0
  25. package/lib/esm/interfaces/RuntimeTypes.js +1 -0
  26. package/lib/esm/interfaces/index.js +9 -0
  27. package/lib/esm/pipes/OutputFilePathPipe.js +40 -18
  28. package/lib/esm/pipes/RoutePipe.js +4 -8
  29. package/lib/esm/pipes/{ClassNamePipe.js → SymbolNamePipe.js} +14 -11
  30. package/lib/esm/pipes/index.js +1 -1
  31. package/lib/esm/platforms/{InitPlatformsModule.js → PlatformsModule.js} +4 -10
  32. package/lib/esm/platforms/supports/InitExpressPlatform.js +27 -10
  33. package/lib/esm/platforms/supports/InitFastifyPlatform.js +27 -10
  34. package/lib/esm/platforms/supports/InitKoaPlatform.js +16 -10
  35. package/lib/esm/processors/__fixtures__/createFakeProject.js +35 -0
  36. package/lib/esm/processors/transformBinFile.js +47 -0
  37. package/lib/esm/processors/transformConfigFile.js +105 -0
  38. package/lib/esm/processors/transformIndexFile.js +23 -0
  39. package/lib/esm/processors/transformServerFile.js +60 -0
  40. package/lib/esm/runtimes/RuntimesModule.js +7 -17
  41. package/lib/esm/runtimes/supports/BabelRuntime.js +5 -11
  42. package/lib/esm/runtimes/supports/BunRuntime.js +4 -10
  43. package/lib/esm/runtimes/supports/NodeRuntime.js +1 -1
  44. package/lib/esm/runtimes/supports/WebpackRuntime.js +1 -1
  45. package/lib/esm/services/CliProjectService.js +95 -0
  46. package/lib/esm/services/CliRunScript.js +4 -8
  47. package/lib/esm/services/CliTemplatesService.js +119 -0
  48. package/lib/esm/services/ProjectClient.js +162 -0
  49. package/lib/esm/services/mappers/addContextMethods.js +17 -0
  50. package/lib/esm/services/mappers/mapDefaultTemplateOptions.js +36 -0
  51. package/lib/esm/templates/asyncFactory.template.js +38 -0
  52. package/lib/esm/templates/barrels.template.js +27 -0
  53. package/lib/esm/templates/command.template.js +56 -0
  54. package/lib/esm/templates/config.template.js +27 -0
  55. package/lib/esm/templates/controller.template.js +44 -0
  56. package/lib/esm/templates/decorator.template.js +184 -0
  57. package/lib/esm/templates/docker-compose.template.js +25 -0
  58. package/lib/esm/templates/dockerfile.template.js +236 -0
  59. package/lib/esm/templates/exception-filter.template.js +19 -0
  60. package/lib/esm/templates/factory.template.js +37 -0
  61. package/lib/esm/templates/index.command.template.js +22 -0
  62. package/lib/esm/templates/index.config.utils.template.js +17 -0
  63. package/{templates/init/src/controllers/pages/IndexController.ts.hbs → lib/esm/templates/index.controller.template.js} +14 -3
  64. package/lib/esm/templates/index.js +32 -0
  65. package/lib/esm/templates/index.logger.template.js +41 -0
  66. package/{templates/init/src/index.ts.hbs → lib/esm/templates/index.template.js} +17 -5
  67. package/lib/esm/templates/interceptor.template.js +31 -0
  68. package/lib/esm/templates/interface.template.js +13 -0
  69. package/lib/esm/templates/middleware.template.js +36 -0
  70. package/lib/esm/templates/model.template.js +16 -0
  71. package/lib/esm/templates/module.template.js +16 -0
  72. package/lib/esm/templates/new-template.template.js +67 -0
  73. package/lib/esm/templates/pipe.template.js +19 -0
  74. package/lib/esm/templates/pm2.template.js +111 -0
  75. package/lib/esm/templates/prisma.service.template.js +23 -0
  76. package/{templates/init/README.md.hbs → lib/esm/templates/readme.template.js} +28 -13
  77. package/lib/esm/templates/repository.template.js +16 -0
  78. package/lib/esm/templates/response-filter.template.js +19 -0
  79. package/lib/esm/templates/server.template.js +37 -0
  80. package/lib/esm/templates/service.template.js +16 -0
  81. package/lib/esm/templates/tsconfig.spec.template.js +35 -0
  82. package/lib/esm/templates/value.template.js +13 -0
  83. package/lib/esm/utils/defineTemplate.js +13 -0
  84. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  85. package/lib/types/bin/tsed.d.ts +1 -1
  86. package/lib/types/commands/add/AddCmd.d.ts +2 -2
  87. package/lib/types/commands/generate/GenerateCmd.d.ts +9 -98
  88. package/lib/types/commands/generate/mappers/mapGenerateContext.d.ts +2 -0
  89. package/lib/types/commands/index.d.ts +2 -1
  90. package/lib/types/commands/init/InitCmd.d.ts +18 -20
  91. package/lib/types/commands/init/config/FeaturesPrompt.d.ts +19 -3
  92. package/lib/types/commands/init/mappers/mapToContext.d.ts +2 -2
  93. package/lib/types/commands/init/mappers/mapUniqFeatures.d.ts +1 -1
  94. package/lib/types/commands/init/prompts/getFeaturesPrompt.d.ts +1 -7
  95. package/lib/types/commands/init/utils/hasFeature.d.ts +1 -0
  96. package/lib/types/commands/template/CreateTemplateCommand.d.ts +62 -0
  97. package/lib/types/commands/update/UpdateCmd.d.ts +2 -2
  98. package/lib/types/fn/exec.d.ts +1 -0
  99. package/lib/types/fn/render.d.ts +2 -0
  100. package/lib/types/fn/taskOutput.d.ts +1 -0
  101. package/lib/types/index.d.ts +10 -5
  102. package/lib/types/interfaces/AlterGenerateTasks.d.ts +5 -0
  103. package/lib/types/interfaces/AlterInitSubTasks.d.ts +5 -0
  104. package/lib/types/interfaces/AlterPackageJson.d.ts +5 -0
  105. package/lib/types/interfaces/AlterProjectFiles.d.ts +5 -0
  106. package/lib/types/interfaces/AlterRenderFiles.d.ts +10 -0
  107. package/lib/types/interfaces/CliCommandHooks.d.ts +11 -0
  108. package/lib/types/interfaces/GenerateCmdContext.d.ts +21 -0
  109. package/lib/types/interfaces/InitCmdOptions.d.ts +8 -0
  110. package/lib/types/interfaces/PlatformType.d.ts +7 -0
  111. package/lib/types/interfaces/RenderDataContext.d.ts +62 -0
  112. package/lib/types/interfaces/RuntimeTypes.d.ts +8 -0
  113. package/lib/types/interfaces/index.d.ts +9 -0
  114. package/lib/types/pipes/OutputFilePathPipe.d.ts +7 -4
  115. package/lib/types/pipes/{ClassNamePipe.d.ts → SymbolNamePipe.d.ts} +4 -4
  116. package/lib/types/pipes/index.d.ts +1 -1
  117. package/lib/types/platforms/{InitPlatformsModule.d.ts → PlatformsModule.d.ts} +1 -1
  118. package/lib/types/platforms/supports/InitBasePlatform.d.ts +3 -0
  119. package/lib/types/platforms/supports/InitExpressPlatform.d.ts +2 -0
  120. package/lib/types/platforms/supports/InitFastifyPlatform.d.ts +2 -0
  121. package/lib/types/platforms/supports/InitKoaPlatform.d.ts +2 -0
  122. package/lib/types/processors/__fixtures__/createFakeProject.d.ts +5 -0
  123. package/lib/types/processors/transformBinFile.d.ts +3 -0
  124. package/lib/types/processors/transformConfigFile.d.ts +3 -0
  125. package/lib/types/processors/transformIndexFile.d.ts +3 -0
  126. package/lib/types/processors/transformServerFile.d.ts +3 -0
  127. package/lib/types/runtimes/RuntimesModule.d.ts +5 -5
  128. package/lib/types/services/CliProjectService.d.ts +16 -0
  129. package/lib/types/services/CliTemplatesService.d.ts +35 -0
  130. package/lib/types/services/ProjectClient.d.ts +40 -0
  131. package/lib/types/services/mappers/addContextMethods.d.ts +12 -0
  132. package/lib/types/services/mappers/mapDefaultTemplateOptions.d.ts +11 -0
  133. package/lib/types/templates/asyncFactory.template.d.ts +16 -0
  134. package/lib/types/templates/barrels.template.d.ts +16 -0
  135. package/lib/types/templates/command.template.d.ts +16 -0
  136. package/lib/types/templates/config.template.d.ts +16 -0
  137. package/lib/types/templates/controller.template.d.ts +17 -0
  138. package/lib/types/templates/decorator.template.d.ts +17 -0
  139. package/lib/types/templates/docker-compose.template.d.ts +16 -0
  140. package/lib/types/templates/dockerfile.template.d.ts +1 -0
  141. package/lib/types/templates/exception-filter.template.d.ts +16 -0
  142. package/lib/types/templates/factory.template.d.ts +16 -0
  143. package/lib/types/templates/index.command.template.d.ts +16 -0
  144. package/lib/types/templates/index.config.utils.template.d.ts +16 -0
  145. package/lib/types/templates/index.controller.template.d.ts +16 -0
  146. package/lib/types/templates/index.d.ts +31 -0
  147. package/lib/types/templates/index.logger.template.d.ts +16 -0
  148. package/lib/types/templates/index.template.d.ts +16 -0
  149. package/lib/types/templates/interceptor.template.d.ts +16 -0
  150. package/lib/types/templates/interface.template.d.ts +16 -0
  151. package/lib/types/templates/middleware.template.d.ts +17 -0
  152. package/lib/types/templates/model.template.d.ts +16 -0
  153. package/lib/types/templates/module.template.d.ts +16 -0
  154. package/lib/types/templates/new-template.template.d.ts +9 -0
  155. package/lib/types/templates/pipe.template.d.ts +16 -0
  156. package/lib/types/templates/pm2.template.d.ts +1 -0
  157. package/lib/types/templates/prisma.service.template.d.ts +16 -0
  158. package/lib/types/templates/readme.template.d.ts +16 -0
  159. package/lib/types/templates/repository.template.d.ts +16 -0
  160. package/lib/types/templates/response-filter.template.d.ts +16 -0
  161. package/lib/types/templates/server.template.d.ts +16 -0
  162. package/lib/types/templates/service.template.d.ts +16 -0
  163. package/lib/types/templates/tsconfig.spec.template.d.ts +16 -0
  164. package/lib/types/templates/value.template.d.ts +16 -0
  165. package/lib/types/utils/defineTemplate.d.ts +67 -0
  166. package/package.json +14 -12
  167. package/templates/{init/tsconfig.json.hbs → tsconfig.json} +2 -7
  168. package/templates/tsconfig.node.json +14 -0
  169. package/templates/webpack.config.js +55 -0
  170. package/lib/esm/Cli.js +0 -57
  171. package/lib/esm/commands/generate/ProviderTypes.js +0 -103
  172. package/lib/esm/commands/init/interfaces/InitOptions.js +0 -5
  173. package/lib/esm/services/ProvidersInfoService.js +0 -46
  174. package/lib/esm/services/Renderer.js +0 -162
  175. package/lib/esm/utils/fillImports.js +0 -38
  176. package/lib/esm/utils/hbs/array.js +0 -515
  177. package/lib/esm/utils/hbs/collection.js +0 -60
  178. package/lib/esm/utils/hbs/comparison.js +0 -431
  179. package/lib/esm/utils/hbs/index.js +0 -11
  180. package/lib/esm/utils/hbs/object.js +0 -236
  181. package/lib/esm/utils/hbs/switch.js +0 -10
  182. package/lib/esm/utils/renderer/insertAfter.js +0 -12
  183. package/lib/esm/utils/renderer/insertImport.js +0 -11
  184. package/lib/types/Cli.d.ts +0 -26
  185. package/lib/types/commands/generate/ProviderTypes.d.ts +0 -11
  186. package/lib/types/commands/init/interfaces/InitCmdContext.d.ts +0 -6
  187. package/lib/types/commands/init/interfaces/InitOptions.d.ts +0 -20
  188. package/lib/types/services/ProvidersInfoService.d.ts +0 -21
  189. package/lib/types/services/Renderer.d.ts +0 -44
  190. package/lib/types/utils/fillImports.d.ts +0 -1
  191. package/lib/types/utils/hbs/array.d.ts +0 -1
  192. package/lib/types/utils/hbs/collection.d.ts +0 -1
  193. package/lib/types/utils/hbs/comparison.d.ts +0 -1
  194. package/lib/types/utils/hbs/object.d.ts +0 -1
  195. package/lib/types/utils/hbs/switch.d.ts +0 -1
  196. package/lib/types/utils/renderer/insertAfter.d.ts +0 -1
  197. package/lib/types/utils/renderer/insertImport.d.ts +0 -1
  198. package/templates/generate/async.factory.hbs +0 -35
  199. package/templates/generate/command.hbs +0 -45
  200. package/templates/generate/controller.hbs +0 -10
  201. package/templates/generate/decorator.class.hbs +0 -14
  202. package/templates/generate/decorator.endpoint.hbs +0 -15
  203. package/templates/generate/decorator.generic.hbs +0 -19
  204. package/templates/generate/decorator.method.hbs +0 -16
  205. package/templates/generate/decorator.middleware.hbs +0 -26
  206. package/templates/generate/decorator.param.hbs +0 -15
  207. package/templates/generate/decorator.parameters.hbs +0 -9
  208. package/templates/generate/decorator.prop.hbs +0 -14
  209. package/templates/generate/decorator.property.hbs +0 -5
  210. package/templates/generate/exception-filter.hbs +0 -9
  211. package/templates/generate/factory.hbs +0 -11
  212. package/templates/generate/injectable.hbs +0 -6
  213. package/templates/generate/interceptor.hbs +0 -21
  214. package/templates/generate/interface.hbs +0 -3
  215. package/templates/generate/middleware.hbs +0 -9
  216. package/templates/generate/model.hbs +0 -6
  217. package/templates/generate/module.hbs +0 -6
  218. package/templates/generate/pipe.hbs +0 -9
  219. package/templates/generate/prisma.service.hbs +0 -13
  220. package/templates/generate/repository.hbs +0 -6
  221. package/templates/generate/response-filter.hbs +0 -9
  222. package/templates/generate/server/_partials/server-footer.hbs +0 -10
  223. package/templates/generate/server/_partials/server-header.hbs +0 -34
  224. package/templates/generate/server/express/server.hbs +0 -10
  225. package/templates/generate/server/fastify/server.hbs +0 -14
  226. package/templates/generate/server/koa/server.hbs +0 -8
  227. package/templates/generate/service.hbs +0 -6
  228. package/templates/generate/value.hbs +0 -3
  229. package/templates/init/.barrels.json.hbs +0 -9
  230. package/templates/init/.gitignore.hbs +0 -57
  231. package/templates/init/.npmrc.hbs +0 -2
  232. package/templates/init/docker/_partials/docker-body.hbs +0 -5
  233. package/templates/init/docker/_partials/docker-dev-tools.hbs +0 -2
  234. package/templates/init/docker/_partials/docker-header.hbs +0 -16
  235. package/templates/init/docker/bun/Dockerfile.hbs +0 -36
  236. package/templates/init/docker/npm/Dockerfile.hbs +0 -28
  237. package/templates/init/docker/pnpm/Dockerfile.hbs +0 -28
  238. package/templates/init/docker/yarn/Dockerfile.hbs +0 -28
  239. package/templates/init/docker/yarn_berry/Dockerfile.hbs +0 -31
  240. package/templates/init/docker-compose.yml.hbs +0 -14
  241. package/templates/init/pm2/bun/processes.config.cjs.hbs +0 -23
  242. package/templates/init/pm2/node-compiled/processes.config.cjs.hbs +0 -22
  243. package/templates/init/pm2/node-loader/processes.config.cjs.hbs +0 -24
  244. package/templates/init/src/bin/index.ts.hbs +0 -9
  245. package/templates/init/src/config/envs/index.ts.hbs +0 -7
  246. package/templates/init/src/config/index.ts.hbs +0 -38
  247. package/templates/init/src/config/logger/index.ts.hbs +0 -25
  248. package/templates/init/tsconfig.node.json.hbs +0 -20
  249. package/templates/init/tsconfig.spec.json.hbs +0 -25
  250. package/templates/init/webpack.config.js.hbs +0 -65
  251. /package/lib/esm/{commands/init/interfaces/InitCmdContext.js → interfaces/AlterGenerateTasks.js} +0 -0
  252. /package/lib/{types/utils/hbs/index.d.ts → esm/interfaces/AlterInitSubTasks.js} +0 -0
  253. /package/templates/{init/.babelrc.hbs → .babelrc} +0 -0
  254. /package/templates/{init/.dockerignore.hbs → .dockerignore} +0 -0
  255. /package/templates/{init/.swcrc.hbs → .swcrc} +0 -0
  256. /package/templates/{init/.yarnrc.hbs → .yarnrc} +0 -0
  257. /package/templates/{init/nodemon.json.hbs → nodemon.json} +0 -0
  258. /package/templates/{init/tsconfig.base.json.hbs → tsconfig.base.json} +0 -0
  259. /package/templates/{init/views/swagger.ejs.hbs → views/swagger.ejs} +0 -0
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import "@swc-node/register/esm-register";
2
3
  import { register } from "node:module";
3
4
  import { join } from "node:path";
4
5
  import { pathToFileURL } from "node:url";
@@ -14,8 +15,28 @@ register(pathToFileURL(join(import.meta.dirname, `../loaders/alias.hook.${EXT}`)
14
15
  },
15
16
  transferList: []
16
17
  });
17
- const { Cli } = await import("../Cli.js");
18
- Cli.bootstrap({}).catch((error) => {
18
+ const { commands, CliCore, PKG, TEMPLATE_DIR, ArchitectureConvention, ProjectConvention } = await import("../index.js");
19
+ CliCore.bootstrap({
20
+ name: "tsed",
21
+ pkg: PKG,
22
+ templateDir: TEMPLATE_DIR,
23
+ plugins: true,
24
+ updateNotifier: true,
25
+ checkPrecondition: true,
26
+ commands,
27
+ defaultProjectPreferences() {
28
+ return {
29
+ convention: ProjectConvention.DEFAULT,
30
+ architecture: ArchitectureConvention.DEFAULT
31
+ };
32
+ },
33
+ project: {
34
+ reinstallAfterRun: true
35
+ },
36
+ logger: {
37
+ level: "info"
38
+ }
39
+ }).catch((error) => {
19
40
  console.error(error);
20
41
  process.exit(-1);
21
42
  });
@@ -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,98 @@
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 { CliProjectService } from "../../services/CliProjectService.js";
3
+ import { CliTemplatesService } from "../../services/CliTemplatesService.js";
4
+ import { addContextMethods } from "../../services/mappers/addContextMethods.js";
5
+ import { mapDefaultTemplateOptions } from "../../services/mappers/mapDefaultTemplateOptions.js";
28
6
  const searchFactory = (list) => {
29
- return (state, keyword) => {
7
+ const items = list.map((item) => ({ name: item.label, value: item.id }));
8
+ return (_, keyword) => {
30
9
  if (keyword) {
31
- return list.filter((item) => item.name.toLowerCase().includes(keyword.toLowerCase()));
10
+ return items.filter((item) => item.name.toLowerCase().includes(keyword.toLowerCase()));
32
11
  }
33
- return list;
12
+ return items;
34
13
  };
35
14
  };
36
- let GenerateCmd = GenerateCmd_1 = class GenerateCmd {
37
- constructor(providersList) {
38
- this.providersList = providersList;
39
- this.srcRenderService = inject(SrcRendererService);
15
+ export class GenerateCmd {
16
+ constructor() {
40
17
  this.projectPackageJson = inject(ProjectPackageJson);
41
- PROVIDER_TYPES.forEach((info) => {
42
- this.providersList.add({
43
- ...info
44
- }, GenerateCmd_1);
45
- });
18
+ this.projectService = inject(CliProjectService);
19
+ this.templates = inject(CliTemplatesService);
46
20
  }
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);
21
+ async $prompt(data) {
22
+ data = addContextMethods(data);
23
+ const templates = this.templates.find();
24
+ const templatesPrompts = await Promise.all(templates
25
+ .filter((template) => template.prompts)
26
+ .map((template) => {
27
+ return template.prompts(data);
28
+ }));
50
29
  return [
51
30
  {
52
31
  type: "autocomplete",
53
32
  name: "type",
54
- message: "Which type of provider?",
55
- default: initialOptions.type,
56
- when: () => proposedProviders.length > 1,
57
- source: searchFactory(proposedProviders)
33
+ message: "Which template you want to use?",
34
+ default: data.type,
35
+ when: () => templates.length > 1,
36
+ source: searchFactory(this.templates.find(data.type))
58
37
  },
59
38
  {
60
39
  type: "input",
61
40
  name: "name",
62
41
  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
- }
42
+ default: data.getName,
43
+ when: !data.name
74
44
  },
75
- {
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));
84
- }
85
- },
86
- {
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);
115
- }
116
- }
45
+ ...templatesPrompts.flat()
117
46
  ];
118
47
  }
119
48
  $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
- });
49
+ return mapDefaultTemplateOptions(ctx);
142
50
  }
143
51
  $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
- ];
187
- }
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
52
+ const { symbolPath, type } = ctx;
53
+ return [
54
+ {
55
+ title: `Generate ${ctx.type} file to '${symbolPath}.ts'`,
56
+ skip: !this.templates.get(type),
57
+ task: () => this.projectService.createFromTemplate(type, ctx)
223
58
  },
224
- name: {
225
- description: "Name of the class",
226
- type: String
59
+ {
60
+ title: "Transform generated files",
61
+ task: () => this.projectService.transformFiles(ctx)
227
62
  }
63
+ ];
64
+ }
65
+ }
66
+ command(GenerateCmd, {
67
+ name: "generate",
68
+ alias: "g",
69
+ description: "Generate a new provider class",
70
+ args: {
71
+ type: {
72
+ description: "Type of the provider (Injectable, Controller, Pipe, etc...)",
73
+ type: String
228
74
  },
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
- }
75
+ name: {
76
+ description: "Name of the class",
77
+ type: String
78
+ }
79
+ },
80
+ options: {
81
+ "--route <route>": {
82
+ type: String,
83
+ description: "The route for the controller generated file"
84
+ },
85
+ "-d, --directory <directory>": {
86
+ description: "Directory where the file must be generated",
87
+ type: String
88
+ },
89
+ "-t, --template-type <templateType>": {
90
+ description: "Directory where the file must be generated",
91
+ type: String
92
+ },
93
+ "-m, --middleware-position <templateType>": {
94
+ description: "Middleware position (before, after)",
95
+ type: String
246
96
  }
247
- }),
248
- __metadata("design:paramtypes", [ProvidersInfoService])
249
- ], GenerateCmd);
250
- export { GenerateCmd };
97
+ }
98
+ });
@@ -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
+ }
@@ -2,5 +2,6 @@ import { AddCmd } from "./add/AddCmd.js";
2
2
  import { GenerateCmd } from "./generate/GenerateCmd.js";
3
3
  import { InitCmd } from "./init/InitCmd.js";
4
4
  import { RunCmd } from "./run/RunCmd.js";
5
+ import { CreateTemplateCommand } from "./template/CreateTemplateCommand.js";
5
6
  import { UpdateCmd } from "./update/UpdateCmd.js";
6
- export default [AddCmd, InitCmd, GenerateCmd, UpdateCmd, RunCmd];
7
+ export default [AddCmd, InitCmd, GenerateCmd, UpdateCmd, RunCmd, CreateTemplateCommand];