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