@tsed/cli 6.2.1 → 6.4.0
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/bin/tsed.js +1 -1
- package/lib/esm/commands/generate/GenerateCmd.js +19 -17
- package/lib/esm/commands/init/InitCmd.js +1 -1
- package/lib/esm/commands/init/config/FeaturesPrompt.js +12 -7
- package/lib/esm/commands/init/prompts/getFeaturesPrompt.js +14 -2
- package/lib/esm/interfaces/PlatformType.js +1 -0
- package/lib/esm/platforms/InitPlatformsModule.js +3 -2
- package/lib/esm/platforms/supports/InitFastifyPlatform.js +31 -0
- package/lib/esm/utils/fillImports.js +1 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/commands/generate/GenerateCmd.d.ts +3 -6
- package/lib/types/commands/init/config/FeaturesPrompt.d.ts +7 -0
- package/lib/types/commands/init/prompts/getFeaturesPrompt.d.ts +6 -0
- package/lib/types/interfaces/PlatformType.d.ts +2 -1
- package/lib/types/platforms/supports/InitFastifyPlatform.d.ts +18 -0
- package/package.json +6 -25
- package/templates/generate/server/_partials/server-footer.hbs +10 -0
- package/templates/generate/{server.hbs → server/_partials/server-header.hbs} +0 -29
- package/templates/generate/server/express/server.hbs +10 -0
- package/templates/generate/server/fastify/server.hbs +14 -0
- package/templates/generate/server/koa/server.hbs +8 -0
- package/templates/init/src/config/index.ts.hbs +3 -0
package/lib/esm/bin/tsed.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { register } from "node:module";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
5
|
const EXT = process.env.CLI_MODE === "ts" ? "ts" : "js";
|
|
6
6
|
register(pathToFileURL(join(import.meta.dirname, `../loaders/alias.hook.${EXT}`)), {
|
|
7
7
|
parentURL: import.meta.dirname,
|
|
@@ -12,6 +12,7 @@ import { RoutePipe } from "../../pipes/RoutePipe.js";
|
|
|
12
12
|
import { ProvidersInfoService } from "../../services/ProvidersInfoService.js";
|
|
13
13
|
import { SrcRendererService } from "../../services/Renderer.js";
|
|
14
14
|
import { fillImports } from "../../utils/fillImports.js";
|
|
15
|
+
import { getFrameworksPrompt } from "../init/prompts/getFeaturesPrompt.js";
|
|
15
16
|
import { PROVIDER_TYPES } from "./ProviderTypes.js";
|
|
16
17
|
const DECORATOR_TYPES = [
|
|
17
18
|
{ name: "Class decorator", value: "class" },
|
|
@@ -63,24 +64,13 @@ let GenerateCmd = GenerateCmd_1 = class GenerateCmd {
|
|
|
63
64
|
when: !initialOptions.name
|
|
64
65
|
},
|
|
65
66
|
{
|
|
67
|
+
...getFrameworksPrompt(),
|
|
66
68
|
message: "Which platform?",
|
|
67
69
|
type: "list",
|
|
68
70
|
name: "platform",
|
|
69
71
|
when(state) {
|
|
70
72
|
return ["server"].includes(state.type || initialOptions.type);
|
|
71
|
-
}
|
|
72
|
-
choices: [
|
|
73
|
-
{
|
|
74
|
-
name: "Express.js",
|
|
75
|
-
checked: true,
|
|
76
|
-
value: "express"
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
name: "Koa.js",
|
|
80
|
-
checked: false,
|
|
81
|
-
value: "koa"
|
|
82
|
-
}
|
|
83
|
-
]
|
|
73
|
+
}
|
|
84
74
|
},
|
|
85
75
|
{
|
|
86
76
|
type: "input",
|
|
@@ -154,13 +144,25 @@ let GenerateCmd = GenerateCmd_1 = class GenerateCmd {
|
|
|
154
144
|
const { symbolPath } = ctx;
|
|
155
145
|
if (this.providersList.isMyProvider(ctx.type, GenerateCmd_1)) {
|
|
156
146
|
const type = [ctx.type, ctx.templateType].filter(Boolean).join(".");
|
|
157
|
-
|
|
147
|
+
let template = `generate/${type}.hbs`;
|
|
148
|
+
if (ctx.type === "server") {
|
|
149
|
+
template = `generate/server/${ctx.platform}/server.hbs`;
|
|
150
|
+
}
|
|
158
151
|
return [
|
|
159
152
|
{
|
|
160
153
|
title: `Generate ${ctx.type} file to '${symbolPath}.ts'`,
|
|
161
|
-
task: () =>
|
|
162
|
-
|
|
163
|
-
|
|
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
|
+
}
|
|
164
166
|
},
|
|
165
167
|
{
|
|
166
168
|
title: `Update bin/index`,
|
|
@@ -360,7 +360,7 @@ InitCmd = __decorate([
|
|
|
360
360
|
"-p, --platform <platform>": {
|
|
361
361
|
type: String,
|
|
362
362
|
defaultValue: PlatformType.EXPRESS,
|
|
363
|
-
description: "Set the default platform for Ts.ED (express or
|
|
363
|
+
description: "Set the default platform for Ts.ED (express, koa or fastify)"
|
|
364
364
|
},
|
|
365
365
|
"--features <features...>": {
|
|
366
366
|
type: Array,
|
|
@@ -44,12 +44,16 @@ export var FeatureType;
|
|
|
44
44
|
export const FeaturesMap = {
|
|
45
45
|
[PlatformType.EXPRESS]: {
|
|
46
46
|
name: "Express.js",
|
|
47
|
-
checked: (options) => options.platform
|
|
47
|
+
checked: (options) => options.platform === PlatformType.EXPRESS || !options.platform
|
|
48
48
|
},
|
|
49
49
|
[PlatformType.KOA]: {
|
|
50
50
|
name: "Koa.js",
|
|
51
51
|
checked: (options) => options.platform === PlatformType.KOA
|
|
52
52
|
},
|
|
53
|
+
[PlatformType.FASTIFY]: {
|
|
54
|
+
name: "Fastify.js (beta)",
|
|
55
|
+
checked: (options) => options.platform === PlatformType.FASTIFY
|
|
56
|
+
},
|
|
53
57
|
[FeatureType.GRAPHQL]: {
|
|
54
58
|
name: "TypeGraphQL",
|
|
55
59
|
dependencies: {
|
|
@@ -279,13 +283,14 @@ export const FeaturesMap = {
|
|
|
279
283
|
checked: false
|
|
280
284
|
}
|
|
281
285
|
};
|
|
286
|
+
export const FrameworksPrompt = {
|
|
287
|
+
message: "Choose the target Framework:",
|
|
288
|
+
type: "list",
|
|
289
|
+
name: "platform",
|
|
290
|
+
choices: [PlatformType.EXPRESS, PlatformType.KOA, PlatformType.FASTIFY]
|
|
291
|
+
};
|
|
282
292
|
export const FeaturesPrompt = (availableRuntimes, availablePackageManagers) => [
|
|
283
|
-
|
|
284
|
-
message: "Choose the target Framework:",
|
|
285
|
-
type: "list",
|
|
286
|
-
name: "platform",
|
|
287
|
-
choices: [PlatformType.EXPRESS, PlatformType.KOA]
|
|
288
|
-
},
|
|
293
|
+
FrameworksPrompt,
|
|
289
294
|
{
|
|
290
295
|
message: "Choose the architecture for your project:",
|
|
291
296
|
type: "list",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cleanObject, isFunction } from "@tsed/core";
|
|
2
|
-
import { FeaturesMap, FeaturesPrompt } from "../config/FeaturesPrompt.js";
|
|
2
|
+
import { FeaturesMap, FeaturesPrompt, FrameworksPrompt } from "../config/FeaturesPrompt.js";
|
|
3
3
|
function mapChoices(item, options) {
|
|
4
4
|
return item.choices.map((choice) => {
|
|
5
5
|
const { checked } = FeaturesMap[choice];
|
|
@@ -11,10 +11,22 @@ function mapChoices(item, options) {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
export function getFeaturesPrompt(runtimes, availablePackageManagers, options) {
|
|
14
|
-
return FeaturesPrompt(runtimes, availablePackageManagers).map((item) => {
|
|
14
|
+
return FeaturesPrompt(runtimes, availablePackageManagers).map((item, index) => {
|
|
15
15
|
return cleanObject({
|
|
16
16
|
...item,
|
|
17
17
|
choices: item.choices?.length ? mapChoices(item, options) : undefined
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
+
export function getFrameworksPrompt() {
|
|
22
|
+
return {
|
|
23
|
+
...FrameworksPrompt,
|
|
24
|
+
choices: FrameworksPrompt.choices.map((choice, index) => {
|
|
25
|
+
return cleanObject({
|
|
26
|
+
...FeaturesMap[choice],
|
|
27
|
+
checked: index === 0,
|
|
28
|
+
value: choice
|
|
29
|
+
});
|
|
30
|
+
})
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import {
|
|
2
|
+
import { injectMany } from "@tsed/cli-core";
|
|
3
3
|
import { Module } from "@tsed/di";
|
|
4
4
|
import { InitExpressPlatform } from "./supports/InitExpressPlatform.js";
|
|
5
|
+
import { InitFastifyPlatform } from "./supports/InitFastifyPlatform.js";
|
|
5
6
|
import { InitKoaPlatform } from "./supports/InitKoaPlatform.js";
|
|
6
7
|
let InitPlatformsModule = class InitPlatformsModule {
|
|
7
8
|
constructor() {
|
|
@@ -13,7 +14,7 @@ let InitPlatformsModule = class InitPlatformsModule {
|
|
|
13
14
|
};
|
|
14
15
|
InitPlatformsModule = __decorate([
|
|
15
16
|
Module({
|
|
16
|
-
imports: [InitExpressPlatform, InitKoaPlatform]
|
|
17
|
+
imports: [InitExpressPlatform, InitKoaPlatform, InitFastifyPlatform]
|
|
17
18
|
})
|
|
18
19
|
], InitPlatformsModule);
|
|
19
20
|
export { InitPlatformsModule };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { Injectable } from "@tsed/cli-core";
|
|
3
|
+
let InitFastifyPlatform = class InitFastifyPlatform {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.name = "fastify";
|
|
6
|
+
}
|
|
7
|
+
dependencies(ctx) {
|
|
8
|
+
return {
|
|
9
|
+
"@tsed/platform-fastify": ctx.tsedVersion,
|
|
10
|
+
"@fastify/accepts": "latest",
|
|
11
|
+
"@fastify/middie": "latest",
|
|
12
|
+
"@fastify/static": "latest",
|
|
13
|
+
"@fastify/cookie": "latest",
|
|
14
|
+
"@fastify/formbody": "latest",
|
|
15
|
+
"@fastify/session": "latest",
|
|
16
|
+
fastify: "latest",
|
|
17
|
+
"fastify-raw-body": "latest"
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
devDependencies(ctx) {
|
|
21
|
+
return {
|
|
22
|
+
"@types/content-disposition": "latest"
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
InitFastifyPlatform = __decorate([
|
|
27
|
+
Injectable({
|
|
28
|
+
type: "platform:init"
|
|
29
|
+
})
|
|
30
|
+
], InitFastifyPlatform);
|
|
31
|
+
export { InitFastifyPlatform };
|
|
@@ -16,6 +16,7 @@ export function fillImports(ctx) {
|
|
|
16
16
|
{ from: "@tsed/platform-log-request", comment: " // remove this import if you don't want log request" },
|
|
17
17
|
ctx.express && { from: "@tsed/platform-express", comment: " // /!\\ keep this import" },
|
|
18
18
|
ctx.koa && { from: "@tsed/platform-koa", comment: " // /!\\ keep this import" },
|
|
19
|
+
ctx.fastify && { from: "@tsed/platform-fastify", comment: " // /!\\ keep this import" },
|
|
19
20
|
{ from: "@tsed/ajv" },
|
|
20
21
|
ctx.swagger && { from: "@tsed/swagger" },
|
|
21
22
|
ctx.scalar && { from: "@tsed/scalar" },
|