@tsed/cli 6.1.13 → 6.2.0-beta.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.
@@ -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 { fileURLToPath, pathToFileURL } from "node:url";
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,
@@ -11,6 +11,7 @@ import { OutputFilePathPipe } from "../../pipes/OutputFilePathPipe.js";
11
11
  import { RoutePipe } from "../../pipes/RoutePipe.js";
12
12
  import { ProvidersInfoService } from "../../services/ProvidersInfoService.js";
13
13
  import { fillImports } from "../../utils/fillImports.js";
14
+ import { getFrameworksPrompt } from "../init/prompts/getFeaturesPrompt.js";
14
15
  import { PROVIDER_TYPES } from "./ProviderTypes.js";
15
16
  const DECORATOR_TYPES = [
16
17
  { name: "Class decorator", value: "class" },
@@ -60,24 +61,13 @@ let GenerateCmd = GenerateCmd_1 = class GenerateCmd {
60
61
  when: !initialOptions.name
61
62
  },
62
63
  {
64
+ ...getFrameworksPrompt(),
63
65
  message: "Which platform?",
64
66
  type: "list",
65
67
  name: "platform",
66
68
  when(state) {
67
69
  return ["server"].includes(state.type || initialOptions.type);
68
- },
69
- choices: [
70
- {
71
- name: "Express.js",
72
- checked: true,
73
- value: "express"
74
- },
75
- {
76
- name: "Koa.js",
77
- checked: false,
78
- value: "koa"
79
- }
80
- ]
70
+ }
81
71
  },
82
72
  {
83
73
  type: "input",
@@ -151,13 +141,25 @@ let GenerateCmd = GenerateCmd_1 = class GenerateCmd {
151
141
  const { symbolPath } = ctx;
152
142
  if (this.providersList.isMyProvider(ctx.type, GenerateCmd_1)) {
153
143
  const type = [ctx.type, ctx.templateType].filter(Boolean).join(".");
154
- const template = `generate/${type}.hbs`;
144
+ let template = `generate/${type}.hbs`;
145
+ if (ctx.type === "server") {
146
+ template = `generate/server/${ctx.platform}/server.hbs`;
147
+ }
155
148
  return [
156
149
  {
157
150
  title: `Generate ${ctx.type} file to '${symbolPath}.ts'`,
158
- task: () => this.srcRenderService.render(template, ctx, {
159
- output: `${symbolPath}.ts`
160
- })
151
+ task: () => {
152
+ if (ctx.type === "server") {
153
+ return this.srcRenderService.render(template, ctx, {
154
+ baseDir: "generate",
155
+ basename: `${symbolPath}.ts`,
156
+ replaces: [`server/${ctx.platform}`]
157
+ });
158
+ }
159
+ return this.srcRenderService.render(template, ctx, {
160
+ output: `${symbolPath}.ts`
161
+ });
162
+ }
161
163
  },
162
164
  {
163
165
  title: `Update bin/index`,
@@ -359,7 +359,7 @@ InitCmd = __decorate([
359
359
  "-p, --platform <platform>": {
360
360
  type: String,
361
361
  defaultValue: PlatformType.EXPRESS,
362
- description: "Set the default platform for Ts.ED (express or koa)"
362
+ description: "Set the default platform for Ts.ED (express, koa or fastify)"
363
363
  },
364
364
  "--features <features...>": {
365
365
  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 !== PlatformType.KOA
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,5 +1,6 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { CliFs, CliRunScript, Command, inject, normalizePath, ProjectPackageJson } from "@tsed/cli-core";
3
+ import { Inject } from "@tsed/di";
3
4
  let RunCmd = class RunCmd {
4
5
  constructor() {
5
6
  this.fs = inject(CliFs);
@@ -8,7 +9,7 @@ let RunCmd = class RunCmd {
8
9
  }
9
10
  async $exec(ctx) {
10
11
  const cmd = "node";
11
- const args = ["--import", "@swc-node/register/esm-register"];
12
+ const args = ["--import", "@swc-node/register/register-esm"];
12
13
  const path = normalizePath("src/bin/index.ts");
13
14
  await this.runScript.run(cmd, [...args, path, ctx.command, ...ctx.rawArgs], {
14
15
  env: process.env
@@ -5,7 +5,7 @@ const { path, packageJson } = readPackageUpSync({
5
5
  });
6
6
  export const PKG = packageJson;
7
7
  export const MINIMAL_TSED_VERSION = "8";
8
- export const DEFAULT_TSED_TAGS = "latest";
8
+ export const DEFAULT_TSED_TAGS = "beta";
9
9
  export const IGNORE_VERSIONS = ["6.0.0"];
10
10
  export const IGNORE_TAGS = false; // /alpha|beta/
11
11
  export const TEMPLATE_DIR = join(dirname(path), "templates");
@@ -2,4 +2,5 @@ export var PlatformType;
2
2
  (function (PlatformType) {
3
3
  PlatformType["EXPRESS"] = "express";
4
4
  PlatformType["KOA"] = "koa";
5
+ PlatformType["FASTIFY"] = "fastify";
5
6
  })(PlatformType || (PlatformType = {}));
@@ -1,7 +1,8 @@
1
1
  import { __decorate } from "tslib";
2
- import { Inject, injectMany } from "@tsed/cli-core";
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" },