@tsed/cli 7.0.0-beta.11 → 7.0.0-beta.13

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,4 +1,4 @@
1
- import { CliPlugins, command, createSubTasks, inject, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
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: (state, keyword) => {
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: createSubTasks(() => this.cliPlugins.addPluginsDependencies(ctx), { ...ctx, concurrent: false })
30
+ task: () => this.cliPlugins.addPluginsDependencies(ctx)
36
31
  },
37
32
  {
38
33
  title: "Transform files",
39
- task: createSubTasks(() => this.cliPlugins.addPluginsDependencies(ctx), { ...ctx, concurrent: false })
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 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
- };
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() {
@@ -30,7 +24,7 @@ export class GenerateCmd {
30
24
  message: "Which template you want to use?",
31
25
  default: data.type,
32
26
  when: () => templates.length > 1,
33
- source: searchFactory(this.templates.find(data.type))
27
+ choices: mapChoices(this.templates.find(data.type))
34
28
  },
35
29
  {
36
30
  type: "input",
@@ -1,5 +1,6 @@
1
1
  import { basename, join } from "node:path";
2
- import { CliExeca, CliFs, CliLoadFile, cliPackageJson, CliPlugins, command, Configuration, createSubTasks, createTasksRunner, inject, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
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";
@@ -74,7 +75,7 @@ export class InitCmd {
74
75
  srcDir: constant("project.srcDir", "src")
75
76
  };
76
77
  }
77
- async $exec(ctx) {
78
+ preExec(ctx) {
78
79
  this.fs.ensureDirSync(this.packageJson.cwd);
79
80
  ctx.projectName && (this.packageJson.name = ctx.projectName);
80
81
  ctx.packageManager && this.packageJson.setPreference("packageManager", ctx.packageManager);
@@ -83,7 +84,7 @@ export class InitCmd {
83
84
  ctx.convention && this.packageJson.setPreference("convention", ctx.convention);
84
85
  ctx.platform && this.packageJson.setPreference("platform", ctx.platform);
85
86
  ctx.GH_TOKEN && this.packageJson.setGhToken(ctx.GH_TOKEN);
86
- await createTasksRunner([
87
+ return tasks([
87
88
  {
88
89
  title: "Write RC files",
89
90
  skip: () => !ctx.premium,
@@ -101,19 +102,19 @@ export class InitCmd {
101
102
  this.addFeatures(ctx);
102
103
  }
103
104
  },
104
- {
105
- title: "Install plugins",
106
- task: createSubTasks(() => this.packageManagers.install(ctx), { ...ctx, concurrent: false })
107
- },
105
+ this.packageManagers.task("Install plugins", ctx),
108
106
  {
109
107
  title: "Load plugins",
110
108
  task: () => this.cliPlugins.loadPlugins()
111
109
  },
112
110
  {
113
111
  title: "Install plugins dependencies",
114
- task: createSubTasks(() => this.cliPlugins.addPluginsDependencies(ctx), { ...ctx, concurrent: false })
112
+ task: () => this.cliPlugins.addPluginsDependencies(ctx)
115
113
  }
116
114
  ], ctx);
115
+ }
116
+ async $exec(ctx) {
117
+ await this.preExec(ctx);
117
118
  const runtime = this.runtimes.get();
118
119
  ctx = {
119
120
  ...ctx,
@@ -128,13 +129,13 @@ export class InitCmd {
128
129
  },
129
130
  {
130
131
  title: "Alter package json",
131
- task: () => {
132
- return $asyncAlter("$alterPackageJson", this.packageJson, [ctx]);
132
+ task: async () => {
133
+ await $asyncAlter("$alterPackageJson", this.packageJson, [ctx]);
133
134
  }
134
135
  },
135
136
  {
136
137
  title: "Generate additional project files",
137
- task: createSubTasks(async () => {
138
+ task: async () => {
138
139
  const subTasks = [
139
140
  ...(await exec("generate", {
140
141
  //...ctx,
@@ -153,7 +154,7 @@ export class InitCmd {
153
154
  : [])
154
155
  ];
155
156
  return $asyncAlter("$alterInitSubTasks", subTasks, [ctx]);
156
- }, { ...ctx, concurrent: false })
157
+ }
157
158
  },
158
159
  {
159
160
  title: "transform generated files to the project configuration",
@@ -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";
@@ -449,6 +451,23 @@ export const FeaturesPrompt = (availableRuntimes, availablePackageManagers) => [
449
451
  ],
450
452
  when: hasValue("featuresDB", FeatureType.TYPEORM)
451
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
+ },
452
471
  {
453
472
  type: "password",
454
473
  name: "GH_TOKEN",
@@ -15,7 +15,6 @@ export class RunCmd {
15
15
  await this.runScript.run(cmd, [...args, path, ctx.command, ...ctx.rawArgs], {
16
16
  env: process.env
17
17
  });
18
- return [];
19
18
  }
20
19
  }
21
20
  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: searchFactory(this.templates.find())
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, createSubTasks, inject, NpmRegistryClient, PackageManagersModule, ProjectPackageJson } from "@tsed/cli-core";
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);
@@ -42,7 +42,7 @@ export class ${symbolName} implements CommandProvider {
42
42
  };
43
43
  }
44
44
  /**
45
- * This step run your tasks with Listr module
45
+ * This step runs your tasks via the @clack/prompts-based @tsed/cli-tasks helpers.
46
46
  */
47
47
  async $exec(ctx: ${symbolName}Context): Promise<any> {
48
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",