@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
@@ -1,7 +1,6 @@
1
- import { __decorate } from "tslib";
2
- import { CliFs, Command, inject, normalizePath, ProjectPackageJson } from "@tsed/cli-core";
1
+ import { CliFs, command, inject, normalizePath, ProjectPackageJson } from "@tsed/cli-core";
3
2
  import { CliRunScript } from "../../services/CliRunScript.js";
4
- let RunCmd = class RunCmd {
3
+ export class RunCmd {
5
4
  constructor() {
6
5
  this.fs = inject(CliFs);
7
6
  this.projectPackageJson = inject(ProjectPackageJson);
@@ -16,26 +15,23 @@ let RunCmd = class RunCmd {
16
15
  });
17
16
  return [];
18
17
  }
19
- };
20
- RunCmd = __decorate([
21
- Command({
22
- name: "run",
23
- description: "Run a project level command",
24
- args: {
25
- command: {
26
- description: "The project command",
27
- type: String,
28
- required: true
29
- }
30
- },
31
- options: {
32
- "-p, --production": {
33
- type: Boolean,
34
- defaultValue: false,
35
- description: "Set production profile to NODE_ENV"
36
- }
37
- },
38
- allowUnknownOption: true
39
- })
40
- ], RunCmd);
41
- export { RunCmd };
18
+ }
19
+ command(RunCmd, {
20
+ name: "run",
21
+ description: "Run a project level command",
22
+ args: {
23
+ command: {
24
+ description: "The project command",
25
+ type: String,
26
+ required: true
27
+ }
28
+ },
29
+ options: {
30
+ "-p, --production": {
31
+ type: Boolean,
32
+ defaultValue: false,
33
+ description: "Set production profile to NODE_ENV"
34
+ }
35
+ },
36
+ allowUnknownOption: true
37
+ });
@@ -1,5 +1,4 @@
1
- import { __decorate } from "tslib";
2
- import { CliPackageJson, Command, createSubTasks, Inject, inject, NpmRegistryClient, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
1
+ import { CliPackageJson, command, createSubTasks, inject, NpmRegistryClient, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
3
2
  import { getValue } from "@tsed/core";
4
3
  import semver from "semver";
5
4
  import { IGNORE_TAGS, IGNORE_VERSIONS, MINIMAL_TSED_VERSION } from "../../constants/index.js";
@@ -14,7 +13,7 @@ function isGreaterThan(a, b) {
14
13
  function shouldUpdate(pkg) {
15
14
  return pkg.includes("@tsed") && !pkg.includes("@tsed/cli") && !pkg.includes("@tsed/logger") && !pkg.includes("@tsed/barrels");
16
15
  }
17
- let UpdateCmd = class UpdateCmd {
16
+ export class UpdateCmd {
18
17
  constructor() {
19
18
  this.npmRegistryClient = inject(NpmRegistryClient);
20
19
  this.projectPackage = inject(ProjectPackageJson);
@@ -97,13 +96,10 @@ let UpdateCmd = class UpdateCmd {
97
96
  }
98
97
  return version && isGreaterThan(version, this.cliPackage.version) ? version : this.cliPackage.version;
99
98
  }
100
- };
101
- UpdateCmd = __decorate([
102
- Command({
103
- name: "update",
104
- description: "Update all Ts.ED packages used by your project",
105
- args: {},
106
- options: {}
107
- })
108
- ], UpdateCmd);
109
- export { UpdateCmd };
99
+ }
100
+ command(UpdateCmd, {
101
+ name: "update",
102
+ description: "Update all Ts.ED packages used by your project",
103
+ args: {},
104
+ options: {}
105
+ });
@@ -0,0 +1,5 @@
1
+ import { CliService } from "@tsed/cli-core";
2
+ import { inject } from "@tsed/di";
3
+ export function exec(command, data) {
4
+ return inject(CliService).getTasks(command, data);
5
+ }
@@ -0,0 +1,5 @@
1
+ import { inject } from "@tsed/di";
2
+ import { CliProjectService } from "../services/CliProjectService.js";
3
+ export function render(id, data) {
4
+ return inject(CliProjectService).createFromTemplate(id, data);
5
+ }
@@ -0,0 +1,7 @@
1
+ import { context } from "@tsed/di";
2
+ export function taskOutput(output) {
3
+ const task = context().get("currentTask");
4
+ if (task) {
5
+ task.output = output;
6
+ }
7
+ }
package/lib/esm/index.js CHANGED
@@ -1,16 +1,19 @@
1
+ import "./templates/index.js";
1
2
  export * from "./Cli.js";
2
3
  export * from "./commands/add/AddCmd.js";
3
4
  export * from "./commands/generate/GenerateCmd.js";
4
5
  export * from "./commands/init/config/FeaturesPrompt.js";
5
6
  export * from "./commands/init/config/FeaturesPrompt.js";
6
7
  export * from "./commands/init/InitCmd.js";
7
- export * from "./commands/init/interfaces/InitCmdContext.js";
8
- export * from "./commands/init/interfaces/InitOptions.js";
9
8
  export * from "./commands/init/prompts/getFeaturesPrompt.js";
10
9
  export * from "./commands/update/UpdateCmd.js";
11
10
  export * from "./constants/index.js";
11
+ export * from "./fn/exec.js";
12
+ export * from "./fn/render.js";
12
13
  export * from "./interfaces/index.js";
13
14
  export * from "./pipes/index.js";
14
15
  export * from "./runtimes/index.js";
15
- export * from "./services/ProvidersInfoService.js";
16
- export * from "./services/Renderer.js";
16
+ export * from "./services/CliProjectService.js";
17
+ export * from "./services/CliTemplatesService.js";
18
+ export * from "./services/ProjectClient.js";
19
+ export * from "./utils/defineTemplate.js";
@@ -0,0 +1 @@
1
+ import { ProjectPackageJson } from "@tsed/cli-core";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import { PackageManager } from "@tsed/cli-core";
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,12 @@
1
+ export * from "./AlterGenerateTasks.js";
2
+ export * from "./AlterInitSubTasks.js";
3
+ export * from "./AlterPackageJson.js";
4
+ export * from "./AlterProjectFiles.js";
5
+ export * from "./AlterRenderFiles.js";
1
6
  export * from "./ArchitectureConvention.js";
7
+ export * from "./CliCommandHooks.js";
8
+ export * from "./GenerateCmdContext.js";
9
+ export * from "./InitCmdOptions.js";
2
10
  export * from "./PlatformType.js";
3
11
  export * from "./ProjectConvention.js";
12
+ export * from "./RenderDataContext.js";
@@ -1,27 +1,49 @@
1
- import { __decorate } from "tslib";
2
- import { dirname, join } from "node:path";
3
- import { inject, Injectable, ProjectPackageJson } from "@tsed/cli-core";
4
- import { Inject } from "@tsed/di";
1
+ import { basename, dirname, join } from "node:path";
2
+ import { inject, injectable, ProjectPackageJson } from "@tsed/cli-core";
3
+ import { constant } from "@tsed/di";
5
4
  import { ArchitectureConvention, ProjectConvention } from "../interfaces/index.js";
6
- import { ProvidersInfoService } from "../services/ProvidersInfoService.js";
7
- import { ClassNamePipe } from "./ClassNamePipe.js";
8
- let OutputFilePathPipe = class OutputFilePathPipe {
5
+ import { CliTemplatesService } from "../services/CliTemplatesService.js";
6
+ import { SymbolNamePipe } from "./SymbolNamePipe.js";
7
+ export class OutputFilePathPipe {
9
8
  constructor() {
10
- this.providers = inject(ProvidersInfoService);
9
+ this.templatesService = inject(CliTemplatesService);
11
10
  this.projectPackageJson = inject(ProjectPackageJson);
12
- this.classNamePipe = inject(ClassNamePipe);
11
+ this.classNamePipe = inject(SymbolNamePipe);
13
12
  }
14
13
  transform(options) {
14
+ const template = this.templatesService.get(options.type);
15
+ const { outputDir, preserveCase, preserveDirectory } = template || {};
16
+ const hasSrcDir = outputDir?.includes("{{srcDir}}");
15
17
  options.format = options.format || this.projectPackageJson.preferences.convention || ProjectConvention.DEFAULT;
16
18
  const featureDir = dirname(options.name);
17
- if (options.type === "server" || this.projectPackageJson.preferences.architecture === ArchitectureConvention.FEATURE) {
18
- return join(options.subDir || "", featureDir, this.classNamePipe.transform(options));
19
+ const baseDir = this.getBaseDir(options.baseDir, outputDir, options.type);
20
+ if (!preserveCase && !preserveDirectory && this.projectPackageJson.preferences.architecture === ArchitectureConvention.FEATURE) {
21
+ return join(hasSrcDir ? constant("project.srcDir", "") : "", options.subDir || "", featureDir, this.classNamePipe.transform(options));
19
22
  }
20
- const baseDir = (options.baseDir || this.providers.get(options.type)?.baseDir || `${options.type}s`).split(":").at(-1);
21
- return join(baseDir, options.subDir || "", featureDir, this.classNamePipe.transform(options));
23
+ return join(hasSrcDir ? constant("project.srcDir", "") : "", baseDir, options.subDir || "", featureDir, this.classNamePipe.transform(options));
22
24
  }
23
- };
24
- OutputFilePathPipe = __decorate([
25
- Injectable()
26
- ], OutputFilePathPipe);
27
- export { OutputFilePathPipe };
25
+ getBaseDir(baseDir, outputDir, type) {
26
+ if (baseDir) {
27
+ return baseDir;
28
+ }
29
+ if (outputDir) {
30
+ return outputDir.replace(/\{\{srcDir}}/, "");
31
+ }
32
+ return `${type}s`.split(":").at(-1) || "";
33
+ }
34
+ getServerName() {
35
+ return basename(`${this.transform({
36
+ name: "Server",
37
+ type: "server",
38
+ format: this.projectPackageJson.preferences.convention
39
+ })}.ts`);
40
+ }
41
+ getIndexControllerName() {
42
+ return basename(`${this.transform({
43
+ name: "Index",
44
+ type: "controller",
45
+ format: this.projectPackageJson.preferences.convention
46
+ })}.ts`);
47
+ }
48
+ }
49
+ injectable(OutputFilePathPipe);
@@ -1,7 +1,6 @@
1
- import { __decorate } from "tslib";
2
- import { Injectable } from "@tsed/cli-core";
1
+ import { injectable } from "@tsed/cli-core";
3
2
  import { kebabCase } from "change-case";
4
- let RoutePipe = class RoutePipe {
3
+ export class RoutePipe {
5
4
  transform(route) {
6
5
  const r = route
7
6
  .split("/")
@@ -15,8 +14,5 @@ let RoutePipe = class RoutePipe {
15
14
  .join("/");
16
15
  return `/${r}`.replace(/\/\//gi, "/");
17
16
  }
18
- };
19
- RoutePipe = __decorate([
20
- Injectable()
21
- ], RoutePipe);
22
- export { RoutePipe };
17
+ }
18
+ injectable(RoutePipe);
@@ -1,18 +1,24 @@
1
- import { __decorate } from "tslib";
2
1
  import { basename } from "node:path";
3
2
  import { ProjectPackageJson } from "@tsed/cli-core";
4
- import { inject, Injectable } from "@tsed/di";
3
+ import { inject, injectable } from "@tsed/di";
5
4
  import { kebabCase, pascalCase } from "change-case";
6
5
  import { ProjectConvention } from "../interfaces/ProjectConvention.js";
7
- import { ProvidersInfoService } from "../services/ProvidersInfoService.js";
8
- let ClassNamePipe = class ClassNamePipe {
6
+ import { CliTemplatesService } from "../services/CliTemplatesService.js";
7
+ export class SymbolNamePipe {
9
8
  constructor() {
10
- this.providers = inject(ProvidersInfoService);
11
9
  this.projectPackageJson = inject(ProjectPackageJson);
10
+ this.templates = inject(CliTemplatesService);
12
11
  }
13
12
  transform(options) {
13
+ if (options.name === "index") {
14
+ return options.name;
15
+ }
14
16
  const format = options.format || this.projectPackageJson.preferences.convention || ProjectConvention.DEFAULT;
15
- const meta = this.providers.get(options.type)?.model || "{{symbolName}}.{{symbolType}}?";
17
+ const template = this.templates.get(options.type);
18
+ if (template?.preserveCase) {
19
+ return template.fileName || options.name;
20
+ }
21
+ const meta = template?.fileName || "{{symbolName}}.{{symbolType}}?";
16
22
  const type = options.type.split(":").at(-1);
17
23
  const symbolName = kebabCase(basename(options.name)).replace(`-${type}`, "");
18
24
  const names = meta.split(".").reduce((acc, key) => {
@@ -29,8 +35,5 @@ let ClassNamePipe = class ClassNamePipe {
29
35
  }
30
36
  return [...names].join(".").toLowerCase();
31
37
  }
32
- };
33
- ClassNamePipe = __decorate([
34
- Injectable()
35
- ], ClassNamePipe);
36
- export { ClassNamePipe };
38
+ }
39
+ injectable(SymbolNamePipe);
@@ -1,3 +1,3 @@
1
- export * from "./ClassNamePipe.js";
2
1
  export * from "./OutputFilePathPipe.js";
3
2
  export * from "./RoutePipe.js";
3
+ export * from "./SymbolNamePipe.js";
@@ -1,20 +1,14 @@
1
- import { __decorate } from "tslib";
2
1
  import { injectMany } from "@tsed/cli-core";
3
- import { Module } from "@tsed/di";
2
+ import { injectable } from "@tsed/di";
4
3
  import { InitExpressPlatform } from "./supports/InitExpressPlatform.js";
5
4
  import { InitFastifyPlatform } from "./supports/InitFastifyPlatform.js";
6
5
  import { InitKoaPlatform } from "./supports/InitKoaPlatform.js";
7
- let InitPlatformsModule = class InitPlatformsModule {
6
+ export class PlatformsModule {
8
7
  constructor() {
9
8
  this.platforms = injectMany("platform:init");
10
9
  }
11
10
  get(name) {
12
11
  return this.platforms.find((platform) => platform.name === name);
13
12
  }
14
- };
15
- InitPlatformsModule = __decorate([
16
- Module({
17
- imports: [InitExpressPlatform, InitKoaPlatform, InitFastifyPlatform]
18
- })
19
- ], InitPlatformsModule);
20
- export { InitPlatformsModule };
13
+ }
14
+ injectable(PlatformsModule).imports([InitExpressPlatform, InitKoaPlatform, InitFastifyPlatform]);
@@ -1,9 +1,31 @@
1
- import { __decorate } from "tslib";
2
- import { Injectable } from "@tsed/cli-core";
3
- let InitExpressPlatform = class InitExpressPlatform {
1
+ import { injectable } from "@tsed/cli-core";
2
+ import { ts } from "ts-morph";
3
+ var SyntaxKind = ts.SyntaxKind;
4
+ export class InitExpressPlatform {
4
5
  constructor() {
5
6
  this.name = "express";
6
7
  }
8
+ alterProjectFiles(project) {
9
+ const options = project.findConfiguration("server");
10
+ if (options) {
11
+ const middlewares = [
12
+ "cors",
13
+ "cookie-parser",
14
+ "compression",
15
+ "method-override",
16
+ "json-parser",
17
+ {
18
+ use: "urlencoded-parser",
19
+ options: { extended: true }
20
+ }
21
+ ];
22
+ project.getPropertyAssignment(options, {
23
+ name: "middlewares",
24
+ kind: SyntaxKind.ArrayLiteralExpression,
25
+ initializer: JSON.stringify(middlewares, null, 2)
26
+ });
27
+ }
28
+ }
7
29
  dependencies(ctx) {
8
30
  return {
9
31
  "@tsed/platform-express": ctx.tsedVersion,
@@ -24,10 +46,5 @@ let InitExpressPlatform = class InitExpressPlatform {
24
46
  "@types/method-override": "latest"
25
47
  };
26
48
  }
27
- };
28
- InitExpressPlatform = __decorate([
29
- Injectable({
30
- type: "platform:init"
31
- })
32
- ], InitExpressPlatform);
33
- export { InitExpressPlatform };
49
+ }
50
+ injectable(InitExpressPlatform).type("platform:init");
@@ -1,9 +1,31 @@
1
- import { __decorate } from "tslib";
2
- import { Injectable } from "@tsed/cli-core";
3
- let InitFastifyPlatform = class InitFastifyPlatform {
1
+ import { injectable } from "@tsed/cli-core";
2
+ import { SyntaxKind } from "ts-morph";
3
+ export class InitFastifyPlatform {
4
4
  constructor() {
5
5
  this.name = "fastify";
6
6
  }
7
+ alterProjectFiles(project) {
8
+ const options = project.findConfiguration("server");
9
+ if (options) {
10
+ const plugins = [
11
+ "@fastify/accepts",
12
+ "@fastify/cookie",
13
+ {
14
+ use: "fastify-raw-body",
15
+ options: {
16
+ global: false,
17
+ runFirst: true
18
+ }
19
+ },
20
+ "@fastify/formbody"
21
+ ];
22
+ project.getPropertyAssignment(options, {
23
+ name: "plugins",
24
+ kind: SyntaxKind.ArrayLiteralExpression,
25
+ initializer: JSON.stringify(plugins, null, 2)
26
+ });
27
+ }
28
+ }
7
29
  dependencies(ctx) {
8
30
  return {
9
31
  "@tsed/platform-fastify": ctx.tsedVersion,
@@ -22,10 +44,5 @@ let InitFastifyPlatform = class InitFastifyPlatform {
22
44
  "@types/content-disposition": "latest"
23
45
  };
24
46
  }
25
- };
26
- InitFastifyPlatform = __decorate([
27
- Injectable({
28
- type: "platform:init"
29
- })
30
- ], InitFastifyPlatform);
31
- export { InitFastifyPlatform };
47
+ }
48
+ injectable(InitFastifyPlatform).type("platform:init");
@@ -1,9 +1,20 @@
1
- import { __decorate } from "tslib";
2
- import { Injectable } from "@tsed/cli-core";
3
- let InitKoaPlatform = class InitKoaPlatform {
1
+ import { injectable } from "@tsed/cli-core";
2
+ import { SyntaxKind } from "ts-morph";
3
+ export class InitKoaPlatform {
4
4
  constructor() {
5
5
  this.name = "koa";
6
6
  }
7
+ alterProjectFiles(project) {
8
+ const options = project.findConfiguration("server");
9
+ if (options) {
10
+ const middlewares = ["@koa/cors", "koa-compress", "koa-override", "koa-bodyparser"];
11
+ project.getPropertyAssignment(options, {
12
+ name: "middlewares",
13
+ kind: SyntaxKind.ArrayLiteralExpression,
14
+ initializer: JSON.stringify(middlewares, null, 2)
15
+ });
16
+ }
17
+ }
7
18
  dependencies(ctx) {
8
19
  return {
9
20
  "@tsed/platform-koa": ctx.tsedVersion,
@@ -28,10 +39,5 @@ let InitKoaPlatform = class InitKoaPlatform {
28
39
  "@types/koa__cors": "latest"
29
40
  };
30
41
  }
31
- };
32
- InitKoaPlatform = __decorate([
33
- Injectable({
34
- type: "platform:init"
35
- })
36
- ], InitKoaPlatform);
37
- export { InitKoaPlatform };
42
+ }
43
+ injectable(InitKoaPlatform).type("platform:init");
@@ -0,0 +1,35 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "path";
3
+ import { ProjectConvention } from "../../interfaces/ProjectConvention.js";
4
+ import { ProjectClient } from "../../services/ProjectClient.js";
5
+ const root = join(import.meta.dirname, "../../../templates/init");
6
+ const mockDir = join(import.meta.dirname, "__mock__");
7
+ export function createFakeProject({ convention = ProjectConvention.DEFAULT }) {
8
+ const project = new ProjectClient({
9
+ fileSystem: undefined,
10
+ useInMemoryFileSystem: true,
11
+ rootDir: "/"
12
+ });
13
+ const indexContent = readFileSync(join(root, "src/index.ts"), { encoding: "utf8" });
14
+ project.createSourceFile("src/index.ts", indexContent, {
15
+ overwrite: true
16
+ });
17
+ const serverPath = convention === ProjectConvention.DEFAULT ? "src/Server.ts" : "src/server.ts";
18
+ const serverContent = readFileSync(join(root, "src/server.ts"), "utf8");
19
+ project.createSourceFile(serverPath, serverContent, {
20
+ overwrite: true
21
+ });
22
+ const configContent = readFileSync(join(root, "src/config/config.ts"), "utf8");
23
+ project.createSourceFile("src/config/config.ts", configContent, {
24
+ overwrite: true
25
+ });
26
+ const binContent = readFileSync(join(root, "src/bin/index.ts"), "utf8");
27
+ project.createSourceFile("src/bin/index.ts", binContent, {
28
+ overwrite: true
29
+ });
30
+ const commandContent = readFileSync(join(mockDir, "TestCommand.ts"), "utf8");
31
+ project.createSourceFile("src/bin/commands/TestCommand.ts", commandContent, {
32
+ overwrite: true
33
+ });
34
+ return project;
35
+ }
@@ -0,0 +1,47 @@
1
+ import { dirname, join, relative } from "node:path";
2
+ import { normalizePath } from "@tsed/normalize-path";
3
+ import { SyntaxKind } from "ts-morph";
4
+ export function transformBinFile(project, data) {
5
+ const binSourceFile = project.binSourceFile;
6
+ const options = project.findConfiguration("bin");
7
+ if (!binSourceFile || !options) {
8
+ return;
9
+ }
10
+ // list all commands in the bin/commands directory
11
+ const files = project.fs.globSync([normalizePath(project.rootDir, "src/bin/commands/*.ts")]);
12
+ const commands = files
13
+ .map((file) => {
14
+ const source = project.getSourceFile(file);
15
+ if (!source) {
16
+ return undefined;
17
+ }
18
+ const command = source?.getClasses().find((cls) => {
19
+ return cls.getDecorators().some((decorator) => {
20
+ return decorator.getName() === "Command" && decorator.getArguments().length > 0;
21
+ });
22
+ });
23
+ return command ? { command, file: source.getFilePath() } : undefined;
24
+ })
25
+ .filter((f) => f !== undefined)
26
+ .map(({ file, command }) => {
27
+ binSourceFile.addImportDeclaration({
28
+ moduleSpecifier: "./" + relative(dirname(binSourceFile.getFilePath()), file).replace(".ts", ".js"),
29
+ namedImports: [command.getName()]
30
+ });
31
+ return command.getName();
32
+ })
33
+ .sort();
34
+ const list = project.getPropertyAssignment(options, {
35
+ name: "commands",
36
+ kind: SyntaxKind.ArrayLiteralExpression,
37
+ initializer: "[]"
38
+ });
39
+ const existingElements = list.getElements();
40
+ commands
41
+ .filter((command) => {
42
+ return !existingElements.some((element) => element.getText() === command);
43
+ })
44
+ .forEach((command) => {
45
+ list.addElement(command);
46
+ });
47
+ }