|
1 | 1 | import {basename, dirname, join} from "node:path"; |
2 | 2 |
|
3 | | -import {type CliDefaultOptions, Command, type CommandProvider, Inject, inject, ProjectPackageJson} from "@tsed/cli-core"; |
| 3 | +import {type CliDefaultOptions, command, type CommandProvider, inject, ProjectPackageJson} from "@tsed/cli-core"; |
4 | 4 | import {normalizePath} from "@tsed/normalize-path"; |
5 | 5 | import {kebabCase, pascalCase} from "change-case"; |
6 | 6 | import {globbySync} from "globby"; |
@@ -52,53 +52,15 @@ const searchFactory = (list: any) => { |
52 | 52 | }; |
53 | 53 | }; |
54 | 54 |
|
55 | | -@Command({ |
56 | | - name: "generate", |
57 | | - alias: "g", |
58 | | - description: "Generate a new provider class", |
59 | | - args: { |
60 | | - type: { |
61 | | - description: "Type of the provider (Injectable, Controller, Pipe, etc...)", |
62 | | - type: String |
63 | | - }, |
64 | | - name: { |
65 | | - description: "Name of the class", |
66 | | - type: String |
67 | | - } |
68 | | - }, |
69 | | - options: { |
70 | | - "--route <route>": { |
71 | | - type: String, |
72 | | - description: "The route for the controller generated file" |
73 | | - }, |
74 | | - "-d, --directory <directory>": { |
75 | | - description: "Directory where the file must be generated", |
76 | | - type: String |
77 | | - }, |
78 | | - "-t, --template-type <templateType>": { |
79 | | - description: "Directory where the file must be generated", |
80 | | - type: String |
81 | | - }, |
82 | | - "-m, --middleware-position <templateType>": { |
83 | | - description: "Middleware position (before, after)", |
84 | | - type: String |
85 | | - } |
86 | | - } |
87 | | -}) |
88 | 55 | export class GenerateCmd implements CommandProvider { |
89 | | - @Inject() |
90 | | - classNamePipe: ClassNamePipe; |
91 | | - |
92 | | - @Inject() |
93 | | - outputFilePathPipe: OutputFilePathPipe; |
94 | | - |
95 | | - @Inject() |
96 | | - routePipe: RoutePipe; |
| 56 | + protected classNamePipe = inject(ClassNamePipe); |
| 57 | + protected outputFilePathPipe = inject(OutputFilePathPipe); |
| 58 | + protected routePipe = inject(RoutePipe); |
| 59 | + protected srcRenderService = inject(SrcRendererService); |
| 60 | + protected projectPackageJson = inject(ProjectPackageJson); |
| 61 | + protected providersList = inject(ProvidersInfoService); |
97 | 62 |
|
98 | | - srcRenderService = inject(SrcRendererService); |
99 | | - projectPackageJson = inject(ProjectPackageJson); |
100 | | - |
101 | | - constructor(private providersList: ProvidersInfoService) { |
| 63 | + constructor() { |
102 | 64 | PROVIDER_TYPES.forEach((info) => { |
103 | 65 | this.providersList.add( |
104 | 66 | { |
@@ -288,3 +250,37 @@ export class GenerateCmd implements CommandProvider { |
288 | 250 | return [...set]; |
289 | 251 | } |
290 | 252 | } |
| 253 | + |
| 254 | +command(GenerateCmd, { |
| 255 | + name: "generate", |
| 256 | + alias: "g", |
| 257 | + description: "Generate a new provider class", |
| 258 | + args: { |
| 259 | + type: { |
| 260 | + description: "Type of the provider (Injectable, Controller, Pipe, etc...)", |
| 261 | + type: String |
| 262 | + }, |
| 263 | + name: { |
| 264 | + description: "Name of the class", |
| 265 | + type: String |
| 266 | + } |
| 267 | + }, |
| 268 | + options: { |
| 269 | + "--route <route>": { |
| 270 | + type: String, |
| 271 | + description: "The route for the controller generated file" |
| 272 | + }, |
| 273 | + "-d, --directory <directory>": { |
| 274 | + description: "Directory where the file must be generated", |
| 275 | + type: String |
| 276 | + }, |
| 277 | + "-t, --template-type <templateType>": { |
| 278 | + description: "Directory where the file must be generated", |
| 279 | + type: String |
| 280 | + }, |
| 281 | + "-m, --middleware-position <templateType>": { |
| 282 | + description: "Middleware position (before, after)", |
| 283 | + type: String |
| 284 | + } |
| 285 | + } |
| 286 | +}); |
0 commit comments