@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,35 +1,36 @@
1
- import { __decorate } from "tslib";
2
1
  import { basename, join } from "node:path";
3
- import { CliExeca, CliFs, CliLoadFile, cliPackageJson, CliPlugins, CliService, Command, Configuration, createSubTasks, createTasksRunner, inject, PackageManager, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
4
- import { kebabCase, pascalCase } from "change-case";
5
- import { DEFAULT_TSED_TAGS } from "../../constants/index.js";
2
+ import { CliExeca, CliFs, CliLoadFile, cliPackageJson, CliPlugins, command, Configuration, createSubTasks, createTasksRunner, inject, PackageManager, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
3
+ import { isString } from "@tsed/core";
4
+ import { constant } from "@tsed/di";
5
+ import { $asyncAlter } from "@tsed/hooks";
6
+ import { kebabCase } from "change-case";
7
+ import { DEFAULT_TSED_TAGS, TEMPLATE_DIR } from "../../constants/index.js";
8
+ import { exec } from "../../fn/exec.js";
9
+ import { render } from "../../fn/render.js";
10
+ import { taskOutput } from "../../fn/taskOutput.js";
6
11
  import { ArchitectureConvention } from "../../interfaces/ArchitectureConvention.js";
7
12
  import { PlatformType } from "../../interfaces/index.js";
8
13
  import { ProjectConvention } from "../../interfaces/ProjectConvention.js";
9
- import { OutputFilePathPipe } from "../../pipes/OutputFilePathPipe.js";
10
- import { InitPlatformsModule } from "../../platforms/InitPlatformsModule.js";
14
+ import { PlatformsModule } from "../../platforms/PlatformsModule.js";
11
15
  import { RuntimesModule } from "../../runtimes/RuntimesModule.js";
12
16
  import { BunRuntime } from "../../runtimes/supports/BunRuntime.js";
13
17
  import { NodeRuntime } from "../../runtimes/supports/NodeRuntime.js";
14
- import { RootRendererService } from "../../services/Renderer.js";
15
- import { fillImports } from "../../utils/fillImports.js";
18
+ import { CliProjectService } from "../../services/CliProjectService.js";
16
19
  import { FeaturesMap, FeatureType } from "./config/FeaturesPrompt.js";
17
20
  import { InitFileSchema } from "./config/InitFileSchema.js";
18
21
  import { mapToContext } from "./mappers/mapToContext.js";
19
22
  import { getFeaturesPrompt } from "./prompts/getFeaturesPrompt.js";
20
- let InitCmd = class InitCmd {
23
+ export class InitCmd {
21
24
  constructor() {
22
25
  this.configuration = inject(Configuration);
23
26
  this.cliPlugins = inject(CliPlugins);
24
27
  this.packageJson = inject(ProjectPackageJson);
25
28
  this.packageManagers = inject(PackageManagersModule);
26
29
  this.runtimes = inject(RuntimesModule);
27
- this.platforms = inject(InitPlatformsModule);
30
+ this.platforms = inject(PlatformsModule);
28
31
  this.cliPackageJson = cliPackageJson();
29
- this.cliService = inject(CliService);
30
32
  this.cliLoadFile = inject(CliLoadFile);
31
- this.rootRenderer = inject(RootRendererService);
32
- this.outputFilePathPipe = inject(OutputFilePathPipe);
33
+ this.project = inject(CliProjectService);
33
34
  this.execa = inject(CliExeca);
34
35
  this.fs = inject(CliFs);
35
36
  }
@@ -101,29 +102,28 @@ let InitCmd = class InitCmd {
101
102
  this.packageManagers.list().forEach((key) => {
102
103
  ctx[key] = ctx.packageManager === key;
103
104
  });
104
- return fillImports({
105
+ return {
105
106
  ...ctx,
106
- entryServer: ctx.convention !== ProjectConvention.ANGULAR ? "Server" : "server",
107
107
  cliVersion: ctx.cliVersion || this.cliPackageJson.version,
108
- srcDir: this.configuration.project?.srcDir,
109
- platformSymbol: ctx.platform && pascalCase(`Platform ${ctx.platform}`)
110
- });
108
+ srcDir: constant("project.srcDir", "src")
109
+ };
111
110
  }
112
111
  async $beforeExec(ctx) {
113
112
  this.fs.ensureDirSync(this.packageJson.dir);
114
- this.packageJson.name = ctx.projectName;
113
+ ctx.projectName && (this.packageJson.name = ctx.projectName);
115
114
  ctx.packageManager && this.packageJson.setPreference("packageManager", ctx.packageManager);
116
115
  ctx.runtime && this.packageJson.setPreference("runtime", ctx.runtime);
117
116
  ctx.architecture && this.packageJson.setPreference("architecture", ctx.architecture);
118
117
  ctx.convention && this.packageJson.setPreference("convention", ctx.convention);
118
+ ctx.platform && this.packageJson.setPreference("platform", ctx.convention);
119
119
  ctx.GH_TOKEN && this.packageJson.setGhToken(ctx.GH_TOKEN);
120
120
  await createTasksRunner([
121
121
  {
122
122
  title: "Write RC files",
123
123
  skip: () => !ctx.GH_TOKEN,
124
- task: () => this.rootRenderer.renderAll(["/init/.npmrc.hbs", "/init/.yarnrc.hbs"], ctx, {
125
- baseDir: "/init"
126
- })
124
+ task: () => {
125
+ return Promise.all([render(".npmrc", ctx), render(".yarnrc", ctx)]);
126
+ }
127
127
  },
128
128
  {
129
129
  title: "Initialize package.json",
@@ -151,39 +151,52 @@ let InitCmd = class InitCmd {
151
151
  }
152
152
  async $exec(ctx) {
153
153
  this.checkPrecondition(ctx);
154
- const subTasks = [
155
- ...(await this.cliService.getTasks("generate", {
156
- ...ctx,
157
- type: "server",
158
- name: "Server",
159
- route: "/rest"
160
- })),
161
- ...(await this.cliService.getTasks("generate", {
162
- type: "controller",
163
- route: "hello-world",
164
- name: "HelloWorld",
165
- directory: "rest"
166
- })),
167
- ...(ctx.commands
168
- ? await this.cliService.getTasks("generate", {
169
- type: "command",
170
- route: "hello",
171
- name: "hello"
172
- })
173
- : [])
174
- ];
154
+ const runtime = this.runtimes.get();
155
+ ctx = {
156
+ ...ctx,
157
+ node: runtime instanceof NodeRuntime,
158
+ bun: runtime instanceof BunRuntime,
159
+ compiled: runtime instanceof NodeRuntime && runtime.isCompiled()
160
+ };
175
161
  return [
176
162
  {
177
- title: "Generate project files",
178
- task: createSubTasks([
179
- {
180
- title: "Root files",
181
- task: () => {
182
- return this.generateFiles(ctx);
183
- }
184
- },
185
- ...subTasks
186
- ], { ...ctx, concurrent: false })
163
+ title: "Render base files",
164
+ task: () => this.renderFiles(ctx)
165
+ },
166
+ {
167
+ title: "Alter package json",
168
+ task: () => {
169
+ return $asyncAlter("$alterPackageJson", this.packageJson, [ctx]);
170
+ }
171
+ },
172
+ {
173
+ title: "Generate additional project files",
174
+ task: createSubTasks(async () => {
175
+ const subTasks = [
176
+ ...(await exec("generate", {
177
+ //...ctx,
178
+ type: "controller",
179
+ route: "rest",
180
+ name: "HelloWorld",
181
+ directory: "rest"
182
+ })),
183
+ ...(ctx.commands
184
+ ? await exec("generate", {
185
+ //...ctx,
186
+ type: "command",
187
+ route: "hello",
188
+ name: "hello"
189
+ })
190
+ : [])
191
+ ];
192
+ return $asyncAlter("$alterInitSubTasks", subTasks, [ctx]);
193
+ }, { ...ctx, concurrent: false })
194
+ },
195
+ {
196
+ title: "transform generated files to the project configuration",
197
+ task: async () => {
198
+ return this.project.transformFiles(ctx);
199
+ }
187
200
  }
188
201
  ];
189
202
  }
@@ -227,6 +240,7 @@ let InitCmd = class InitCmd {
227
240
  "@tsed/core": ctx.tsedVersion,
228
241
  "@tsed/di": ctx.tsedVersion,
229
242
  "@tsed/ajv": ctx.tsedVersion,
243
+ "@tsed/config": ctx.tsedVersion,
230
244
  "@tsed/exceptions": ctx.tsedVersion,
231
245
  "@tsed/schema": ctx.tsedVersion,
232
246
  "@tsed/json-mapper": ctx.tsedVersion,
@@ -245,9 +259,6 @@ let InitCmd = class InitCmd {
245
259
  "@tsed/barrels": "latest",
246
260
  ajv: "latest",
247
261
  "cross-env": "latest",
248
- dotenv: "latest",
249
- "dotenv-expand": "latest",
250
- "dotenv-flow": "latest",
251
262
  ...this.runtimes.get().dependencies(),
252
263
  ...this.platforms.get(ctx.platform).dependencies(ctx)
253
264
  });
@@ -262,7 +273,7 @@ let InitCmd = class InitCmd {
262
273
  }, ctx);
263
274
  }
264
275
  addFeatures(ctx) {
265
- ctx.features.forEach((value) => {
276
+ ctx.features?.forEach((value) => {
266
277
  const feature = FeaturesMap[value.toLowerCase()];
267
278
  if (feature) {
268
279
  if (feature.dependencies) {
@@ -273,128 +284,136 @@ let InitCmd = class InitCmd {
273
284
  }
274
285
  }
275
286
  });
276
- if (ctx.features.find((value) => value === FeatureType.GRAPHQL)) {
287
+ if (ctx.features?.find((value) => value === FeatureType.GRAPHQL)) {
277
288
  this.packageJson.addDependencies({
278
289
  [`apollo-server-${ctx.platform}`]: "2.25.2"
279
290
  }, ctx);
280
291
  }
281
292
  }
282
- generateFiles(ctx) {
283
- const indexCtrlBaseName = basename(`${this.outputFilePathPipe.transform({
284
- name: "Index",
285
- type: "controller",
286
- format: ctx.convention
287
- })}.ts`);
288
- const runtime = this.runtimes.get();
289
- const packageManager = this.packageManagers.get();
290
- ctx = {
291
- ...ctx,
292
- node: runtime instanceof NodeRuntime,
293
- bun: runtime instanceof BunRuntime,
294
- compiled: runtime instanceof NodeRuntime && runtime.isCompiled()
295
- };
293
+ async baseFiles(ctx) {
294
+ const packageManager = inject(PackageManagersModule).get();
296
295
  const pm2 = ctx.bun ? "bun" : ctx.compiled ? "node-compiled" : "node-loader";
297
- return this.rootRenderer.renderAll([
298
- ...runtime.files(),
299
- "/init/.dockerignore.hbs",
300
- "/init/.gitignore.hbs",
301
- "/init/.barrels.json.hbs",
302
- {
303
- path: `/init/pm2/${pm2}/processes.config.cjs.hbs`,
304
- output: `processes.config.cjs`,
305
- replaces: [`pm2/${pm2}`]
306
- },
307
- "/init/docker-compose.yml.hbs",
308
- {
309
- path: `/init/docker/${packageManager.name}/Dockerfile.hbs`,
310
- output: `Dockerfile`,
311
- replaces: [`docker/${packageManager.name}`]
312
- },
313
- "/init/README.md.hbs",
314
- "/init/tsconfig.json.hbs",
315
- "/init/tsconfig.base.json.hbs",
316
- "/init/tsconfig.node.json.hbs",
317
- ctx.testing && "/init/tsconfig.spec.json.hbs",
318
- "/init/src/index.ts.hbs",
319
- "/init/src/config/envs/index.ts.hbs",
320
- "/init/src/config/logger/index.ts.hbs",
321
- "/init/src/config/index.ts.hbs",
322
- ctx.commands && "/init/src/bin/index.ts.hbs",
323
- ctx.swagger && "/init/views/swagger.ejs.hbs",
324
- ctx.swagger && {
325
- path: "/init/src/controllers/pages/IndexController.ts.hbs",
326
- basename: indexCtrlBaseName,
327
- replaces: [ctx.architecture === ArchitectureConvention.FEATURE ? "controllers" : null]
328
- }
329
- ].filter(Boolean), ctx, {
330
- baseDir: "/init"
296
+ const runtimes = inject(RuntimesModule);
297
+ const runtime = runtimes.get();
298
+ // files with higher priority
299
+ const promises = [
300
+ "tsconfig.base.json",
301
+ "tsconfig.config.json",
302
+ "tsconfig.spec.json",
303
+ "tsconfig.node.json",
304
+ "docker-compose.yml",
305
+ `dockerfile.${packageManager.name}`,
306
+ ".dockerignore",
307
+ ".gitignore",
308
+ "server",
309
+ "config",
310
+ "index",
311
+ "index.config.util",
312
+ "index.logger",
313
+ "index.controller",
314
+ "barrels",
315
+ "readme",
316
+ `pm2.${pm2}`,
317
+ ctx.swagger && "/views/swagger.ejs",
318
+ ...runtime.files()
319
+ ].map((id) => {
320
+ return id && render(id, ctx);
331
321
  });
322
+ await Promise.all(promises);
332
323
  }
333
- };
334
- InitCmd = __decorate([
335
- Command({
336
- name: "init",
337
- description: "Init a new Ts.ED project",
338
- args: {
339
- root: {
340
- type: String,
341
- defaultValue: ".",
342
- description: "Root directory to initialize the Ts.ED project"
324
+ async renderFiles(ctx) {
325
+ // base files
326
+ let startTime = Date.now();
327
+ await this.baseFiles(ctx);
328
+ taskOutput(`Base files rendered (${Date.now() - startTime}ms)`);
329
+ const files = await $asyncAlter("$alterRenderFiles", [], [ctx]);
330
+ startTime = Date.now();
331
+ const promises = files.map((option) => {
332
+ if (!option) {
333
+ return;
343
334
  }
344
- },
345
- options: {
346
- "-n, --project-name <projectName>": {
347
- type: String,
348
- defaultValue: "",
349
- description: "Set the project name. By default, the project is the same as the name directory."
350
- },
351
- "-a, --arch <architecture>": {
352
- type: String,
353
- defaultValue: ArchitectureConvention.DEFAULT,
354
- description: `Set the default architecture convention (${ArchitectureConvention.DEFAULT} or ${ArchitectureConvention.FEATURE})`
355
- },
356
- "-c, --convention <convention>": {
357
- type: String,
358
- defaultValue: ProjectConvention.DEFAULT,
359
- description: `Set the default project convention (${ArchitectureConvention.DEFAULT} or ${ArchitectureConvention.FEATURE})`
360
- },
361
- "-p, --platform <platform>": {
362
- type: String,
363
- defaultValue: PlatformType.EXPRESS,
364
- description: "Set the default platform for Ts.ED (express, koa or fastify)"
365
- },
366
- "--features <features...>": {
367
- type: Array,
368
- itemType: String,
369
- defaultValue: [],
370
- description: "List of the Ts.ED features."
371
- },
372
- "--runtime <runtime>": {
373
- itemType: String,
374
- defaultValue: "node",
375
- description: "The default runtime used to run the project"
376
- },
377
- "-m, --package-manager <packageManager>": {
378
- itemType: String,
379
- defaultValue: PackageManager.YARN,
380
- description: "The default package manager to install the project"
381
- },
382
- "-t, --tsed-version <version>": {
383
- type: String,
384
- defaultValue: DEFAULT_TSED_TAGS,
385
- description: "Use a specific version of Ts.ED (format: 5.x.x)."
386
- },
387
- "-f, --file <path>": {
388
- type: String,
389
- description: "Location of a file in which the features are defined."
390
- },
391
- "-s, --skip-prompt": {
392
- type: Boolean,
393
- defaultValue: false,
394
- description: "Skip the prompt."
335
+ if (isString(option)) {
336
+ const [id, name] = option.split(":");
337
+ return render(id, {
338
+ ...ctx,
339
+ from: TEMPLATE_DIR,
340
+ name: name || id
341
+ });
395
342
  }
343
+ else {
344
+ if ("id" in option) {
345
+ return render(option.id, {
346
+ ...ctx,
347
+ ...option
348
+ });
349
+ }
350
+ }
351
+ });
352
+ await Promise.all(promises);
353
+ taskOutput(`Plugins files rendered (${Date.now() - startTime}ms)`);
354
+ }
355
+ }
356
+ command(InitCmd, {
357
+ name: "init",
358
+ description: "Init a new Ts.ED project",
359
+ args: {
360
+ root: {
361
+ type: String,
362
+ defaultValue: ".",
363
+ description: "Root directory to initialize the Ts.ED project"
364
+ }
365
+ },
366
+ options: {
367
+ "-n, --project-name <projectName>": {
368
+ type: String,
369
+ defaultValue: "",
370
+ description: "Set the project name. By default, the project is the same as the name directory."
371
+ },
372
+ "-a, --arch <architecture>": {
373
+ type: String,
374
+ defaultValue: ArchitectureConvention.DEFAULT,
375
+ description: `Set the default architecture convention (${ArchitectureConvention.DEFAULT} or ${ArchitectureConvention.FEATURE})`
376
+ },
377
+ "-c, --convention <convention>": {
378
+ type: String,
379
+ defaultValue: ProjectConvention.DEFAULT,
380
+ description: `Set the default project convention (${ArchitectureConvention.DEFAULT} or ${ArchitectureConvention.FEATURE})`
396
381
  },
397
- disableReadUpPkg: true
398
- })
399
- ], InitCmd);
400
- export { InitCmd };
382
+ "-p, --platform <platform>": {
383
+ type: String,
384
+ defaultValue: PlatformType.EXPRESS,
385
+ description: "Set the default platform for Ts.ED (express, koa or fastify)"
386
+ },
387
+ "--features <features...>": {
388
+ type: Array,
389
+ itemType: String,
390
+ defaultValue: [],
391
+ description: "List of the Ts.ED features."
392
+ },
393
+ "--runtime <runtime>": {
394
+ itemType: String,
395
+ defaultValue: "node",
396
+ description: "The default runtime used to run the project"
397
+ },
398
+ "-m, --package-manager <packageManager>": {
399
+ itemType: String,
400
+ defaultValue: PackageManager.YARN,
401
+ description: "The default package manager to install the project"
402
+ },
403
+ "-t, --tsed-version <version>": {
404
+ type: String,
405
+ defaultValue: DEFAULT_TSED_TAGS,
406
+ description: "Use a specific version of Ts.ED (format: 5.x.x)."
407
+ },
408
+ "-f, --file <path>": {
409
+ type: String,
410
+ description: "Location of a file in which the features are defined."
411
+ },
412
+ "-s, --skip-prompt": {
413
+ type: Boolean,
414
+ defaultValue: false,
415
+ description: "Skip the prompt."
416
+ }
417
+ },
418
+ disableReadUpPkg: true
419
+ });
@@ -7,9 +7,20 @@ export var FeatureType;
7
7
  FeatureType["SOCKETIO"] = "socketio";
8
8
  FeatureType["OIDC"] = "oidc";
9
9
  FeatureType["PASSPORTJS"] = "passportjs";
10
+ FeatureType["CONFIG"] = "config";
10
11
  FeatureType["COMMANDS"] = "commands";
11
12
  FeatureType["DB"] = "db";
12
13
  FeatureType["DOC"] = "doc";
14
+ // CONFIG
15
+ FeatureType["CONFIG_ENVS"] = "config:envs";
16
+ FeatureType["CONFIG_DOTENV"] = "config:dotenv";
17
+ FeatureType["CONFIG_JSON"] = "config:json";
18
+ FeatureType["CONFIG_YAML"] = "config:yaml";
19
+ FeatureType["CONFIG_AWS_SECRETS"] = "config:aws_secrets";
20
+ FeatureType["CONFIG_IOREDIS"] = "config:ioredis";
21
+ FeatureType["CONFIG_MONGO"] = "config:mongo";
22
+ FeatureType["CONFIG_VAULT"] = "config:vault";
23
+ FeatureType["CONFIG_POSTGRES"] = "config:postgres";
13
24
  // DOC
14
25
  FeatureType["SWAGGER"] = "swagger";
15
26
  FeatureType["SCALAR"] = "scalar";
@@ -32,7 +43,7 @@ export var FeatureType;
32
43
  FeatureType["TYPEORM_SQLJS"] = "typeorm:sqljs";
33
44
  FeatureType["TYPEORM_REACTNATIVE"] = "typeorm:reactnative";
34
45
  FeatureType["TYPEORM_EXPO"] = "typeorm:expo";
35
- // TESTING
46
+ // TESTING & LINTER
36
47
  FeatureType["TESTING"] = "testing";
37
48
  FeatureType["JEST"] = "jest";
38
49
  FeatureType["VITEST"] = "vitest";
@@ -137,6 +148,73 @@ export const FeaturesMap = {
137
148
  name: "Feature",
138
149
  checked: false
139
150
  },
151
+ /// CONFIGURATION SOURCES
152
+ [FeatureType.CONFIG]: {
153
+ name: "Configuration sources",
154
+ dependencies: {
155
+ "@tsed/config": "{{tsedVersion}}"
156
+ }
157
+ },
158
+ [FeatureType.CONFIG_ENVS]: {
159
+ name: "Envs"
160
+ },
161
+ [FeatureType.CONFIG_DOTENV]: {
162
+ name: "Dotenv",
163
+ dependencies: {
164
+ dotenv: "latest",
165
+ "dotenv-expand": "latest",
166
+ "dotenv-flow": "latest"
167
+ }
168
+ },
169
+ [FeatureType.CONFIG_JSON]: {
170
+ name: "JSON"
171
+ },
172
+ [FeatureType.CONFIG_YAML]: {
173
+ name: "YAML",
174
+ dependencies: {
175
+ "js-yaml": "latest"
176
+ }
177
+ },
178
+ [FeatureType.CONFIG_AWS_SECRETS]: {
179
+ name: "AWS Secrets Manager (Premium)",
180
+ dependencies: {
181
+ "@tsedio/config-source-aws-secrets": "latest",
182
+ "@aws-sdk/client-secrets-manager": "latest"
183
+ }
184
+ },
185
+ [FeatureType.CONFIG_IOREDIS]: {
186
+ name: "IORedis (Premium)",
187
+ dependencies: {
188
+ "@tsedio/config-ioredis": "{{tsedVersion}}",
189
+ "@tsed/ioredis": "{{tsedVersion}}",
190
+ ioredis: "latest"
191
+ },
192
+ devDependencies: {
193
+ "@tsedio/testcontainers-redis": "latest"
194
+ }
195
+ },
196
+ [FeatureType.CONFIG_MONGO]: {
197
+ name: "MongoDB (Premium)",
198
+ dependencies: {
199
+ mongodb: "latest",
200
+ "@tsedio/config-mongo": "latest"
201
+ }
202
+ },
203
+ [FeatureType.CONFIG_VAULT]: {
204
+ name: "Vault (Premium)",
205
+ dependencies: {
206
+ "@tsedio/config-vault": "latest",
207
+ "node-vault": "latest"
208
+ }
209
+ },
210
+ [FeatureType.CONFIG_POSTGRES]: {
211
+ name: "Postgres (Premium)",
212
+ dependencies: {
213
+ pg: "latest",
214
+ "@tsedio/config-postgres": "latest"
215
+ }
216
+ },
217
+ /// TYPEORM
140
218
  [FeatureType.TYPEORM_MYSQL]: {
141
219
  name: "MySQL",
142
220
  dependencies: {
@@ -225,6 +303,7 @@ export const FeaturesMap = {
225
303
  typeorm: "latest"
226
304
  }
227
305
  },
306
+ /// TESTING
228
307
  [FeatureType.VITEST]: {
229
308
  name: "Vitest",
230
309
  devDependencies: {
@@ -237,6 +316,7 @@ export const FeaturesMap = {
237
316
  "@tsed/cli-plugin-jest": "{{cliVersion}}"
238
317
  }
239
318
  },
319
+ // LINTER
240
320
  [FeatureType.ESLINT]: {
241
321
  name: "EsLint",
242
322
  checked: true,
@@ -308,6 +388,7 @@ export const FeaturesPrompt = (availableRuntimes, availablePackageManagers) => [
308
388
  name: "features",
309
389
  message: "Check the features needed for your project",
310
390
  choices: [
391
+ FeatureType.CONFIG,
311
392
  FeatureType.GRAPHQL,
312
393
  FeatureType.DB,
313
394
  FeatureType.PASSPORTJS,
@@ -317,6 +398,23 @@ export const FeaturesPrompt = (availableRuntimes, availablePackageManagers) => [
317
398
  FeatureType.TESTING,
318
399
  FeatureType.LINTER,
319
400
  FeatureType.COMMANDS
401
+ ].sort((a, b) => a.localeCompare(b))
402
+ },
403
+ {
404
+ type: "checkbox",
405
+ message: "Choose configuration sources",
406
+ name: "featuresConfig",
407
+ when: hasFeature(FeatureType.CONFIG),
408
+ choices: [
409
+ FeatureType.CONFIG_ENVS,
410
+ FeatureType.CONFIG_DOTENV,
411
+ FeatureType.CONFIG_JSON,
412
+ FeatureType.CONFIG_YAML,
413
+ FeatureType.CONFIG_AWS_SECRETS,
414
+ FeatureType.CONFIG_IOREDIS,
415
+ FeatureType.CONFIG_MONGO,
416
+ FeatureType.CONFIG_VAULT,
417
+ FeatureType.CONFIG_POSTGRES
320
418
  ]
321
419
  },
322
420
  {
@@ -359,8 +457,8 @@ export const FeaturesPrompt = (availableRuntimes, availablePackageManagers) => [
359
457
  // type: "password",
360
458
  // name: "GH_TOKEN",
361
459
  // message:
362
- // "Enter GH_TOKEN to use the premium @tsedio/prisma package or leave blank (see https://tsed.dev/tutorials/prisma-client.html)",
363
- // when: hasValue("featuresDB.type", "prisma")
460
+ // "Enter GH_TOKEN to use the premium @tsedio package or leave blank (see https://tsed.dev/plugins/premium/install-premium-plugins.html)"
461
+ // // when: hasValue("featuresDB.type", "prisma")
364
462
  // },
365
463
  {
366
464
  message: "Choose unit framework",
@@ -3,9 +3,10 @@ import { mapUniqFeatures } from "./mapUniqFeatures.js";
3
3
  export function mapToContext(options) {
4
4
  options = mapUniqFeatures(options);
5
5
  options.features.forEach((feature) => {
6
- feature.split(":").forEach((type) => {
7
- options[camelCase(type)] = true;
8
- });
6
+ const [base, type] = feature.split(":");
7
+ options[camelCase(base)] = true;
8
+ type && (options[camelCase(type)] = true);
9
+ feature && (options[camelCase(feature)] = true);
9
10
  });
10
11
  return options;
11
12
  }