@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.
- package/lib/esm/commands/add/AddCmd.js +16 -16
- package/lib/esm/commands/generate/GenerateCmd.js +71 -220
- package/lib/esm/commands/generate/mappers/mapGenerateContext.js +29 -0
- package/lib/esm/commands/init/InitCmd.js +186 -168
- package/lib/esm/commands/init/config/FeaturesPrompt.js +79 -3
- package/lib/esm/commands/init/mappers/mapToContext.js +4 -3
- package/lib/esm/commands/run/RunCmd.js +22 -26
- package/lib/esm/commands/update/UpdateCmd.js +9 -13
- package/lib/esm/fn/exec.js +5 -0
- package/lib/esm/fn/render.js +5 -0
- package/lib/esm/index.js +7 -4
- package/lib/esm/interfaces/AlterPackageJson.js +1 -0
- package/lib/esm/interfaces/AlterProjectFiles.js +1 -0
- package/lib/esm/interfaces/AlterRenderFiles.js +1 -0
- package/lib/esm/interfaces/CliCommandHooks.js +1 -0
- package/lib/esm/interfaces/GenerateCmdContext.js +1 -0
- package/lib/esm/interfaces/InitCmdOptions.js +1 -0
- package/lib/esm/interfaces/RenderDataContext.js +1 -0
- package/lib/esm/interfaces/RuntimeTypes.js +1 -0
- package/lib/esm/interfaces/index.js +9 -0
- package/lib/esm/pipes/OutputFilePathPipe.js +40 -18
- package/lib/esm/pipes/RoutePipe.js +4 -8
- package/lib/esm/pipes/{ClassNamePipe.js → SymbolNamePipe.js} +14 -11
- package/lib/esm/pipes/index.js +1 -1
- package/lib/esm/platforms/{InitPlatformsModule.js → PlatformsModule.js} +4 -10
- package/lib/esm/platforms/supports/InitExpressPlatform.js +27 -10
- package/lib/esm/platforms/supports/InitFastifyPlatform.js +27 -10
- package/lib/esm/platforms/supports/InitKoaPlatform.js +16 -10
- package/lib/esm/processors/__fixtures__/createFakeProject.js +35 -0
- package/lib/esm/processors/transformBinFile.js +47 -0
- package/lib/esm/processors/transformConfigFile.js +26 -0
- package/lib/esm/processors/transformIndexFile.js +28 -0
- package/lib/esm/processors/transformServerFile.js +64 -0
- package/lib/esm/runtimes/RuntimesModule.js +7 -17
- package/lib/esm/runtimes/supports/BabelRuntime.js +5 -11
- package/lib/esm/runtimes/supports/BunRuntime.js +4 -10
- package/lib/esm/runtimes/supports/NodeRuntime.js +1 -1
- package/lib/esm/runtimes/supports/WebpackRuntime.js +1 -1
- package/lib/esm/services/CliProjectService.js +91 -0
- package/lib/esm/services/CliRunScript.js +4 -8
- package/lib/esm/services/CliTemplatesService.js +67 -0
- package/lib/esm/services/ProjectClient.js +139 -0
- package/lib/esm/services/mappers/mapDefaultTemplateOptions.js +30 -0
- package/lib/esm/templates/asyncFactory.template.js +38 -0
- package/lib/esm/templates/barrels.template.js +22 -0
- package/lib/esm/templates/command.template.js +56 -0
- package/lib/esm/templates/config.template.js +27 -0
- package/lib/esm/templates/controller.template.js +45 -0
- package/lib/esm/templates/decorator.template.js +182 -0
- package/lib/esm/templates/docker-compose.template.js +25 -0
- package/lib/esm/templates/dockerfile.template.js +236 -0
- package/lib/esm/templates/exception-filter.template.js +19 -0
- package/lib/esm/templates/factory.template.js +37 -0
- package/lib/esm/templates/index.command.template.js +18 -0
- package/lib/esm/templates/index.config.utils.template.js +17 -0
- package/{templates/init/src/controllers/pages/IndexController.ts.hbs → lib/esm/templates/index.controller.template.js} +14 -3
- package/lib/esm/templates/index.js +32 -0
- package/lib/esm/templates/index.logger.template.js +38 -0
- package/{templates/init/src/index.ts.hbs → lib/esm/templates/index.template.js} +17 -5
- package/lib/esm/templates/interceptor.template.js +31 -0
- package/lib/esm/templates/interface.template.js +13 -0
- package/lib/esm/templates/middleware.template.js +34 -0
- package/lib/esm/templates/model.template.js +16 -0
- package/lib/esm/templates/module.template.js +16 -0
- package/lib/esm/templates/pipe.template.js +19 -0
- package/lib/esm/templates/pm2.template.js +111 -0
- package/lib/esm/templates/prisma.service.template.js +23 -0
- package/{templates/init/README.md.hbs → lib/esm/templates/readme.template.js} +28 -13
- package/lib/esm/templates/repository.template.js +16 -0
- package/lib/esm/templates/response-filter.template.js +19 -0
- package/lib/esm/templates/server.template.js +37 -0
- package/lib/esm/templates/service.template.js +16 -0
- package/lib/esm/templates/tsconfig.spec.template.js +34 -0
- package/lib/esm/templates/tsconfig.template.js +31 -0
- package/lib/esm/templates/value.template.js +13 -0
- package/lib/esm/utils/defineTemplate.js +13 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/commands/add/AddCmd.d.ts +2 -2
- package/lib/types/commands/generate/GenerateCmd.d.ts +33 -87
- package/lib/types/commands/generate/mappers/mapGenerateContext.d.ts +2 -0
- package/lib/types/commands/init/InitCmd.d.ts +18 -20
- package/lib/types/commands/init/config/FeaturesPrompt.d.ts +10 -2
- package/lib/types/commands/init/mappers/mapToContext.d.ts +2 -2
- package/lib/types/commands/init/mappers/mapUniqFeatures.d.ts +1 -1
- package/lib/types/commands/init/prompts/getFeaturesPrompt.d.ts +1 -1
- package/lib/types/commands/update/UpdateCmd.d.ts +2 -2
- package/lib/types/fn/exec.d.ts +1 -0
- package/lib/types/fn/render.d.ts +2 -0
- package/lib/types/index.d.ts +7 -4
- package/lib/types/interfaces/AlterGenerateTasks.d.ts +5 -0
- package/lib/types/interfaces/AlterInitSubTasks.d.ts +5 -0
- package/lib/types/interfaces/AlterPackageJson.d.ts +5 -0
- package/lib/types/interfaces/AlterProjectFiles.d.ts +5 -0
- package/lib/types/interfaces/AlterRenderFiles.d.ts +10 -0
- package/lib/types/interfaces/CliCommandHooks.d.ts +11 -0
- package/lib/types/interfaces/GenerateCmdContext.d.ts +19 -0
- package/lib/types/interfaces/InitCmdOptions.d.ts +8 -0
- package/lib/types/interfaces/PlatformType.d.ts +7 -0
- package/lib/types/interfaces/RenderDataContext.d.ts +60 -0
- package/lib/types/interfaces/RuntimeTypes.d.ts +8 -0
- package/lib/types/interfaces/index.d.ts +9 -0
- package/lib/types/pipes/OutputFilePathPipe.d.ts +7 -4
- package/lib/types/pipes/{ClassNamePipe.d.ts → SymbolNamePipe.d.ts} +3 -3
- package/lib/types/pipes/index.d.ts +1 -1
- package/lib/types/platforms/{InitPlatformsModule.d.ts → PlatformsModule.d.ts} +1 -1
- package/lib/types/platforms/supports/InitBasePlatform.d.ts +3 -0
- package/lib/types/platforms/supports/InitExpressPlatform.d.ts +2 -0
- package/lib/types/platforms/supports/InitFastifyPlatform.d.ts +2 -0
- package/lib/types/platforms/supports/InitKoaPlatform.d.ts +2 -0
- package/lib/types/processors/__fixtures__/createFakeProject.d.ts +5 -0
- package/lib/types/processors/transformBinFile.d.ts +3 -0
- package/lib/types/processors/transformConfigFile.d.ts +3 -0
- package/lib/types/processors/transformIndexFile.d.ts +3 -0
- package/lib/types/processors/transformServerFile.d.ts +3 -0
- package/lib/types/runtimes/RuntimesModule.d.ts +5 -5
- package/lib/types/services/CliProjectService.d.ts +15 -0
- package/lib/types/services/CliTemplatesService.d.ts +29 -0
- package/lib/types/services/ProjectClient.d.ts +36 -0
- package/lib/types/services/mappers/mapDefaultTemplateOptions.d.ts +11 -0
- package/lib/types/templates/asyncFactory.template.d.ts +2 -0
- package/lib/types/templates/barrels.template.d.ts +2 -0
- package/lib/types/templates/command.template.d.ts +2 -0
- package/lib/types/templates/config.template.d.ts +2 -0
- package/lib/types/templates/controller.template.d.ts +2 -0
- package/lib/types/templates/decorator.template.d.ts +2 -0
- package/lib/types/templates/docker-compose.template.d.ts +2 -0
- package/lib/types/templates/dockerfile.template.d.ts +1 -0
- package/lib/types/templates/exception-filter.template.d.ts +2 -0
- package/lib/types/templates/factory.template.d.ts +2 -0
- package/lib/types/templates/index.command.template.d.ts +2 -0
- package/lib/types/templates/index.config.utils.template.d.ts +2 -0
- package/lib/types/templates/index.controller.template.d.ts +2 -0
- package/lib/types/templates/index.d.ts +31 -0
- package/lib/types/templates/index.logger.template.d.ts +2 -0
- package/lib/types/templates/index.template.d.ts +2 -0
- package/lib/types/templates/interceptor.template.d.ts +2 -0
- package/lib/types/templates/interface.template.d.ts +2 -0
- package/lib/types/templates/middleware.template.d.ts +2 -0
- package/lib/types/templates/model.template.d.ts +2 -0
- package/lib/types/templates/module.template.d.ts +2 -0
- package/lib/types/templates/pipe.template.d.ts +2 -0
- package/lib/types/templates/pm2.template.d.ts +1 -0
- package/lib/types/templates/prisma.service.template.d.ts +2 -0
- package/lib/types/templates/readme.template.d.ts +2 -0
- package/lib/types/templates/repository.template.d.ts +2 -0
- package/lib/types/templates/response-filter.template.d.ts +2 -0
- package/lib/types/templates/server.template.d.ts +2 -0
- package/lib/types/templates/service.template.d.ts +2 -0
- package/lib/types/templates/tsconfig.spec.template.d.ts +2 -0
- package/lib/types/templates/tsconfig.template.d.ts +2 -0
- package/lib/types/templates/value.template.d.ts +2 -0
- package/lib/types/utils/defineTemplate.d.ts +39 -0
- package/package.json +18 -16
- package/templates/tsconfig.node.json +14 -0
- package/templates/webpack.config.js +55 -0
- package/lib/esm/commands/generate/ProviderTypes.js +0 -103
- package/lib/esm/commands/init/interfaces/InitOptions.js +0 -5
- package/lib/esm/services/ProvidersInfoService.js +0 -46
- package/lib/esm/services/Renderer.js +0 -162
- package/lib/esm/utils/fillImports.js +0 -38
- package/lib/esm/utils/hbs/array.js +0 -515
- package/lib/esm/utils/hbs/collection.js +0 -60
- package/lib/esm/utils/hbs/comparison.js +0 -431
- package/lib/esm/utils/hbs/index.js +0 -11
- package/lib/esm/utils/hbs/object.js +0 -236
- package/lib/esm/utils/hbs/switch.js +0 -10
- package/lib/esm/utils/renderer/insertAfter.js +0 -12
- package/lib/esm/utils/renderer/insertImport.js +0 -11
- package/lib/types/commands/generate/ProviderTypes.d.ts +0 -11
- package/lib/types/commands/init/interfaces/InitCmdContext.d.ts +0 -6
- package/lib/types/commands/init/interfaces/InitOptions.d.ts +0 -20
- package/lib/types/services/ProvidersInfoService.d.ts +0 -21
- package/lib/types/services/Renderer.d.ts +0 -44
- package/lib/types/utils/fillImports.d.ts +0 -1
- package/lib/types/utils/hbs/array.d.ts +0 -1
- package/lib/types/utils/hbs/collection.d.ts +0 -1
- package/lib/types/utils/hbs/comparison.d.ts +0 -1
- package/lib/types/utils/hbs/object.d.ts +0 -1
- package/lib/types/utils/hbs/switch.d.ts +0 -1
- package/lib/types/utils/renderer/insertAfter.d.ts +0 -1
- package/lib/types/utils/renderer/insertImport.d.ts +0 -1
- package/templates/generate/async.factory.hbs +0 -35
- package/templates/generate/command.hbs +0 -45
- package/templates/generate/controller.hbs +0 -10
- package/templates/generate/decorator.class.hbs +0 -14
- package/templates/generate/decorator.endpoint.hbs +0 -15
- package/templates/generate/decorator.generic.hbs +0 -19
- package/templates/generate/decorator.method.hbs +0 -16
- package/templates/generate/decorator.middleware.hbs +0 -26
- package/templates/generate/decorator.param.hbs +0 -15
- package/templates/generate/decorator.parameters.hbs +0 -9
- package/templates/generate/decorator.prop.hbs +0 -14
- package/templates/generate/decorator.property.hbs +0 -5
- package/templates/generate/exception-filter.hbs +0 -9
- package/templates/generate/factory.hbs +0 -11
- package/templates/generate/injectable.hbs +0 -6
- package/templates/generate/interceptor.hbs +0 -21
- package/templates/generate/interface.hbs +0 -3
- package/templates/generate/middleware.hbs +0 -9
- package/templates/generate/model.hbs +0 -6
- package/templates/generate/module.hbs +0 -6
- package/templates/generate/pipe.hbs +0 -9
- package/templates/generate/prisma.service.hbs +0 -13
- package/templates/generate/repository.hbs +0 -6
- package/templates/generate/response-filter.hbs +0 -9
- package/templates/generate/server/_partials/server-footer.hbs +0 -10
- package/templates/generate/server/_partials/server-header.hbs +0 -34
- package/templates/generate/server/express/server.hbs +0 -10
- package/templates/generate/server/fastify/server.hbs +0 -14
- package/templates/generate/server/koa/server.hbs +0 -8
- package/templates/generate/service.hbs +0 -6
- package/templates/generate/value.hbs +0 -3
- package/templates/init/.barrels.json.hbs +0 -9
- package/templates/init/.gitignore.hbs +0 -57
- package/templates/init/.npmrc.hbs +0 -2
- package/templates/init/docker/_partials/docker-body.hbs +0 -5
- package/templates/init/docker/_partials/docker-dev-tools.hbs +0 -2
- package/templates/init/docker/_partials/docker-header.hbs +0 -16
- package/templates/init/docker/bun/Dockerfile.hbs +0 -36
- package/templates/init/docker/npm/Dockerfile.hbs +0 -28
- package/templates/init/docker/pnpm/Dockerfile.hbs +0 -28
- package/templates/init/docker/yarn/Dockerfile.hbs +0 -28
- package/templates/init/docker/yarn_berry/Dockerfile.hbs +0 -31
- package/templates/init/docker-compose.yml.hbs +0 -14
- package/templates/init/pm2/bun/processes.config.cjs.hbs +0 -23
- package/templates/init/pm2/node-compiled/processes.config.cjs.hbs +0 -22
- package/templates/init/pm2/node-loader/processes.config.cjs.hbs +0 -24
- package/templates/init/src/bin/index.ts.hbs +0 -9
- package/templates/init/src/config/envs/index.ts.hbs +0 -7
- package/templates/init/src/config/index.ts.hbs +0 -38
- package/templates/init/src/config/logger/index.ts.hbs +0 -25
- package/templates/init/tsconfig.json.hbs +0 -16
- package/templates/init/tsconfig.node.json.hbs +0 -20
- package/templates/init/tsconfig.spec.json.hbs +0 -25
- package/templates/init/webpack.config.js.hbs +0 -65
- /package/lib/esm/{commands/init/interfaces/InitCmdContext.js → interfaces/AlterGenerateTasks.js} +0 -0
- /package/lib/{types/utils/hbs/index.d.ts → esm/interfaces/AlterInitSubTasks.js} +0 -0
- /package/templates/{init/.babelrc.hbs → .babelrc} +0 -0
- /package/templates/{init/.dockerignore.hbs → .dockerignore} +0 -0
- /package/templates/{init/.swcrc.hbs → .swcrc} +0 -0
- /package/templates/{init/.yarnrc.hbs → .yarnrc} +0 -0
- /package/templates/{init/nodemon.json.hbs → nodemon.json} +0 -0
- /package/templates/{init/tsconfig.base.json.hbs → tsconfig.base.json} +0 -0
- /package/templates/{init/views/swagger.ejs.hbs → views/swagger.ejs} +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
let AddCmd = class AddCmd {
|
|
1
|
+
import { CliPlugins, command, createSubTasks, inject, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
|
|
2
|
+
export class AddCmd {
|
|
4
3
|
constructor() {
|
|
5
4
|
this.cliPlugins = inject(CliPlugins);
|
|
6
5
|
this.packageJson = inject(ProjectPackageJson);
|
|
@@ -34,20 +33,21 @@ let AddCmd = class AddCmd {
|
|
|
34
33
|
{
|
|
35
34
|
title: "Install plugins dependencies",
|
|
36
35
|
task: createSubTasks(() => this.cliPlugins.addPluginsDependencies(ctx), { ...ctx, concurrent: false })
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
title: "Transform files",
|
|
39
|
+
task: createSubTasks(() => this.cliPlugins.addPluginsDependencies(ctx), { ...ctx, concurrent: false })
|
|
37
40
|
}
|
|
38
41
|
];
|
|
39
42
|
}
|
|
40
|
-
}
|
|
41
|
-
AddCmd
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
type: String
|
|
49
|
-
}
|
|
43
|
+
}
|
|
44
|
+
command(AddCmd, {
|
|
45
|
+
name: "add",
|
|
46
|
+
description: "Add cli plugin to the current project",
|
|
47
|
+
args: {
|
|
48
|
+
name: {
|
|
49
|
+
description: "Npm package name of the cli plugin",
|
|
50
|
+
type: String
|
|
50
51
|
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export { AddCmd };
|
|
52
|
+
}
|
|
53
|
+
});
|
|
@@ -1,250 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { kebabCase, pascalCase } from "change-case";
|
|
7
|
-
import { globbySync } from "globby";
|
|
8
|
-
import { ProjectConvention } from "../../interfaces/ProjectConvention.js";
|
|
9
|
-
import { ClassNamePipe } from "../../pipes/ClassNamePipe.js";
|
|
10
|
-
import { OutputFilePathPipe } from "../../pipes/OutputFilePathPipe.js";
|
|
11
|
-
import { RoutePipe } from "../../pipes/RoutePipe.js";
|
|
12
|
-
import { ProvidersInfoService } from "../../services/ProvidersInfoService.js";
|
|
13
|
-
import { SrcRendererService } from "../../services/Renderer.js";
|
|
14
|
-
import { fillImports } from "../../utils/fillImports.js";
|
|
15
|
-
import { getFrameworksPrompt } from "../init/prompts/getFeaturesPrompt.js";
|
|
16
|
-
import { PROVIDER_TYPES } from "./ProviderTypes.js";
|
|
17
|
-
const DECORATOR_TYPES = [
|
|
18
|
-
{ name: "Class decorator", value: "class" },
|
|
19
|
-
{ name: "Ts.ED middleware and its decorator", value: "middleware" },
|
|
20
|
-
{ name: "Ts.ED endpoint decorator", value: "endpoint" },
|
|
21
|
-
{ name: "Ts.ED property decorator", value: "prop" },
|
|
22
|
-
{ name: "Ts.ED parameter decorator", value: "param" },
|
|
23
|
-
{ name: "Vanilla Method decorator", value: "method" },
|
|
24
|
-
{ name: "Vanilla Property decorator", value: "property" },
|
|
25
|
-
{ name: "Vanilla Parameter decorator", value: "parameter" },
|
|
26
|
-
{ name: "Generic decorator", value: "generic" }
|
|
27
|
-
];
|
|
1
|
+
import { command, inject, ProjectPackageJson } from "@tsed/cli-core";
|
|
2
|
+
import { pascalCase } from "change-case";
|
|
3
|
+
import { CliProjectService } from "../../services/CliProjectService.js";
|
|
4
|
+
import { CliTemplatesService } from "../../services/CliTemplatesService.js";
|
|
5
|
+
import { mapDefaultTemplateOptions } from "../../services/mappers/mapDefaultTemplateOptions.js";
|
|
28
6
|
const searchFactory = (list) => {
|
|
29
|
-
return (
|
|
7
|
+
return (_, keyword) => {
|
|
30
8
|
if (keyword) {
|
|
31
|
-
return list.filter((item) => item.
|
|
9
|
+
return list.filter((item) => item.label.toLowerCase().includes(keyword.toLowerCase()));
|
|
32
10
|
}
|
|
33
11
|
return list;
|
|
34
12
|
};
|
|
35
13
|
};
|
|
36
|
-
|
|
37
|
-
constructor(
|
|
38
|
-
this.providersList = providersList;
|
|
39
|
-
this.srcRenderService = inject(SrcRendererService);
|
|
14
|
+
export class GenerateCmd {
|
|
15
|
+
constructor() {
|
|
40
16
|
this.projectPackageJson = inject(ProjectPackageJson);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
...info
|
|
44
|
-
}, GenerateCmd_1);
|
|
45
|
-
});
|
|
17
|
+
this.projectService = inject(CliProjectService);
|
|
18
|
+
this.templates = inject(CliTemplatesService);
|
|
46
19
|
}
|
|
47
|
-
$prompt(
|
|
48
|
-
|
|
49
|
-
const
|
|
20
|
+
async $prompt(data) {
|
|
21
|
+
data.getName = (state) => data.name || pascalCase(state.name || data.name || state.type || data.type || "");
|
|
22
|
+
const templates = this.templates.find();
|
|
23
|
+
const templatesPrompts = await Promise.all(templates
|
|
24
|
+
.filter((template) => template.prompts)
|
|
25
|
+
.map((template) => {
|
|
26
|
+
return template.prompts(data);
|
|
27
|
+
}));
|
|
50
28
|
return [
|
|
51
29
|
{
|
|
52
30
|
type: "autocomplete",
|
|
53
31
|
name: "type",
|
|
54
32
|
message: "Which type of provider?",
|
|
55
|
-
default:
|
|
56
|
-
when: () =>
|
|
57
|
-
source: searchFactory(
|
|
33
|
+
default: data.type,
|
|
34
|
+
when: () => templates.length > 1,
|
|
35
|
+
source: searchFactory(this.templates.find(data.type))
|
|
58
36
|
},
|
|
59
37
|
{
|
|
60
38
|
type: "input",
|
|
61
39
|
name: "name",
|
|
62
40
|
message: "Which name?",
|
|
63
|
-
default: getName,
|
|
64
|
-
when: !
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
...getFrameworksPrompt(),
|
|
68
|
-
message: "Which platform?",
|
|
69
|
-
type: "list",
|
|
70
|
-
name: "platform",
|
|
71
|
-
when(state) {
|
|
72
|
-
return ["server"].includes(state.type || initialOptions.type);
|
|
73
|
-
}
|
|
41
|
+
default: data.getName,
|
|
42
|
+
when: !data.name
|
|
74
43
|
},
|
|
44
|
+
...templatesPrompts.flat()
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
$mapContext(ctx) {
|
|
48
|
+
return mapDefaultTemplateOptions(ctx);
|
|
49
|
+
}
|
|
50
|
+
$exec(ctx) {
|
|
51
|
+
const { symbolPath, type } = ctx;
|
|
52
|
+
return [
|
|
75
53
|
{
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return !!(["controller", "server"].includes(state.type || initialOptions.type) || initialOptions.route);
|
|
81
|
-
},
|
|
82
|
-
default: (state) => {
|
|
83
|
-
return state.type === "server" ? "/rest" : this.routePipe.transform(getName(state));
|
|
54
|
+
title: `Generate ${ctx.type} file to '${symbolPath}.ts'`,
|
|
55
|
+
skip: !this.templates.get(type),
|
|
56
|
+
task: () => {
|
|
57
|
+
this.projectService.createFromTemplate(type, ctx);
|
|
84
58
|
}
|
|
85
59
|
},
|
|
86
60
|
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
when(state) {
|
|
91
|
-
return ["controller"].includes(state.type || initialOptions.type) || initialOptions.directory;
|
|
92
|
-
},
|
|
93
|
-
choices: this.getDirectories("controllers")
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
type: "autocomplete",
|
|
97
|
-
name: "templateType",
|
|
98
|
-
message: (state) => `Which type of ${state.type || initialOptions.type}?`,
|
|
99
|
-
when(state) {
|
|
100
|
-
return !!(["decorator"].includes(state.type || initialOptions.type) || initialOptions.templateType);
|
|
101
|
-
},
|
|
102
|
-
source: searchFactory(DECORATOR_TYPES)
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
type: "list",
|
|
106
|
-
name: "middlewarePosition",
|
|
107
|
-
message: () => `The middleware should be called:`,
|
|
108
|
-
choices: [
|
|
109
|
-
{ name: "Before the endpoint", value: "before" },
|
|
110
|
-
{ name: "After the endpoint", value: "after" }
|
|
111
|
-
],
|
|
112
|
-
when(state) {
|
|
113
|
-
return !!((["decorator"].includes(state.type || initialOptions.type) && ["middleware"].includes(state.templateType)) ||
|
|
114
|
-
initialOptions.middlewarePosition);
|
|
61
|
+
title: "Transform generated files",
|
|
62
|
+
task: () => {
|
|
63
|
+
return this.projectService.transformFiles(ctx);
|
|
115
64
|
}
|
|
116
65
|
}
|
|
117
66
|
];
|
|
118
67
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
symbolName,
|
|
133
|
-
symbolParamName,
|
|
134
|
-
symbolPath: normalizePath(this.outputFilePathPipe.transform({
|
|
135
|
-
name,
|
|
136
|
-
type,
|
|
137
|
-
subDir: ctx.directory
|
|
138
|
-
})),
|
|
139
|
-
symbolPathBasename: normalizePath(this.classNamePipe.transform({ name, type })),
|
|
140
|
-
platformSymbol: ctx.platform && pascalCase(`Platform ${ctx.platform}`)
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
$exec(ctx) {
|
|
144
|
-
const { symbolPath } = ctx;
|
|
145
|
-
if (this.providersList.isMyProvider(ctx.type, GenerateCmd_1)) {
|
|
146
|
-
const type = [ctx.type, ctx.templateType].filter(Boolean).join(".");
|
|
147
|
-
let template = `generate/${type}.hbs`;
|
|
148
|
-
if (ctx.type === "server") {
|
|
149
|
-
template = `generate/server/${ctx.platform}/server.hbs`;
|
|
150
|
-
}
|
|
151
|
-
return [
|
|
152
|
-
{
|
|
153
|
-
title: `Generate ${ctx.type} file to '${symbolPath}.ts'`,
|
|
154
|
-
task: () => {
|
|
155
|
-
if (ctx.type === "server") {
|
|
156
|
-
return this.srcRenderService.render(template, ctx, {
|
|
157
|
-
baseDir: "generate",
|
|
158
|
-
basename: `${symbolPath}.ts`,
|
|
159
|
-
replaces: [`server/${ctx.platform}`]
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
return this.srcRenderService.render(template, ctx, {
|
|
163
|
-
output: `${symbolPath}.ts`
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
title: `Update bin/index`,
|
|
169
|
-
skip() {
|
|
170
|
-
return ctx.type !== "command";
|
|
171
|
-
},
|
|
172
|
-
task: () => {
|
|
173
|
-
return this.srcRenderService.update("bin/index.ts", [
|
|
174
|
-
{
|
|
175
|
-
type: "import",
|
|
176
|
-
content: `import {${ctx.symbolName}} from "./${basename(symbolPath)}.js";`
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
type: "insert-after",
|
|
180
|
-
pattern: /commands: \[/,
|
|
181
|
-
content: ` ${ctx.symbolName}`
|
|
182
|
-
}
|
|
183
|
-
]);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
];
|
|
68
|
+
}
|
|
69
|
+
command(GenerateCmd, {
|
|
70
|
+
name: "generate",
|
|
71
|
+
alias: "g",
|
|
72
|
+
description: "Generate a new provider class",
|
|
73
|
+
args: {
|
|
74
|
+
type: {
|
|
75
|
+
description: "Type of the provider (Injectable, Controller, Pipe, etc...)",
|
|
76
|
+
type: String
|
|
77
|
+
},
|
|
78
|
+
name: {
|
|
79
|
+
description: "Name of the class",
|
|
80
|
+
type: String
|
|
187
81
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
ignore: ["__*"]
|
|
194
|
-
});
|
|
195
|
-
const set = new Set(directories.map((dir) => {
|
|
196
|
-
return dirname(dir);
|
|
197
|
-
}));
|
|
198
|
-
set.delete(".");
|
|
199
|
-
return [...set];
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
__decorate([
|
|
203
|
-
Inject(),
|
|
204
|
-
__metadata("design:type", ClassNamePipe)
|
|
205
|
-
], GenerateCmd.prototype, "classNamePipe", void 0);
|
|
206
|
-
__decorate([
|
|
207
|
-
Inject(),
|
|
208
|
-
__metadata("design:type", OutputFilePathPipe)
|
|
209
|
-
], GenerateCmd.prototype, "outputFilePathPipe", void 0);
|
|
210
|
-
__decorate([
|
|
211
|
-
Inject(),
|
|
212
|
-
__metadata("design:type", RoutePipe)
|
|
213
|
-
], GenerateCmd.prototype, "routePipe", void 0);
|
|
214
|
-
GenerateCmd = GenerateCmd_1 = __decorate([
|
|
215
|
-
Command({
|
|
216
|
-
name: "generate",
|
|
217
|
-
alias: "g",
|
|
218
|
-
description: "Generate a new provider class",
|
|
219
|
-
args: {
|
|
220
|
-
type: {
|
|
221
|
-
description: "Type of the provider (Injectable, Controller, Pipe, etc...)",
|
|
222
|
-
type: String
|
|
223
|
-
},
|
|
224
|
-
name: {
|
|
225
|
-
description: "Name of the class",
|
|
226
|
-
type: String
|
|
227
|
-
}
|
|
82
|
+
},
|
|
83
|
+
options: {
|
|
84
|
+
"--route <route>": {
|
|
85
|
+
type: String,
|
|
86
|
+
description: "The route for the controller generated file"
|
|
228
87
|
},
|
|
229
|
-
|
|
230
|
-
"
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
"
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
"
|
|
239
|
-
|
|
240
|
-
type: String
|
|
241
|
-
},
|
|
242
|
-
"-m, --middleware-position <templateType>": {
|
|
243
|
-
description: "Middleware position (before, after)",
|
|
244
|
-
type: String
|
|
245
|
-
}
|
|
88
|
+
"-d, --directory <directory>": {
|
|
89
|
+
description: "Directory where the file must be generated",
|
|
90
|
+
type: String
|
|
91
|
+
},
|
|
92
|
+
"-t, --template-type <templateType>": {
|
|
93
|
+
description: "Directory where the file must be generated",
|
|
94
|
+
type: String
|
|
95
|
+
},
|
|
96
|
+
"-m, --middleware-position <templateType>": {
|
|
97
|
+
description: "Middleware position (before, after)",
|
|
98
|
+
type: String
|
|
246
99
|
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
], GenerateCmd);
|
|
250
|
-
export { GenerateCmd };
|
|
100
|
+
}
|
|
101
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { inject, ProjectPackageJson } from "@tsed/cli-core";
|
|
2
|
+
import { normalizePath } from "@tsed/normalize-path";
|
|
3
|
+
import { ProjectConvention } from "../../../interfaces/ProjectConvention.js";
|
|
4
|
+
import { OutputFilePathPipe } from "../../../pipes/OutputFilePathPipe.js";
|
|
5
|
+
import { SymbolNamePipe } from "../../../pipes/SymbolNamePipe.js";
|
|
6
|
+
export function mapGenerateContext(ctx) {
|
|
7
|
+
const classNamePipe = inject(SymbolNamePipe);
|
|
8
|
+
const outputFilePathPipe = inject(OutputFilePathPipe);
|
|
9
|
+
const projectPackageJson = inject(ProjectPackageJson);
|
|
10
|
+
const { name = "" } = ctx;
|
|
11
|
+
let { type = "" } = ctx;
|
|
12
|
+
type = type.toLowerCase();
|
|
13
|
+
if (ctx.name === "prisma" && ctx.name) {
|
|
14
|
+
type = "prisma.service";
|
|
15
|
+
}
|
|
16
|
+
const symbolName = classNamePipe.transform({ name, type, format: ProjectConvention.DEFAULT });
|
|
17
|
+
const symbolPath = normalizePath(outputFilePathPipe.transform({
|
|
18
|
+
name,
|
|
19
|
+
type,
|
|
20
|
+
subDir: ctx.directory
|
|
21
|
+
}));
|
|
22
|
+
return {
|
|
23
|
+
...projectPackageJson.fillWithPreferences(ctx),
|
|
24
|
+
type,
|
|
25
|
+
symbolName,
|
|
26
|
+
symbolPath,
|
|
27
|
+
symbolPathBasename: normalizePath(classNamePipe.transform({ name, type }))
|
|
28
|
+
};
|
|
29
|
+
}
|