@tsed/cli 7.0.0-beta.8 → 7.0.0-rc.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 +5 -10
- package/lib/esm/commands/generate/GenerateCmd.js +6 -15
- package/lib/esm/commands/init/InitCmd.js +16 -14
- package/lib/esm/commands/init/config/FeaturesPrompt.js +19 -3
- package/lib/esm/commands/run/RunCmd.js +2 -2
- package/lib/esm/commands/template/CreateTemplateCommand.js +1 -10
- package/lib/esm/commands/update/UpdateCmd.js +2 -7
- package/lib/esm/processors/transformServerFile.js +5 -7
- package/lib/esm/templates/agents.template.js +17 -0
- package/lib/esm/templates/barrels.template.js +1 -5
- package/lib/esm/templates/command.template.js +6 -4
- package/lib/esm/templates/controller.template.js +6 -1
- package/lib/esm/templates/index.command.template.js +1 -1
- package/lib/esm/templates/index.controller.template.js +12 -8
- package/lib/esm/templates/index.js +1 -0
- package/lib/esm/templates/index.template.js +13 -23
- 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 +2 -39
- package/lib/types/commands/index.d.ts +16 -12
- package/lib/types/commands/init/InitCmd.d.ts +6 -7
- package/lib/types/commands/init/InitOptionsCmd.d.ts +8 -6
- package/lib/types/commands/init/config/FeaturesPrompt.d.ts +32 -4
- package/lib/types/commands/mcp/McpCommand.d.ts +8 -6
- package/lib/types/commands/run/RunCmd.d.ts +2 -2
- package/lib/types/commands/template/CreateTemplateCommand.d.ts +5 -5
- package/lib/types/commands/update/UpdateCmd.d.ts +3 -2
- package/lib/types/fn/exec.d.ts +1 -1
- package/lib/types/templates/agents.template.d.ts +17 -0
- package/lib/types/templates/asyncFactory.template.d.ts +1 -1
- package/lib/types/templates/barrels.template.d.ts +1 -1
- package/lib/types/templates/command.template.d.ts +1 -1
- package/lib/types/templates/config.template.d.ts +1 -1
- package/lib/types/templates/controller.template.d.ts +1 -1
- package/lib/types/templates/decorator.template.d.ts +1 -1
- package/lib/types/templates/docker-compose.template.d.ts +1 -1
- package/lib/types/templates/exception-filter.template.d.ts +1 -1
- package/lib/types/templates/factory.template.d.ts +1 -1
- package/lib/types/templates/index.command.template.d.ts +1 -1
- package/lib/types/templates/index.config.utils.template.d.ts +1 -1
- package/lib/types/templates/index.controller.template.d.ts +1 -1
- package/lib/types/templates/index.d.ts +1 -0
- package/lib/types/templates/index.logger.template.d.ts +1 -1
- package/lib/types/templates/index.template.d.ts +1 -1
- package/lib/types/templates/interceptor.template.d.ts +1 -1
- package/lib/types/templates/interface.template.d.ts +1 -1
- package/lib/types/templates/middleware.template.d.ts +1 -1
- package/lib/types/templates/model.template.d.ts +1 -1
- package/lib/types/templates/module.template.d.ts +1 -1
- package/lib/types/templates/pipe.template.d.ts +1 -1
- package/lib/types/templates/prisma.service.template.d.ts +1 -1
- package/lib/types/templates/readme.template.d.ts +1 -1
- package/lib/types/templates/repository.template.d.ts +1 -1
- package/lib/types/templates/response-filter.template.d.ts +1 -1
- package/lib/types/templates/server.template.d.ts +1 -1
- package/lib/types/templates/service.template.d.ts +1 -1
- package/lib/types/templates/tsconfig.spec.template.d.ts +1 -1
- package/lib/types/templates/value.template.d.ts +1 -1
- package/lib/types/utils/defineTemplate.d.ts +3 -3
- package/package.json +7 -5
- package/templates/views/home.ejs +347 -0
- package/templates/views/swagger.ejs +0 -100
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CliPlugins, command,
|
|
1
|
+
import { CliPlugins, command, inject, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
|
|
2
2
|
export class AddCmd {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.cliPlugins = inject(CliPlugins);
|
|
@@ -13,30 +13,25 @@ export class AddCmd {
|
|
|
13
13
|
message: "Which cli plugin ?",
|
|
14
14
|
default: initialOptions.name,
|
|
15
15
|
when: !initialOptions.name,
|
|
16
|
-
source: (
|
|
17
|
-
return this.cliPlugins.searchPlugins(keyword);
|
|
18
|
-
}
|
|
16
|
+
source: () => this.cliPlugins.searchPlugins()
|
|
19
17
|
}
|
|
20
18
|
];
|
|
21
19
|
}
|
|
22
20
|
$exec(ctx) {
|
|
23
21
|
this.packageJson.addDevDependency(ctx.name, "latest");
|
|
24
22
|
return [
|
|
25
|
-
|
|
26
|
-
title: "Install plugins",
|
|
27
|
-
task: createSubTasks(() => this.packageManagers.install(ctx), { ...ctx, concurrent: false })
|
|
28
|
-
},
|
|
23
|
+
this.packageManagers.task("Install plugins", ctx),
|
|
29
24
|
{
|
|
30
25
|
title: "Load plugins",
|
|
31
26
|
task: () => this.cliPlugins.loadPlugins()
|
|
32
27
|
},
|
|
33
28
|
{
|
|
34
29
|
title: "Install plugins dependencies",
|
|
35
|
-
task:
|
|
30
|
+
task: () => this.cliPlugins.addPluginsDependencies(ctx)
|
|
36
31
|
},
|
|
37
32
|
{
|
|
38
33
|
title: "Transform files",
|
|
39
|
-
task:
|
|
34
|
+
task: () => this.cliPlugins.addPluginsDependencies(ctx)
|
|
40
35
|
}
|
|
41
36
|
];
|
|
42
37
|
}
|
|
@@ -3,14 +3,8 @@ import { CliProjectService } from "../../services/CliProjectService.js";
|
|
|
3
3
|
import { CliTemplatesService } from "../../services/CliTemplatesService.js";
|
|
4
4
|
import { addContextMethods } from "../../services/mappers/addContextMethods.js";
|
|
5
5
|
import { mapDefaultTemplateOptions } from "../../services/mappers/mapDefaultTemplateOptions.js";
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
return (_, keyword) => {
|
|
9
|
-
if (keyword) {
|
|
10
|
-
return items.filter((item) => item.name.toLowerCase().includes(keyword.toLowerCase()));
|
|
11
|
-
}
|
|
12
|
-
return items;
|
|
13
|
-
};
|
|
6
|
+
const mapChoices = (list) => {
|
|
7
|
+
return list.map((item) => ({ label: item.label, value: item.id }));
|
|
14
8
|
};
|
|
15
9
|
export class GenerateCmd {
|
|
16
10
|
constructor() {
|
|
@@ -21,11 +15,8 @@ export class GenerateCmd {
|
|
|
21
15
|
async $prompt(data) {
|
|
22
16
|
data = addContextMethods(data);
|
|
23
17
|
const templates = this.templates.find();
|
|
24
|
-
const templatesPrompts = await Promise.all(templates
|
|
25
|
-
|
|
26
|
-
.map((template) => {
|
|
27
|
-
return template.prompts(data);
|
|
28
|
-
}));
|
|
18
|
+
const templatesPrompts = await Promise.all(templates.filter((template) => template.prompts).map((template) => template.prompts(data)));
|
|
19
|
+
const additionalPrompts = templatesPrompts.flat();
|
|
29
20
|
return [
|
|
30
21
|
{
|
|
31
22
|
type: "autocomplete",
|
|
@@ -33,7 +24,7 @@ export class GenerateCmd {
|
|
|
33
24
|
message: "Which template you want to use?",
|
|
34
25
|
default: data.type,
|
|
35
26
|
when: () => templates.length > 1,
|
|
36
|
-
|
|
27
|
+
choices: mapChoices(this.templates.find(data.type))
|
|
37
28
|
},
|
|
38
29
|
{
|
|
39
30
|
type: "input",
|
|
@@ -42,7 +33,7 @@ export class GenerateCmd {
|
|
|
42
33
|
default: data.getName,
|
|
43
34
|
when: !data.name
|
|
44
35
|
},
|
|
45
|
-
...
|
|
36
|
+
...additionalPrompts
|
|
46
37
|
];
|
|
47
38
|
}
|
|
48
39
|
$mapContext(ctx) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { basename, join } from "node:path";
|
|
2
|
-
import { CliExeca, CliFs, CliLoadFile, cliPackageJson, CliPlugins, command, Configuration,
|
|
2
|
+
import { CliExeca, CliFs, CliLoadFile, cliPackageJson, CliPlugins, command, Configuration, inject, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
|
|
3
|
+
import { tasks } from "@tsed/cli-tasks";
|
|
3
4
|
import { isString } from "@tsed/core";
|
|
4
5
|
import { constant } from "@tsed/di";
|
|
5
6
|
import { $asyncAlter } from "@tsed/hooks";
|
|
@@ -8,7 +9,6 @@ import { TEMPLATE_DIR } from "../../constants/index.js";
|
|
|
8
9
|
import { exec } from "../../fn/exec.js";
|
|
9
10
|
import { render } from "../../fn/render.js";
|
|
10
11
|
import { taskOutput } from "../../fn/taskOutput.js";
|
|
11
|
-
import {} from "../../interfaces/index.js";
|
|
12
12
|
import { PlatformsModule } from "../../platforms/PlatformsModule.js";
|
|
13
13
|
import { RuntimesModule } from "../../runtimes/RuntimesModule.js";
|
|
14
14
|
import { BunRuntime } from "../../runtimes/supports/BunRuntime.js";
|
|
@@ -75,7 +75,7 @@ export class InitCmd {
|
|
|
75
75
|
srcDir: constant("project.srcDir", "src")
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
preExec(ctx) {
|
|
79
79
|
this.fs.ensureDirSync(this.packageJson.cwd);
|
|
80
80
|
ctx.projectName && (this.packageJson.name = ctx.projectName);
|
|
81
81
|
ctx.packageManager && this.packageJson.setPreference("packageManager", ctx.packageManager);
|
|
@@ -84,7 +84,7 @@ export class InitCmd {
|
|
|
84
84
|
ctx.convention && this.packageJson.setPreference("convention", ctx.convention);
|
|
85
85
|
ctx.platform && this.packageJson.setPreference("platform", ctx.platform);
|
|
86
86
|
ctx.GH_TOKEN && this.packageJson.setGhToken(ctx.GH_TOKEN);
|
|
87
|
-
|
|
87
|
+
return tasks([
|
|
88
88
|
{
|
|
89
89
|
title: "Write RC files",
|
|
90
90
|
skip: () => !ctx.premium,
|
|
@@ -102,19 +102,19 @@ export class InitCmd {
|
|
|
102
102
|
this.addFeatures(ctx);
|
|
103
103
|
}
|
|
104
104
|
},
|
|
105
|
-
|
|
106
|
-
title: "Install plugins",
|
|
107
|
-
task: createSubTasks(() => this.packageManagers.install(ctx), { ...ctx, concurrent: false })
|
|
108
|
-
},
|
|
105
|
+
this.packageManagers.task("Install plugins", ctx),
|
|
109
106
|
{
|
|
110
107
|
title: "Load plugins",
|
|
111
108
|
task: () => this.cliPlugins.loadPlugins()
|
|
112
109
|
},
|
|
113
110
|
{
|
|
114
111
|
title: "Install plugins dependencies",
|
|
115
|
-
task:
|
|
112
|
+
task: () => this.cliPlugins.addPluginsDependencies(ctx)
|
|
116
113
|
}
|
|
117
114
|
], ctx);
|
|
115
|
+
}
|
|
116
|
+
async $exec(ctx) {
|
|
117
|
+
await this.preExec(ctx);
|
|
118
118
|
const runtime = this.runtimes.get();
|
|
119
119
|
ctx = {
|
|
120
120
|
...ctx,
|
|
@@ -129,13 +129,13 @@ export class InitCmd {
|
|
|
129
129
|
},
|
|
130
130
|
{
|
|
131
131
|
title: "Alter package json",
|
|
132
|
-
task: () => {
|
|
133
|
-
|
|
132
|
+
task: async () => {
|
|
133
|
+
await $asyncAlter("$alterPackageJson", this.packageJson, [ctx]);
|
|
134
134
|
}
|
|
135
135
|
},
|
|
136
136
|
{
|
|
137
137
|
title: "Generate additional project files",
|
|
138
|
-
task:
|
|
138
|
+
task: async () => {
|
|
139
139
|
const subTasks = [
|
|
140
140
|
...(await exec("generate", {
|
|
141
141
|
//...ctx,
|
|
@@ -154,7 +154,7 @@ export class InitCmd {
|
|
|
154
154
|
: [])
|
|
155
155
|
];
|
|
156
156
|
return $asyncAlter("$alterInitSubTasks", subTasks, [ctx]);
|
|
157
|
-
}
|
|
157
|
+
}
|
|
158
158
|
},
|
|
159
159
|
{
|
|
160
160
|
title: "transform generated files to the project configuration",
|
|
@@ -166,6 +166,7 @@ export class InitCmd {
|
|
|
166
166
|
}
|
|
167
167
|
$afterPostInstall() {
|
|
168
168
|
return [
|
|
169
|
+
this.packageManagers.task("Check installed dependencies"),
|
|
169
170
|
{
|
|
170
171
|
title: "Generate barrels files",
|
|
171
172
|
task: () => {
|
|
@@ -279,8 +280,9 @@ export class InitCmd {
|
|
|
279
280
|
ctx.commands && "index.command",
|
|
280
281
|
"barrels",
|
|
281
282
|
"readme",
|
|
283
|
+
"agents",
|
|
282
284
|
`pm2.${pm2}`,
|
|
283
|
-
|
|
285
|
+
"/views/home.ejs",
|
|
284
286
|
...runtime.files()
|
|
285
287
|
].map((id) => {
|
|
286
288
|
return id && render(id, ctx);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CliHttpClient } from "@tsed/cli-core";
|
|
2
|
+
import { inject } from "@tsed/di";
|
|
1
3
|
import { ArchitectureConvention, PlatformType, ProjectConvention } from "../../../interfaces/index.js";
|
|
2
4
|
import { hasFeature, hasValue, hasValuePremium } from "../utils/hasFeature.js";
|
|
3
5
|
import { isPlatform } from "../utils/isPlatform.js";
|
|
@@ -127,9 +129,6 @@ export const FeaturesMap = {
|
|
|
127
129
|
name: "Commands",
|
|
128
130
|
dependencies: {
|
|
129
131
|
"@tsed/cli-core": "{{cliVersion}}"
|
|
130
|
-
},
|
|
131
|
-
devDependencies: {
|
|
132
|
-
"@types/inquirer": "^8.2.4"
|
|
133
132
|
}
|
|
134
133
|
},
|
|
135
134
|
[ProjectConvention.DEFAULT]: {
|
|
@@ -452,6 +451,23 @@ export const FeaturesPrompt = (availableRuntimes, availablePackageManagers) => [
|
|
|
452
451
|
],
|
|
453
452
|
when: hasValue("featuresDB", FeatureType.TYPEORM)
|
|
454
453
|
},
|
|
454
|
+
{
|
|
455
|
+
type: "autocomplete",
|
|
456
|
+
name: "passportPackage",
|
|
457
|
+
message: "Which passport package ?",
|
|
458
|
+
when: hasFeature(FeatureType.PASSPORTJS),
|
|
459
|
+
async source(_) {
|
|
460
|
+
const result = await inject(CliHttpClient).get(`https://www.passportjs.org/packages/-/all.json`, {});
|
|
461
|
+
return Object.values(result)
|
|
462
|
+
.filter((o) => {
|
|
463
|
+
return o.name && o.name?.startsWith("passport-");
|
|
464
|
+
})
|
|
465
|
+
.map((item) => ({
|
|
466
|
+
name: `${item.name} - ${item.description}`,
|
|
467
|
+
value: item.name
|
|
468
|
+
}));
|
|
469
|
+
}
|
|
470
|
+
},
|
|
455
471
|
{
|
|
456
472
|
type: "password",
|
|
457
473
|
name: "GH_TOKEN",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CliFs, command, inject, normalizePath, ProjectPackageJson } from "@tsed/cli-core";
|
|
2
|
+
import { taskLogger } from "@tsed/cli-tasks";
|
|
2
3
|
import { logger } from "@tsed/di";
|
|
3
4
|
import { CliRunScript } from "../../services/CliRunScript.js";
|
|
4
5
|
export class RunCmd {
|
|
@@ -11,11 +12,10 @@ export class RunCmd {
|
|
|
11
12
|
const cmd = "node";
|
|
12
13
|
const args = ["--import", "@swc-node/register/esm-register"];
|
|
13
14
|
const path = normalizePath("src/bin/index.ts");
|
|
14
|
-
|
|
15
|
+
taskLogger().info(`Run ${cmd} ${[...args, path, ctx.command, ...ctx.rawArgs].join(" ")}`);
|
|
15
16
|
await this.runScript.run(cmd, [...args, path, ctx.command, ...ctx.rawArgs], {
|
|
16
17
|
env: process.env
|
|
17
18
|
});
|
|
18
|
-
return [];
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
command({
|
|
@@ -3,15 +3,6 @@ import { snakeCase } from "change-case";
|
|
|
3
3
|
import { PKG } from "../../constants/index.js";
|
|
4
4
|
import { render } from "../../fn/render.js";
|
|
5
5
|
import { CliTemplatesService } from "../../services/CliTemplatesService.js";
|
|
6
|
-
const searchFactory = (list) => {
|
|
7
|
-
const items = list.map((item) => ({ name: item.label, value: item.id }));
|
|
8
|
-
return (_, keyword) => {
|
|
9
|
-
if (keyword) {
|
|
10
|
-
return items.filter((item) => item.name.toLowerCase().includes(keyword.toLowerCase()));
|
|
11
|
-
}
|
|
12
|
-
return items;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
6
|
export class CreateTemplateCommand {
|
|
16
7
|
constructor() {
|
|
17
8
|
this.projectPackageJson = inject(ProjectPackageJson);
|
|
@@ -38,7 +29,7 @@ export class CreateTemplateCommand {
|
|
|
38
29
|
when: (ctx) => {
|
|
39
30
|
return ctx.from === "existing";
|
|
40
31
|
},
|
|
41
|
-
source:
|
|
32
|
+
source: () => this.templates.find().map((item) => ({ name: item.label, value: item.id }))
|
|
42
33
|
},
|
|
43
34
|
{
|
|
44
35
|
type: "confirm",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CliPackageJson, command,
|
|
1
|
+
import { CliPackageJson, command, inject, NpmRegistryClient, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
|
|
2
2
|
import { getValue } from "@tsed/core";
|
|
3
3
|
import semver from "semver";
|
|
4
4
|
import { IGNORE_TAGS, IGNORE_VERSIONS, MINIMAL_TSED_VERSION } from "../../constants/index.js";
|
|
@@ -59,12 +59,7 @@ export class UpdateCmd {
|
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
return [
|
|
63
|
-
{
|
|
64
|
-
title: "Update packages",
|
|
65
|
-
task: createSubTasks(() => this.packageManagers.install(), { ...ctx, concurrent: false })
|
|
66
|
-
}
|
|
67
|
-
];
|
|
62
|
+
return [this.packageManagers.task("Update dependencies", ctx)];
|
|
68
63
|
}
|
|
69
64
|
async getAvailableVersions() {
|
|
70
65
|
const { versions } = await this.npmRegistryClient.info("@tsed/platform-http", 10);
|
|
@@ -49,12 +49,10 @@ export function transformServerFile(project, data) {
|
|
|
49
49
|
});
|
|
50
50
|
project.addNamespaceImport(sourceFile, isFeature ? "./rest/index.js" : "./controllers/rest/index.js", "rest");
|
|
51
51
|
project.addMountPath(data.route || "/rest", "...Object.values(rest)");
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
project.addMountPath("/", "...Object.values(pages)");
|
|
58
|
-
}
|
|
52
|
+
sourceFile.addImportDeclaration({
|
|
53
|
+
moduleSpecifier: isFeature ? "./pages/index.js" : "./controllers/pages/index.js",
|
|
54
|
+
namespaceImport: "pages"
|
|
55
|
+
});
|
|
56
|
+
project.addMountPath("/", "...Object.values(pages)");
|
|
59
57
|
}
|
|
60
58
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineTemplate } from "../utils/defineTemplate.js";
|
|
2
|
+
import { CliHttpClient } from "@tsed/cli-core";
|
|
3
|
+
import { inject } from "@tsed/di";
|
|
4
|
+
export default defineTemplate({
|
|
5
|
+
id: "agents",
|
|
6
|
+
label: "AGENTS.md",
|
|
7
|
+
description: "Create AGENTS.md designed for AI project and Ts.ED",
|
|
8
|
+
fileName: "AGENTS",
|
|
9
|
+
ext: "md",
|
|
10
|
+
outputDir: ".",
|
|
11
|
+
hidden: true,
|
|
12
|
+
preserveCase: true,
|
|
13
|
+
async render() {
|
|
14
|
+
const httpClient = inject(CliHttpClient);
|
|
15
|
+
return httpClient.get("https://tsed.dev/ai/AGENTS.md");
|
|
16
|
+
}
|
|
17
|
+
});
|
|
@@ -11,11 +11,7 @@ export default defineTemplate({
|
|
|
11
11
|
preserveCase: true,
|
|
12
12
|
render(_, context) {
|
|
13
13
|
const barrels = $alter("$alterBarrels", {
|
|
14
|
-
directory: [
|
|
15
|
-
"./src/controllers/rest",
|
|
16
|
-
context.commands && "./src/bin/commands",
|
|
17
|
-
(context.swagger || context.oidc) && "./src/controllers/pages"
|
|
18
|
-
].filter(Boolean),
|
|
14
|
+
directory: ["./src/controllers/rest", context.commands && "./src/bin/commands", "./src/controllers/pages"].filter(Boolean),
|
|
19
15
|
exclude: ["**/__mock__", "**/__mocks__", "**/*.spec.ts"],
|
|
20
16
|
delete: true
|
|
21
17
|
});
|
|
@@ -8,7 +8,8 @@ export default defineTemplate({
|
|
|
8
8
|
outputDir: "{{srcDir}}/bin/commands",
|
|
9
9
|
render(symbolName) {
|
|
10
10
|
const symbolParamName = kebabCase(symbolName);
|
|
11
|
-
return `import {Command, CommandProvider
|
|
11
|
+
return `import {Command, CommandProvider} from "@tsed/cli-core";
|
|
12
|
+
import type {PromptOptions} from "@tsed/cli-prompts";
|
|
12
13
|
|
|
13
14
|
export interface ${symbolName}Context {
|
|
14
15
|
}
|
|
@@ -24,9 +25,10 @@ export interface ${symbolName}Context {
|
|
|
24
25
|
})
|
|
25
26
|
export class ${symbolName} implements CommandProvider {
|
|
26
27
|
/**
|
|
27
|
-
* Ask questions with
|
|
28
|
+
* Ask questions with the Ts.ED prompt runner (powered by @clack/prompts).
|
|
29
|
+
* Return an empty array or don't implement the method to skip this step.
|
|
28
30
|
*/
|
|
29
|
-
async $prompt(initialOptions: Partial<${symbolName}Context>): Promise<
|
|
31
|
+
async $prompt(initialOptions: Partial<${symbolName}Context>): Promise<PromptOptions[]> {
|
|
30
32
|
return [];
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -40,7 +42,7 @@ export class ${symbolName} implements CommandProvider {
|
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
43
|
-
* This step
|
|
45
|
+
* This step runs your tasks via the @clack/prompts-based @tsed/cli-tasks helpers.
|
|
44
46
|
*/
|
|
45
47
|
async $exec(ctx: ${symbolName}Context): Promise<any> {
|
|
46
48
|
return [
|
|
@@ -20,7 +20,12 @@ export default defineTemplate({
|
|
|
20
20
|
when(state) {
|
|
21
21
|
return !!(["controller"].includes(state.type || context.type) || context.directory);
|
|
22
22
|
},
|
|
23
|
-
choices: context.getDirectories("controllers")
|
|
23
|
+
choices: context.getDirectories("controllers").map((value) => {
|
|
24
|
+
return {
|
|
25
|
+
label: value,
|
|
26
|
+
value
|
|
27
|
+
};
|
|
28
|
+
})
|
|
24
29
|
},
|
|
25
30
|
{
|
|
26
31
|
type: "input",
|
|
@@ -11,7 +11,7 @@ export default defineTemplate({
|
|
|
11
11
|
return `#!/usr/bin/env node
|
|
12
12
|
import {CliCore} from "@tsed/cli-core";
|
|
13
13
|
import {config} from "@/config/config.js";
|
|
14
|
-
import * commands from "@/bin/commands/index.js";
|
|
14
|
+
import * as commands from "@/bin/commands/index.js";
|
|
15
15
|
|
|
16
16
|
CliCore.bootstrap({
|
|
17
17
|
...config,
|
|
@@ -6,33 +6,37 @@ export default defineTemplate({
|
|
|
6
6
|
outputDir: "{{srcDir}}/controllers/pages",
|
|
7
7
|
fileName: "index.controller",
|
|
8
8
|
hidden: true,
|
|
9
|
-
render() {
|
|
9
|
+
render(_, ctx) {
|
|
10
10
|
return `import {Constant, Controller} from "@tsed/di";
|
|
11
11
|
import {HeaderParams} from "@tsed/platform-params";
|
|
12
|
-
import {View} from "@tsed/
|
|
13
|
-
import {SwaggerSettings} from "@tsed/swagger";
|
|
12
|
+
import {View} from "@tsed/schema";
|
|
13
|
+
${ctx.swagger ? 'import type {SwaggerSettings} from "@tsed/swagger";' : ""}
|
|
14
14
|
import {Hidden, Get, Returns} from "@tsed/schema";
|
|
15
15
|
|
|
16
16
|
@Hidden()
|
|
17
17
|
@Controller("/")
|
|
18
18
|
export class IndexController {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
${ctx.swagger
|
|
20
|
+
? `@Constant("swagger", [])
|
|
21
|
+
private swagger: SwaggerSettings[];`
|
|
22
|
+
: ""}
|
|
21
23
|
|
|
22
24
|
@Get("/")
|
|
23
|
-
@View("
|
|
25
|
+
@View("home.ejs")
|
|
24
26
|
@(Returns(200, String).ContentType("text/html"))
|
|
25
27
|
get(@HeaderParams("x-forwarded-proto") protocol: string, @HeaderParams("host") host: string) {
|
|
26
28
|
const hostUrl = \`\${protocol || "http"}://\${host}\`;
|
|
27
29
|
|
|
28
30
|
return {
|
|
29
31
|
BASE_URL: hostUrl,
|
|
30
|
-
docs:
|
|
32
|
+
docs: ${ctx.swagger
|
|
33
|
+
? `this.swagger.map((conf) => {
|
|
31
34
|
return {
|
|
32
35
|
url: hostUrl + conf.path,
|
|
33
36
|
...conf
|
|
34
37
|
};
|
|
35
|
-
})
|
|
38
|
+
})`
|
|
39
|
+
: "[]"}
|
|
36
40
|
};
|
|
37
41
|
}
|
|
38
42
|
}`;
|
|
@@ -11,35 +11,25 @@ export default defineTemplate({
|
|
|
11
11
|
return `import {$log} from "@tsed/logger";
|
|
12
12
|
import {PlatformBuilder} from "@tsed/platform-http";
|
|
13
13
|
|
|
14
|
-
const SIG_EVENTS = [
|
|
15
|
-
"beforeExit",
|
|
16
|
-
"SIGHUP",
|
|
17
|
-
"SIGINT",
|
|
18
|
-
"SIGQUIT",
|
|
19
|
-
"SIGILL",
|
|
20
|
-
"SIGTRAP",
|
|
21
|
-
"SIGABRT",
|
|
22
|
-
"SIGBUS",
|
|
23
|
-
"SIGFPE",
|
|
24
|
-
"SIGUSR1",
|
|
25
|
-
"SIGSEGV",
|
|
26
|
-
"SIGUSR2",
|
|
27
|
-
"SIGTERM"
|
|
28
|
-
];
|
|
29
|
-
|
|
30
14
|
try {
|
|
31
15
|
const platform = await PlatformBuilder.bootstrap(Server);
|
|
32
16
|
|
|
33
17
|
await platform.listen();
|
|
34
18
|
|
|
35
|
-
|
|
19
|
+
const close = () => {
|
|
20
|
+
$log.warn('Stop server gracefully...');
|
|
21
|
+
|
|
22
|
+
platform
|
|
23
|
+
.stop()
|
|
24
|
+
.then(() => process.exit(0))
|
|
25
|
+
.catch((error) => {
|
|
26
|
+
console.error(error);
|
|
27
|
+
process.exit(-1);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
$log.error({event: "SERVER_" + evt.toUpperCase(), message: error.message, stack: error.stack});
|
|
40
|
-
await platform.stop();
|
|
41
|
-
})
|
|
42
|
-
);
|
|
31
|
+
process.on('SIGINT', close);
|
|
32
|
+
process.on('SIGTERM', close);
|
|
43
33
|
} catch (error) {
|
|
44
34
|
$log.error({event: "SERVER_BOOTSTRAP_ERROR", message: error.message, stack: error.stack});
|
|
45
35
|
}
|