@tsed/cli 6.6.2 → 7.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/lib/esm/commands/add/AddCmd.js +16 -16
  2. package/lib/esm/commands/generate/GenerateCmd.js +71 -220
  3. package/lib/esm/commands/generate/mappers/mapGenerateContext.js +29 -0
  4. package/lib/esm/commands/init/InitCmd.js +186 -168
  5. package/lib/esm/commands/init/config/FeaturesPrompt.js +79 -3
  6. package/lib/esm/commands/init/mappers/mapToContext.js +4 -3
  7. package/lib/esm/commands/run/RunCmd.js +22 -26
  8. package/lib/esm/commands/update/UpdateCmd.js +9 -13
  9. package/lib/esm/fn/exec.js +5 -0
  10. package/lib/esm/fn/render.js +5 -0
  11. package/lib/esm/index.js +7 -4
  12. package/lib/esm/interfaces/AlterPackageJson.js +1 -0
  13. package/lib/esm/interfaces/AlterProjectFiles.js +1 -0
  14. package/lib/esm/interfaces/AlterRenderFiles.js +1 -0
  15. package/lib/esm/interfaces/CliCommandHooks.js +1 -0
  16. package/lib/esm/interfaces/GenerateCmdContext.js +1 -0
  17. package/lib/esm/interfaces/InitCmdOptions.js +1 -0
  18. package/lib/esm/interfaces/RenderDataContext.js +1 -0
  19. package/lib/esm/interfaces/RuntimeTypes.js +1 -0
  20. package/lib/esm/interfaces/index.js +9 -0
  21. package/lib/esm/pipes/OutputFilePathPipe.js +40 -18
  22. package/lib/esm/pipes/RoutePipe.js +4 -8
  23. package/lib/esm/pipes/{ClassNamePipe.js → SymbolNamePipe.js} +14 -11
  24. package/lib/esm/pipes/index.js +1 -1
  25. package/lib/esm/platforms/{InitPlatformsModule.js → PlatformsModule.js} +4 -10
  26. package/lib/esm/platforms/supports/InitExpressPlatform.js +27 -10
  27. package/lib/esm/platforms/supports/InitFastifyPlatform.js +27 -10
  28. package/lib/esm/platforms/supports/InitKoaPlatform.js +16 -10
  29. package/lib/esm/processors/__fixtures__/createFakeProject.js +35 -0
  30. package/lib/esm/processors/transformBinFile.js +47 -0
  31. package/lib/esm/processors/transformConfigFile.js +26 -0
  32. package/lib/esm/processors/transformIndexFile.js +28 -0
  33. package/lib/esm/processors/transformServerFile.js +64 -0
  34. package/lib/esm/runtimes/RuntimesModule.js +7 -17
  35. package/lib/esm/runtimes/supports/BabelRuntime.js +5 -11
  36. package/lib/esm/runtimes/supports/BunRuntime.js +4 -10
  37. package/lib/esm/runtimes/supports/NodeRuntime.js +1 -1
  38. package/lib/esm/runtimes/supports/WebpackRuntime.js +1 -1
  39. package/lib/esm/services/CliProjectService.js +91 -0
  40. package/lib/esm/services/CliRunScript.js +4 -8
  41. package/lib/esm/services/CliTemplatesService.js +67 -0
  42. package/lib/esm/services/ProjectClient.js +139 -0
  43. package/lib/esm/services/mappers/mapDefaultTemplateOptions.js +30 -0
  44. package/lib/esm/templates/asyncFactory.template.js +38 -0
  45. package/lib/esm/templates/barrels.template.js +22 -0
  46. package/lib/esm/templates/command.template.js +56 -0
  47. package/lib/esm/templates/config.template.js +27 -0
  48. package/lib/esm/templates/controller.template.js +45 -0
  49. package/lib/esm/templates/decorator.template.js +182 -0
  50. package/lib/esm/templates/docker-compose.template.js +25 -0
  51. package/lib/esm/templates/dockerfile.template.js +236 -0
  52. package/lib/esm/templates/exception-filter.template.js +19 -0
  53. package/lib/esm/templates/factory.template.js +37 -0
  54. package/lib/esm/templates/index.command.template.js +18 -0
  55. package/lib/esm/templates/index.config.utils.template.js +17 -0
  56. package/{templates/init/src/controllers/pages/IndexController.ts.hbs → lib/esm/templates/index.controller.template.js} +14 -3
  57. package/lib/esm/templates/index.js +32 -0
  58. package/lib/esm/templates/index.logger.template.js +38 -0
  59. package/{templates/init/src/index.ts.hbs → lib/esm/templates/index.template.js} +17 -5
  60. package/lib/esm/templates/interceptor.template.js +31 -0
  61. package/lib/esm/templates/interface.template.js +13 -0
  62. package/lib/esm/templates/middleware.template.js +34 -0
  63. package/lib/esm/templates/model.template.js +16 -0
  64. package/lib/esm/templates/module.template.js +16 -0
  65. package/lib/esm/templates/pipe.template.js +19 -0
  66. package/lib/esm/templates/pm2.template.js +111 -0
  67. package/lib/esm/templates/prisma.service.template.js +23 -0
  68. package/{templates/init/README.md.hbs → lib/esm/templates/readme.template.js} +28 -13
  69. package/lib/esm/templates/repository.template.js +16 -0
  70. package/lib/esm/templates/response-filter.template.js +19 -0
  71. package/lib/esm/templates/server.template.js +37 -0
  72. package/lib/esm/templates/service.template.js +16 -0
  73. package/lib/esm/templates/tsconfig.spec.template.js +34 -0
  74. package/lib/esm/templates/tsconfig.template.js +31 -0
  75. package/lib/esm/templates/value.template.js +13 -0
  76. package/lib/esm/utils/defineTemplate.js +13 -0
  77. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  78. package/lib/types/commands/add/AddCmd.d.ts +2 -2
  79. package/lib/types/commands/generate/GenerateCmd.d.ts +33 -87
  80. package/lib/types/commands/generate/mappers/mapGenerateContext.d.ts +2 -0
  81. package/lib/types/commands/init/InitCmd.d.ts +18 -20
  82. package/lib/types/commands/init/config/FeaturesPrompt.d.ts +10 -2
  83. package/lib/types/commands/init/mappers/mapToContext.d.ts +2 -2
  84. package/lib/types/commands/init/mappers/mapUniqFeatures.d.ts +1 -1
  85. package/lib/types/commands/init/prompts/getFeaturesPrompt.d.ts +1 -1
  86. package/lib/types/commands/update/UpdateCmd.d.ts +2 -2
  87. package/lib/types/fn/exec.d.ts +1 -0
  88. package/lib/types/fn/render.d.ts +2 -0
  89. package/lib/types/index.d.ts +7 -4
  90. package/lib/types/interfaces/AlterGenerateTasks.d.ts +5 -0
  91. package/lib/types/interfaces/AlterInitSubTasks.d.ts +5 -0
  92. package/lib/types/interfaces/AlterPackageJson.d.ts +5 -0
  93. package/lib/types/interfaces/AlterProjectFiles.d.ts +5 -0
  94. package/lib/types/interfaces/AlterRenderFiles.d.ts +10 -0
  95. package/lib/types/interfaces/CliCommandHooks.d.ts +11 -0
  96. package/lib/types/interfaces/GenerateCmdContext.d.ts +19 -0
  97. package/lib/types/interfaces/InitCmdOptions.d.ts +8 -0
  98. package/lib/types/interfaces/PlatformType.d.ts +7 -0
  99. package/lib/types/interfaces/RenderDataContext.d.ts +60 -0
  100. package/lib/types/interfaces/RuntimeTypes.d.ts +8 -0
  101. package/lib/types/interfaces/index.d.ts +9 -0
  102. package/lib/types/pipes/OutputFilePathPipe.d.ts +7 -4
  103. package/lib/types/pipes/{ClassNamePipe.d.ts → SymbolNamePipe.d.ts} +3 -3
  104. package/lib/types/pipes/index.d.ts +1 -1
  105. package/lib/types/platforms/{InitPlatformsModule.d.ts → PlatformsModule.d.ts} +1 -1
  106. package/lib/types/platforms/supports/InitBasePlatform.d.ts +3 -0
  107. package/lib/types/platforms/supports/InitExpressPlatform.d.ts +2 -0
  108. package/lib/types/platforms/supports/InitFastifyPlatform.d.ts +2 -0
  109. package/lib/types/platforms/supports/InitKoaPlatform.d.ts +2 -0
  110. package/lib/types/processors/__fixtures__/createFakeProject.d.ts +5 -0
  111. package/lib/types/processors/transformBinFile.d.ts +3 -0
  112. package/lib/types/processors/transformConfigFile.d.ts +3 -0
  113. package/lib/types/processors/transformIndexFile.d.ts +3 -0
  114. package/lib/types/processors/transformServerFile.d.ts +3 -0
  115. package/lib/types/runtimes/RuntimesModule.d.ts +5 -5
  116. package/lib/types/services/CliProjectService.d.ts +15 -0
  117. package/lib/types/services/CliTemplatesService.d.ts +29 -0
  118. package/lib/types/services/ProjectClient.d.ts +36 -0
  119. package/lib/types/services/mappers/mapDefaultTemplateOptions.d.ts +11 -0
  120. package/lib/types/templates/asyncFactory.template.d.ts +2 -0
  121. package/lib/types/templates/barrels.template.d.ts +2 -0
  122. package/lib/types/templates/command.template.d.ts +2 -0
  123. package/lib/types/templates/config.template.d.ts +2 -0
  124. package/lib/types/templates/controller.template.d.ts +2 -0
  125. package/lib/types/templates/decorator.template.d.ts +2 -0
  126. package/lib/types/templates/docker-compose.template.d.ts +2 -0
  127. package/lib/types/templates/dockerfile.template.d.ts +1 -0
  128. package/lib/types/templates/exception-filter.template.d.ts +2 -0
  129. package/lib/types/templates/factory.template.d.ts +2 -0
  130. package/lib/types/templates/index.command.template.d.ts +2 -0
  131. package/lib/types/templates/index.config.utils.template.d.ts +2 -0
  132. package/lib/types/templates/index.controller.template.d.ts +2 -0
  133. package/lib/types/templates/index.d.ts +31 -0
  134. package/lib/types/templates/index.logger.template.d.ts +2 -0
  135. package/lib/types/templates/index.template.d.ts +2 -0
  136. package/lib/types/templates/interceptor.template.d.ts +2 -0
  137. package/lib/types/templates/interface.template.d.ts +2 -0
  138. package/lib/types/templates/middleware.template.d.ts +2 -0
  139. package/lib/types/templates/model.template.d.ts +2 -0
  140. package/lib/types/templates/module.template.d.ts +2 -0
  141. package/lib/types/templates/pipe.template.d.ts +2 -0
  142. package/lib/types/templates/pm2.template.d.ts +1 -0
  143. package/lib/types/templates/prisma.service.template.d.ts +2 -0
  144. package/lib/types/templates/readme.template.d.ts +2 -0
  145. package/lib/types/templates/repository.template.d.ts +2 -0
  146. package/lib/types/templates/response-filter.template.d.ts +2 -0
  147. package/lib/types/templates/server.template.d.ts +2 -0
  148. package/lib/types/templates/service.template.d.ts +2 -0
  149. package/lib/types/templates/tsconfig.spec.template.d.ts +2 -0
  150. package/lib/types/templates/tsconfig.template.d.ts +2 -0
  151. package/lib/types/templates/value.template.d.ts +2 -0
  152. package/lib/types/utils/defineTemplate.d.ts +39 -0
  153. package/package.json +18 -16
  154. package/templates/tsconfig.node.json +14 -0
  155. package/templates/webpack.config.js +55 -0
  156. package/lib/esm/commands/generate/ProviderTypes.js +0 -103
  157. package/lib/esm/commands/init/interfaces/InitOptions.js +0 -5
  158. package/lib/esm/services/ProvidersInfoService.js +0 -46
  159. package/lib/esm/services/Renderer.js +0 -162
  160. package/lib/esm/utils/fillImports.js +0 -38
  161. package/lib/esm/utils/hbs/array.js +0 -515
  162. package/lib/esm/utils/hbs/collection.js +0 -60
  163. package/lib/esm/utils/hbs/comparison.js +0 -431
  164. package/lib/esm/utils/hbs/index.js +0 -11
  165. package/lib/esm/utils/hbs/object.js +0 -236
  166. package/lib/esm/utils/hbs/switch.js +0 -10
  167. package/lib/esm/utils/renderer/insertAfter.js +0 -12
  168. package/lib/esm/utils/renderer/insertImport.js +0 -11
  169. package/lib/types/commands/generate/ProviderTypes.d.ts +0 -11
  170. package/lib/types/commands/init/interfaces/InitCmdContext.d.ts +0 -6
  171. package/lib/types/commands/init/interfaces/InitOptions.d.ts +0 -20
  172. package/lib/types/services/ProvidersInfoService.d.ts +0 -21
  173. package/lib/types/services/Renderer.d.ts +0 -44
  174. package/lib/types/utils/fillImports.d.ts +0 -1
  175. package/lib/types/utils/hbs/array.d.ts +0 -1
  176. package/lib/types/utils/hbs/collection.d.ts +0 -1
  177. package/lib/types/utils/hbs/comparison.d.ts +0 -1
  178. package/lib/types/utils/hbs/object.d.ts +0 -1
  179. package/lib/types/utils/hbs/switch.d.ts +0 -1
  180. package/lib/types/utils/renderer/insertAfter.d.ts +0 -1
  181. package/lib/types/utils/renderer/insertImport.d.ts +0 -1
  182. package/templates/generate/async.factory.hbs +0 -35
  183. package/templates/generate/command.hbs +0 -45
  184. package/templates/generate/controller.hbs +0 -10
  185. package/templates/generate/decorator.class.hbs +0 -14
  186. package/templates/generate/decorator.endpoint.hbs +0 -15
  187. package/templates/generate/decorator.generic.hbs +0 -19
  188. package/templates/generate/decorator.method.hbs +0 -16
  189. package/templates/generate/decorator.middleware.hbs +0 -26
  190. package/templates/generate/decorator.param.hbs +0 -15
  191. package/templates/generate/decorator.parameters.hbs +0 -9
  192. package/templates/generate/decorator.prop.hbs +0 -14
  193. package/templates/generate/decorator.property.hbs +0 -5
  194. package/templates/generate/exception-filter.hbs +0 -9
  195. package/templates/generate/factory.hbs +0 -11
  196. package/templates/generate/injectable.hbs +0 -6
  197. package/templates/generate/interceptor.hbs +0 -21
  198. package/templates/generate/interface.hbs +0 -3
  199. package/templates/generate/middleware.hbs +0 -9
  200. package/templates/generate/model.hbs +0 -6
  201. package/templates/generate/module.hbs +0 -6
  202. package/templates/generate/pipe.hbs +0 -9
  203. package/templates/generate/prisma.service.hbs +0 -13
  204. package/templates/generate/repository.hbs +0 -6
  205. package/templates/generate/response-filter.hbs +0 -9
  206. package/templates/generate/server/_partials/server-footer.hbs +0 -10
  207. package/templates/generate/server/_partials/server-header.hbs +0 -34
  208. package/templates/generate/server/express/server.hbs +0 -10
  209. package/templates/generate/server/fastify/server.hbs +0 -14
  210. package/templates/generate/server/koa/server.hbs +0 -8
  211. package/templates/generate/service.hbs +0 -6
  212. package/templates/generate/value.hbs +0 -3
  213. package/templates/init/.barrels.json.hbs +0 -9
  214. package/templates/init/.gitignore.hbs +0 -57
  215. package/templates/init/.npmrc.hbs +0 -2
  216. package/templates/init/docker/_partials/docker-body.hbs +0 -5
  217. package/templates/init/docker/_partials/docker-dev-tools.hbs +0 -2
  218. package/templates/init/docker/_partials/docker-header.hbs +0 -16
  219. package/templates/init/docker/bun/Dockerfile.hbs +0 -36
  220. package/templates/init/docker/npm/Dockerfile.hbs +0 -28
  221. package/templates/init/docker/pnpm/Dockerfile.hbs +0 -28
  222. package/templates/init/docker/yarn/Dockerfile.hbs +0 -28
  223. package/templates/init/docker/yarn_berry/Dockerfile.hbs +0 -31
  224. package/templates/init/docker-compose.yml.hbs +0 -14
  225. package/templates/init/pm2/bun/processes.config.cjs.hbs +0 -23
  226. package/templates/init/pm2/node-compiled/processes.config.cjs.hbs +0 -22
  227. package/templates/init/pm2/node-loader/processes.config.cjs.hbs +0 -24
  228. package/templates/init/src/bin/index.ts.hbs +0 -9
  229. package/templates/init/src/config/envs/index.ts.hbs +0 -7
  230. package/templates/init/src/config/index.ts.hbs +0 -38
  231. package/templates/init/src/config/logger/index.ts.hbs +0 -25
  232. package/templates/init/tsconfig.json.hbs +0 -16
  233. package/templates/init/tsconfig.node.json.hbs +0 -20
  234. package/templates/init/tsconfig.spec.json.hbs +0 -25
  235. package/templates/init/webpack.config.js.hbs +0 -65
  236. /package/lib/esm/{commands/init/interfaces/InitCmdContext.js → interfaces/AlterGenerateTasks.js} +0 -0
  237. /package/lib/{types/utils/hbs/index.d.ts → esm/interfaces/AlterInitSubTasks.js} +0 -0
  238. /package/templates/{init/.babelrc.hbs → .babelrc} +0 -0
  239. /package/templates/{init/.dockerignore.hbs → .dockerignore} +0 -0
  240. /package/templates/{init/.swcrc.hbs → .swcrc} +0 -0
  241. /package/templates/{init/.yarnrc.hbs → .yarnrc} +0 -0
  242. /package/templates/{init/nodemon.json.hbs → nodemon.json} +0 -0
  243. /package/templates/{init/tsconfig.base.json.hbs → tsconfig.base.json} +0 -0
  244. /package/templates/{init/views/swagger.ejs.hbs → views/swagger.ejs} +0 -0
@@ -1,35 +1,35 @@
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";
6
10
  import { ArchitectureConvention } from "../../interfaces/ArchitectureConvention.js";
7
11
  import { PlatformType } from "../../interfaces/index.js";
8
12
  import { ProjectConvention } from "../../interfaces/ProjectConvention.js";
9
- import { OutputFilePathPipe } from "../../pipes/OutputFilePathPipe.js";
10
- import { InitPlatformsModule } from "../../platforms/InitPlatformsModule.js";
13
+ import { PlatformsModule } from "../../platforms/PlatformsModule.js";
11
14
  import { RuntimesModule } from "../../runtimes/RuntimesModule.js";
12
15
  import { BunRuntime } from "../../runtimes/supports/BunRuntime.js";
13
16
  import { NodeRuntime } from "../../runtimes/supports/NodeRuntime.js";
14
- import { RootRendererService } from "../../services/Renderer.js";
15
- import { fillImports } from "../../utils/fillImports.js";
17
+ import { CliProjectService } from "../../services/CliProjectService.js";
16
18
  import { FeaturesMap, FeatureType } from "./config/FeaturesPrompt.js";
17
19
  import { InitFileSchema } from "./config/InitFileSchema.js";
18
20
  import { mapToContext } from "./mappers/mapToContext.js";
19
21
  import { getFeaturesPrompt } from "./prompts/getFeaturesPrompt.js";
20
- let InitCmd = class InitCmd {
22
+ export class InitCmd {
21
23
  constructor() {
22
24
  this.configuration = inject(Configuration);
23
25
  this.cliPlugins = inject(CliPlugins);
24
26
  this.packageJson = inject(ProjectPackageJson);
25
27
  this.packageManagers = inject(PackageManagersModule);
26
28
  this.runtimes = inject(RuntimesModule);
27
- this.platforms = inject(InitPlatformsModule);
29
+ this.platforms = inject(PlatformsModule);
28
30
  this.cliPackageJson = cliPackageJson();
29
- this.cliService = inject(CliService);
30
31
  this.cliLoadFile = inject(CliLoadFile);
31
- this.rootRenderer = inject(RootRendererService);
32
- this.outputFilePathPipe = inject(OutputFilePathPipe);
32
+ this.project = inject(CliProjectService);
33
33
  this.execa = inject(CliExeca);
34
34
  this.fs = inject(CliFs);
35
35
  }
@@ -101,29 +101,28 @@ let InitCmd = class InitCmd {
101
101
  this.packageManagers.list().forEach((key) => {
102
102
  ctx[key] = ctx.packageManager === key;
103
103
  });
104
- return fillImports({
104
+ return {
105
105
  ...ctx,
106
- entryServer: ctx.convention !== ProjectConvention.ANGULAR ? "Server" : "server",
107
106
  cliVersion: ctx.cliVersion || this.cliPackageJson.version,
108
- srcDir: this.configuration.project?.srcDir,
109
- platformSymbol: ctx.platform && pascalCase(`Platform ${ctx.platform}`)
110
- });
107
+ srcDir: constant("project.srcDir", "src")
108
+ };
111
109
  }
112
110
  async $beforeExec(ctx) {
113
111
  this.fs.ensureDirSync(this.packageJson.dir);
114
- this.packageJson.name = ctx.projectName;
112
+ ctx.projectName && (this.packageJson.name = ctx.projectName);
115
113
  ctx.packageManager && this.packageJson.setPreference("packageManager", ctx.packageManager);
116
114
  ctx.runtime && this.packageJson.setPreference("runtime", ctx.runtime);
117
115
  ctx.architecture && this.packageJson.setPreference("architecture", ctx.architecture);
118
116
  ctx.convention && this.packageJson.setPreference("convention", ctx.convention);
117
+ ctx.platform && this.packageJson.setPreference("platform", ctx.convention);
119
118
  ctx.GH_TOKEN && this.packageJson.setGhToken(ctx.GH_TOKEN);
120
119
  await createTasksRunner([
121
120
  {
122
121
  title: "Write RC files",
123
122
  skip: () => !ctx.GH_TOKEN,
124
- task: () => this.rootRenderer.renderAll(["/init/.npmrc.hbs", "/init/.yarnrc.hbs"], ctx, {
125
- baseDir: "/init"
126
- })
123
+ task: () => {
124
+ return Promise.all([render(".npmrc", ctx), render(".yarnrc", ctx)]);
125
+ }
127
126
  },
128
127
  {
129
128
  title: "Initialize package.json",
@@ -151,39 +150,54 @@ let InitCmd = class InitCmd {
151
150
  }
152
151
  async $exec(ctx) {
153
152
  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
- ];
153
+ const runtime = this.runtimes.get();
154
+ ctx = {
155
+ ...ctx,
156
+ node: runtime instanceof NodeRuntime,
157
+ bun: runtime instanceof BunRuntime,
158
+ compiled: runtime instanceof NodeRuntime && runtime.isCompiled()
159
+ };
175
160
  return [
176
161
  {
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 })
162
+ title: "Render base files",
163
+ task: async () => {
164
+ return this.renderFiles(ctx);
165
+ }
166
+ },
167
+ {
168
+ title: "Alter package json",
169
+ task: async () => {
170
+ return $asyncAlter("$alterPackageJson", this.packageJson, [ctx]);
171
+ }
172
+ },
173
+ {
174
+ title: "Generate additional project files",
175
+ task: createSubTasks(async () => {
176
+ const subTasks = [
177
+ ...(await exec("generate", {
178
+ ...ctx,
179
+ type: "controller",
180
+ route: "rest",
181
+ name: "HelloWorld",
182
+ directory: "rest"
183
+ })),
184
+ ...(ctx.commands
185
+ ? await exec("generate", {
186
+ ...ctx,
187
+ type: "command",
188
+ route: "hello",
189
+ name: "hello"
190
+ })
191
+ : [])
192
+ ];
193
+ return $asyncAlter("$alterInitSubTasks", subTasks, [ctx]);
194
+ }, { ...ctx, concurrent: false })
195
+ },
196
+ {
197
+ title: "transform generated files to the project configuration",
198
+ task: async () => {
199
+ return this.project.transformFiles(ctx);
200
+ }
187
201
  }
188
202
  ];
189
203
  }
@@ -262,7 +276,7 @@ let InitCmd = class InitCmd {
262
276
  }, ctx);
263
277
  }
264
278
  addFeatures(ctx) {
265
- ctx.features.forEach((value) => {
279
+ ctx.features?.forEach((value) => {
266
280
  const feature = FeaturesMap[value.toLowerCase()];
267
281
  if (feature) {
268
282
  if (feature.dependencies) {
@@ -273,128 +287,132 @@ let InitCmd = class InitCmd {
273
287
  }
274
288
  }
275
289
  });
276
- if (ctx.features.find((value) => value === FeatureType.GRAPHQL)) {
290
+ if (ctx.features?.find((value) => value === FeatureType.GRAPHQL)) {
277
291
  this.packageJson.addDependencies({
278
292
  [`apollo-server-${ctx.platform}`]: "2.25.2"
279
293
  }, ctx);
280
294
  }
281
295
  }
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
- };
296
+ async baseFiles(ctx) {
297
+ const packageManager = inject(PackageManagersModule).get();
296
298
  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"
299
+ const runtimes = inject(RuntimesModule);
300
+ const runtime = runtimes.get();
301
+ // files with higher priority
302
+ const promises = [
303
+ "tsconfig.base.json",
304
+ "tsconfig.config.json",
305
+ "tsconfig.spec.json",
306
+ "tsconfig.node.json",
307
+ "docker-compose.yml",
308
+ `dockerfile.${packageManager.name}`,
309
+ ".dockerignore",
310
+ ".gitignore",
311
+ "server",
312
+ "config",
313
+ "index",
314
+ "index.config.util",
315
+ "index.logger",
316
+ "index.controller",
317
+ "barrels",
318
+ "readme",
319
+ `pm2.${pm2}`,
320
+ ctx.swagger && "/views/swagger.ejs",
321
+ ...runtime.files()
322
+ ].map((id) => {
323
+ return id && render(id, ctx);
331
324
  });
325
+ await Promise.all(promises);
332
326
  }
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"
327
+ async renderFiles(ctx) {
328
+ // base files
329
+ await this.baseFiles(ctx);
330
+ const files = await $asyncAlter("$alterRenderFiles", [], [ctx]);
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
+ }
354
+ }
355
+ command(InitCmd, {
356
+ name: "init",
357
+ description: "Init a new Ts.ED project",
358
+ args: {
359
+ root: {
360
+ type: String,
361
+ defaultValue: ".",
362
+ description: "Root directory to initialize the Ts.ED project"
363
+ }
364
+ },
365
+ options: {
366
+ "-n, --project-name <projectName>": {
367
+ type: String,
368
+ defaultValue: "",
369
+ description: "Set the project name. By default, the project is the same as the name directory."
370
+ },
371
+ "-a, --arch <architecture>": {
372
+ type: String,
373
+ defaultValue: ArchitectureConvention.DEFAULT,
374
+ description: `Set the default architecture convention (${ArchitectureConvention.DEFAULT} or ${ArchitectureConvention.FEATURE})`
375
+ },
376
+ "-c, --convention <convention>": {
377
+ type: String,
378
+ defaultValue: ProjectConvention.DEFAULT,
379
+ description: `Set the default project convention (${ArchitectureConvention.DEFAULT} or ${ArchitectureConvention.FEATURE})`
396
380
  },
397
- disableReadUpPkg: true
398
- })
399
- ], InitCmd);
400
- export { InitCmd };
381
+ "-p, --platform <platform>": {
382
+ type: String,
383
+ defaultValue: PlatformType.EXPRESS,
384
+ description: "Set the default platform for Ts.ED (express, koa or fastify)"
385
+ },
386
+ "--features <features...>": {
387
+ type: Array,
388
+ itemType: String,
389
+ defaultValue: [],
390
+ description: "List of the Ts.ED features."
391
+ },
392
+ "--runtime <runtime>": {
393
+ itemType: String,
394
+ defaultValue: "node",
395
+ description: "The default runtime used to run the project"
396
+ },
397
+ "-m, --package-manager <packageManager>": {
398
+ itemType: String,
399
+ defaultValue: PackageManager.YARN,
400
+ description: "The default package manager to install the project"
401
+ },
402
+ "-t, --tsed-version <version>": {
403
+ type: String,
404
+ defaultValue: DEFAULT_TSED_TAGS,
405
+ description: "Use a specific version of Ts.ED (format: 5.x.x)."
406
+ },
407
+ "-f, --file <path>": {
408
+ type: String,
409
+ description: "Location of a file in which the features are defined."
410
+ },
411
+ "-s, --skip-prompt": {
412
+ type: Boolean,
413
+ defaultValue: false,
414
+ description: "Skip the prompt."
415
+ }
416
+ },
417
+ disableReadUpPkg: true
418
+ });
@@ -7,9 +7,19 @@ 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_IOREDIS"] = "config:ioredis";
20
+ FeatureType["CONFIG_MONGO"] = "config:mongo";
21
+ FeatureType["CONFIG_VAULT"] = "config:vault";
22
+ FeatureType["CONFIG_POSTGRES"] = "config:postgres";
13
23
  // DOC
14
24
  FeatureType["SWAGGER"] = "swagger";
15
25
  FeatureType["SCALAR"] = "scalar";
@@ -32,7 +42,7 @@ export var FeatureType;
32
42
  FeatureType["TYPEORM_SQLJS"] = "typeorm:sqljs";
33
43
  FeatureType["TYPEORM_REACTNATIVE"] = "typeorm:reactnative";
34
44
  FeatureType["TYPEORM_EXPO"] = "typeorm:expo";
35
- // TESTING
45
+ // TESTING & LINTER
36
46
  FeatureType["TESTING"] = "testing";
37
47
  FeatureType["JEST"] = "jest";
38
48
  FeatureType["VITEST"] = "vitest";
@@ -137,6 +147,53 @@ export const FeaturesMap = {
137
147
  name: "Feature",
138
148
  checked: false
139
149
  },
150
+ /// CONFIGURATION SOURCES
151
+ [FeatureType.CONFIG]: {
152
+ name: "Configuration sources",
153
+ dependencies: {
154
+ "@tsed/config": "{{tsedVersion}}"
155
+ }
156
+ },
157
+ [FeatureType.CONFIG_ENVS]: {
158
+ name: "Envs"
159
+ },
160
+ [FeatureType.CONFIG_DOTENV]: {
161
+ name: "Dotenv"
162
+ },
163
+ [FeatureType.CONFIG_JSON]: {
164
+ name: "JSON"
165
+ },
166
+ [FeatureType.CONFIG_YAML]: {
167
+ name: "YAML"
168
+ },
169
+ [FeatureType.CONFIG_IOREDIS]: {
170
+ name: "IORedis (Premium)",
171
+ dependencies: {
172
+ ioredis: "latest",
173
+ "@tsedio/config-ioredis": "{{tsedVersion}}"
174
+ }
175
+ },
176
+ [FeatureType.CONFIG_MONGO]: {
177
+ name: "MongoDB (Premium)",
178
+ dependencies: {
179
+ mongodb: "latest",
180
+ "@tsedio/config-mongo": "{{tsedVersion}}"
181
+ }
182
+ },
183
+ [FeatureType.CONFIG_VAULT]: {
184
+ name: "Vault (Premium)",
185
+ dependencies: {
186
+ "@tsedio/config-vault": "{{tsedVersion}}"
187
+ }
188
+ },
189
+ [FeatureType.CONFIG_POSTGRES]: {
190
+ name: "Postgres (Premium)",
191
+ dependencies: {
192
+ pg: "latest",
193
+ "@tsedio/config-postgres": "{{tsedVersion}}"
194
+ }
195
+ },
196
+ /// TYPEORM
140
197
  [FeatureType.TYPEORM_MYSQL]: {
141
198
  name: "MySQL",
142
199
  dependencies: {
@@ -225,6 +282,7 @@ export const FeaturesMap = {
225
282
  typeorm: "latest"
226
283
  }
227
284
  },
285
+ /// TESTING
228
286
  [FeatureType.VITEST]: {
229
287
  name: "Vitest",
230
288
  devDependencies: {
@@ -237,6 +295,7 @@ export const FeaturesMap = {
237
295
  "@tsed/cli-plugin-jest": "{{cliVersion}}"
238
296
  }
239
297
  },
298
+ // LINTER
240
299
  [FeatureType.ESLINT]: {
241
300
  name: "EsLint",
242
301
  checked: true,
@@ -308,6 +367,7 @@ export const FeaturesPrompt = (availableRuntimes, availablePackageManagers) => [
308
367
  name: "features",
309
368
  message: "Check the features needed for your project",
310
369
  choices: [
370
+ FeatureType.CONFIG,
311
371
  FeatureType.GRAPHQL,
312
372
  FeatureType.DB,
313
373
  FeatureType.PASSPORTJS,
@@ -317,6 +377,22 @@ export const FeaturesPrompt = (availableRuntimes, availablePackageManagers) => [
317
377
  FeatureType.TESTING,
318
378
  FeatureType.LINTER,
319
379
  FeatureType.COMMANDS
380
+ ].sort((a, b) => a.localeCompare(b))
381
+ },
382
+ {
383
+ type: "checkbox",
384
+ message: "Choose configuration sources",
385
+ name: "featuresConfig",
386
+ when: hasFeature(FeatureType.CONFIG),
387
+ choices: [
388
+ FeatureType.CONFIG_ENVS,
389
+ FeatureType.CONFIG_DOTENV,
390
+ FeatureType.CONFIG_JSON,
391
+ FeatureType.CONFIG_YAML,
392
+ FeatureType.CONFIG_IOREDIS,
393
+ FeatureType.CONFIG_MONGO,
394
+ FeatureType.CONFIG_VAULT,
395
+ FeatureType.CONFIG_POSTGRES
320
396
  ]
321
397
  },
322
398
  {
@@ -359,8 +435,8 @@ export const FeaturesPrompt = (availableRuntimes, availablePackageManagers) => [
359
435
  // type: "password",
360
436
  // name: "GH_TOKEN",
361
437
  // 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")
438
+ // "Enter GH_TOKEN to use the premium @tsedio package or leave blank (see https://tsed.dev/plugins/premium/install-premium-plugins.html)"
439
+ // // when: hasValue("featuresDB.type", "prisma")
364
440
  // },
365
441
  {
366
442
  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
  }
@@ -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
+ });