@tsed/cli-core 7.0.0-beta.10 → 7.0.0-beta.11

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,5 +1,6 @@
1
1
  import "@tsed/logger-std";
2
2
  import { join, resolve } from "node:path";
3
+ import { PromptCancelledError } from "@tsed/cli-prompts";
3
4
  import { constant, inject, injector } from "@tsed/di";
4
5
  import { $asyncEmit } from "@tsed/hooks";
5
6
  import chalk from "chalk";
@@ -88,6 +89,10 @@ export class CliCore {
88
89
  await cliService.parseArgs(constant("argv"));
89
90
  }
90
91
  catch (er) {
92
+ if (er instanceof PromptCancelledError) {
93
+ console.log(chalk.yellow("Prompt cancelled."));
94
+ return this;
95
+ }
91
96
  throw new CliError({ origin: er, cli: this });
92
97
  }
93
98
  return this;
package/lib/esm/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import "./utils/patchCommander.js";
2
- import Inquirer from "inquirer";
3
2
  export * from "./CliCore.js";
4
3
  export * from "./decorators/index.js";
5
4
  export * from "./fn/command.js";
@@ -7,8 +6,8 @@ export * from "./interfaces/index.js";
7
6
  export * from "./packageManagers/index.js";
8
7
  export * from "./services/index.js";
9
8
  export * from "./utils/index.js";
9
+ export * from "@tsed/cli-prompts";
10
10
  export * from "@tsed/core";
11
11
  export * from "@tsed/di";
12
12
  export * from "@tsed/logger";
13
13
  export * from "@tsed/normalize-path";
14
- export { Inquirer };
@@ -1,2 +1 @@
1
- import "inquirer-autocomplete-prompt";
2
- import AutocompletePrompt from "inquirer-autocomplete-prompt";
1
+ export {};
@@ -1,4 +1,3 @@
1
- import { Type } from "@tsed/core";
2
1
  export * from "./CliDefaultOptions.js";
3
2
  export * from "./CommandData.js";
4
3
  export * from "./CommandMetadata.js";
@@ -1,10 +1,9 @@
1
+ import { PromptRunner } from "@tsed/cli-prompts";
1
2
  import { classOf, isArrowFn } from "@tsed/core";
2
3
  import { configuration, constant, context, destroyInjector, DIContext, getContext, inject, injectable, injector, logger, Provider, runInContext } from "@tsed/di";
3
4
  import { $asyncAlter, $asyncEmit } from "@tsed/hooks";
4
5
  import { pascalCase } from "change-case";
5
6
  import { Argument, Command } from "commander";
6
- import Inquirer from "inquirer";
7
- import inquirer_autocomplete_prompt from "inquirer-autocomplete-prompt";
8
7
  import { v4 } from "uuid";
9
8
  import { PackageManagersModule } from "../packageManagers/index.js";
10
9
  import { createSubTasks, createTasksRunner } from "../utils/createTasksRunner.js";
@@ -14,7 +13,6 @@ import { mapCommanderArgs } from "../utils/mapCommanderArgs.js";
14
13
  import { parseOption } from "../utils/parseOption.js";
15
14
  import { CliHooks } from "./CliHooks.js";
16
15
  import { ProjectPackageJson } from "./ProjectPackageJson.js";
17
- Inquirer.registerPrompt("autocomplete", inquirer_autocomplete_prompt);
18
16
  export class CliService {
19
17
  constructor() {
20
18
  this.reinstallAfterRun = constant("project.reinstallAfterRun", false);
@@ -23,6 +21,7 @@ export class CliService {
23
21
  this.hooks = inject(CliHooks);
24
22
  this.projectPkg = inject(ProjectPackageJson);
25
23
  this.packageManagers = inject(PackageManagersModule);
24
+ this.promptRunner = inject(PromptRunner);
26
25
  this.commands = new Map();
27
26
  }
28
27
  /**
@@ -45,17 +44,18 @@ export class CliService {
45
44
  return runInContext($ctx, async () => {
46
45
  $ctx.set("dispatchCmd", cmdName);
47
46
  await $asyncEmit("$loadPackageJson");
48
- data = await this.prompt(cmdName, data, $ctx);
49
47
  try {
48
+ data = await this.prompt(cmdName, data, $ctx);
50
49
  await this.exec(cmdName, data, $ctx);
50
+ await $asyncEmit("$onFinish", [data]);
51
51
  }
52
52
  catch (er) {
53
53
  await $asyncEmit("$onFinish", [data, er]);
54
- await destroyInjector();
55
54
  throw er;
56
55
  }
57
- await $asyncEmit("$onFinish", [data]);
58
- await destroyInjector();
56
+ finally {
57
+ await destroyInjector();
58
+ }
59
59
  });
60
60
  }
61
61
  async exec(cmdName, data, $ctx) {
@@ -84,11 +84,12 @@ export class CliService {
84
84
  const instance = inject(provider.token);
85
85
  $ctx.set("data", data);
86
86
  if (instance.$prompt) {
87
- const questions = [...(await instance.$prompt(data))];
88
- if (questions.length) {
87
+ const questions = await instance.$prompt(data);
88
+ if (questions) {
89
+ const answers = await this.promptRunner.run(questions, data);
89
90
  data = {
90
91
  ...data,
91
- ...(await Inquirer.prompt(questions))
92
+ ...answers
92
93
  };
93
94
  }
94
95
  }
@@ -38,8 +38,8 @@ export declare function command<Input>(options: CommandOptions<Input>): TsED.Pro
38
38
  } | {
39
39
  $prompt: any;
40
40
  $exec: any;
41
- prompt?<T extends import("inquirer").Answers = import("inquirer").Answers>(initialOptions: Partial<Input>): import("../interfaces/CommandProvider.js").QuestionOptions<T> | Promise<import("../interfaces/CommandProvider.js").QuestionOptions<T>>;
42
41
  handler: (data: Input) => import("../interfaces/Tasks.js").Tasks | Promise<import("../interfaces/Tasks.js").Tasks> | any | Promise<any>;
42
+ prompt?(initialOptions: Partial<Input>): import("@tsed/cli-prompts").PromptQuestion[] | Promise<import("@tsed/cli-prompts").PromptQuestion[]>;
43
43
  name: string;
44
44
  alias?: string;
45
45
  description: string;
@@ -1,5 +1,4 @@
1
1
  import "./utils/patchCommander.js";
2
- import Inquirer from "inquirer";
3
2
  export * from "./CliCore.js";
4
3
  export * from "./decorators/index.js";
5
4
  export * from "./fn/command.js";
@@ -7,8 +6,8 @@ export * from "./interfaces/index.js";
7
6
  export * from "./packageManagers/index.js";
8
7
  export * from "./services/index.js";
9
8
  export * from "./utils/index.js";
9
+ export * from "@tsed/cli-prompts";
10
10
  export * from "@tsed/core";
11
11
  export * from "@tsed/di";
12
12
  export * from "@tsed/logger";
13
13
  export * from "@tsed/normalize-path";
14
- export { Inquirer };
@@ -9,4 +9,5 @@ export interface CommandData extends TsED.InitialCommandData {
9
9
  verbose?: boolean;
10
10
  bindLogger?: boolean;
11
11
  rawArgs?: string[];
12
+ [key: string]: any;
12
13
  }
@@ -1,8 +1,8 @@
1
+ import type { PromptQuestion } from "@tsed/cli-prompts";
1
2
  import { Type } from "@tsed/core";
2
3
  import type { TokenProvider } from "@tsed/di";
3
4
  import type { JsonSchema } from "@tsed/schema";
4
- import type { Answers } from "inquirer";
5
- import type { CommandProvider, QuestionOptions } from "./CommandProvider.js";
5
+ import type { CommandProvider } from "./CommandProvider.js";
6
6
  import type { Tasks } from "./Tasks.js";
7
7
  export interface CommandArg {
8
8
  /**
@@ -82,8 +82,8 @@ export interface BaseCommandOptions<Input> {
82
82
  bindLogger?: boolean;
83
83
  }
84
84
  interface FunctionalCommandOptions<Input> extends BaseCommandOptions<Input> {
85
- prompt?<T extends Answers = Answers>(initialOptions: Partial<Input>): QuestionOptions<T> | Promise<QuestionOptions<T>>;
86
85
  handler: (data: Input) => Tasks | Promise<Tasks> | any | Promise<any>;
86
+ prompt?(initialOptions: Partial<Input>): PromptQuestion[] | Promise<PromptQuestion[]>;
87
87
  [key: string]: any;
88
88
  }
89
89
  export interface ClassCommandOptions<Input> extends BaseCommandOptions<Input> {
@@ -1,20 +1,12 @@
1
- import "inquirer-autocomplete-prompt";
2
- import type { Answers, QuestionCollection } from "inquirer";
3
- import AutocompletePrompt from "inquirer-autocomplete-prompt";
1
+ import type { PromptQuestion } from "@tsed/cli-prompts";
4
2
  import type { Tasks } from "./Tasks.js";
5
- declare module "inquirer" {
6
- interface QuestionMap<T extends Answers = Answers> {
7
- autocomplete: AutocompletePrompt.AutocompleteQuestionOptions<T>;
8
- }
9
- }
10
- export type QuestionOptions<T extends Answers = Answers> = QuestionCollection<T>;
11
3
  export interface CommandProvider<Ctx = any> {
12
4
  /**
13
- * Hook to create the main prompt for the command
14
- * See https://github.com/enquirer/enquirer for more detail on question configuration.
5
+ * Hook to create the main prompt for the command. Refer to {@link PromptQuestion}
6
+ * for supported question attributes.
15
7
  * @param initialOptions
16
8
  */
17
- $prompt?<T extends Answers = Answers>(initialOptions: Partial<Ctx>): QuestionOptions<T> | Promise<QuestionOptions<T>>;
9
+ $prompt?(initialOptions: Partial<Ctx>): PromptQuestion[] | Promise<PromptQuestion[]>;
18
10
  /**
19
11
  * Hook to map options
20
12
  * @param ctx
@@ -1,3 +1,4 @@
1
+ import { PromptRunner } from "@tsed/cli-prompts";
1
2
  import { DIContext } from "@tsed/di";
2
3
  import { Command } from "commander";
3
4
  import type { CommandData } from "../interfaces/CommandData.js";
@@ -13,6 +14,7 @@ export declare class CliService {
13
14
  protected hooks: CliHooks;
14
15
  protected projectPkg: ProjectPackageJson;
15
16
  protected packageManagers: PackageManagersModule;
17
+ protected promptRunner: PromptRunner;
16
18
  private commands;
17
19
  /**
18
20
  * Parse process.argv and runLifecycle action
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tsed/cli-core",
3
3
  "description": "Build your CLI with TypeScript and Decorators",
4
- "version": "7.0.0-beta.10",
4
+ "version": "7.0.0-beta.11",
5
5
  "type": "module",
6
6
  "main": "./lib/esm/index.js",
7
7
  "source": "./src/index.ts",
@@ -28,28 +28,25 @@
28
28
  "api",
29
29
  "decorators",
30
30
  "commander.js",
31
- "inquirer.js",
31
+ "prompts",
32
32
  "listr"
33
33
  ],
34
34
  "dependencies": {
35
35
  "@ts-morph/common": "0.28.0",
36
+ "@tsed/cli-prompts": "7.0.0-beta.11",
36
37
  "@tsed/logger": ">=8.0.3",
37
38
  "@tsed/logger-pattern-layout": ">=8.0.3",
38
39
  "@tsed/logger-std": ">=8.0.3",
39
40
  "@tsed/normalize-path": ">=8.0.0",
40
- "@types/inquirer": "^9.0.7",
41
41
  "ajv": "^8.17.1",
42
42
  "axios": "^1.7.7",
43
43
  "chalk": "^5.3.0",
44
44
  "change-case": "^5.4.4",
45
45
  "commander": "^12.1.0",
46
- "enquirer": "^2.4.1",
47
46
  "execa": "^8.0.1",
48
47
  "figures": "^6.1.0",
49
48
  "fs-extra": "^11.2.0",
50
49
  "globby": "^14.0.2",
51
- "inquirer": "^9.3.7",
52
- "inquirer-autocomplete-prompt": "^3.0.1",
53
50
  "js-yaml": "^4.1.0",
54
51
  "listr2": "^8.2.4",
55
52
  "read-pkg-up": "^11.0.0",
@@ -65,7 +62,7 @@
65
62
  "uuid": "^10.0.0"
66
63
  },
67
64
  "devDependencies": {
68
- "@tsed/typescript": "7.0.0-beta.10",
65
+ "@tsed/typescript": "7.0.0-beta.11",
69
66
  "@types/commander": "2.12.2",
70
67
  "@types/figures": "3.0.1",
71
68
  "@types/fs-extra": "^11.0.4",
package/readme.md CHANGED
@@ -116,7 +116,7 @@ export class GenerateCmd implements CommandProvider {
116
116
  srcRenderService: SrcRendererService;
117
117
 
118
118
  /**
119
- * Prompt use Inquirer.js to print questions (see Inquirer.js for more details)
119
+ * Prompts run through the Ts.ED prompt runner (powered by `@clack/prompts`) to gather inputs
120
120
  */
121
121
  $prompt(initialOptions: Partial<GenerateCmdContext>) {
122
122
  return [