Skip to content

Commit 1cc99a9

Browse files
committed
chore(deps): replace inquirer with @inquirer/select
1 parent dae9a80 commit 1cc99a9

File tree

4 files changed

+136
-149
lines changed

4 files changed

+136
-149
lines changed

apps/generator-cli/src/app/controllers/version-manager.controller.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class VersionManagerController {
2626
@Inject(LOGGER) private readonly logger: LOGGER,
2727
@Inject(COMMANDER_PROGRAM) private readonly program: Command,
2828
private readonly ui: UIService,
29-
private readonly service: VersionManagerService
29+
private readonly service: VersionManagerService,
3030
) {}
3131

3232
private list = async (versionTags: string[]) => {
@@ -43,8 +43,12 @@ export class VersionManagerController {
4343
}
4444

4545
const { version, installed } = await this.table(versions);
46-
const isSelected = await this.service.isSelectedVersion(version);
47-
const choice = (name: string, cb = () => null, color = (v) => v) => ({
46+
const isSelected = this.service.isSelectedVersion(version);
47+
const choice = (
48+
name: string,
49+
cb: () => Promise<unknown> = () => Promise.resolve(),
50+
color = (v: string) => v,
51+
) => ({
4852
name: color(name),
4953
value: cb,
5054
});
@@ -53,11 +57,11 @@ export class VersionManagerController {
5357

5458
if (!installed) {
5559
choices.unshift(
56-
choice('download', () => this.service.download(version), chalk.yellow)
60+
choice('download', () => this.service.download(version), chalk.yellow),
5761
);
5862
} else if (!isSelected) {
5963
choices.unshift(
60-
choice('remove', () => this.service.remove(version), chalk.red)
64+
choice('remove', () => this.service.remove(version), chalk.red),
6165
);
6266
}
6367

@@ -66,13 +70,13 @@ export class VersionManagerController {
6670
choice(
6771
'use',
6872
() => this.service.setSelectedVersion(version),
69-
chalk.green
70-
)
73+
chalk.green,
74+
),
7175
);
7276
}
7377

7478
await (
75-
await this.ui.list({ name: 'next', message: 'Whats next?', choices })
79+
await this.ui.list({ message: 'Whats next?', choices })
7680
)();
7781
};
7882

@@ -86,21 +90,20 @@ export class VersionManagerController {
8690

8791
this.logger.log(
8892
chalk.red(
89-
`Unable to find version matching criteria "${versionTags.join(' ')}"`
90-
)
93+
`Unable to find version matching criteria "${versionTags.join(' ')}"`,
94+
),
9195
);
9296
};
9397

9498
private table = (versions: Version[]) =>
9599
this.ui.table({
96100
printColNum: false,
97101
message: 'The following releases are available:',
98-
name: 'version',
99102
rows: versions.map((version) => {
100103
const stable = version.versionTags.includes('stable');
101104
const selected = this.service.isSelectedVersion(version.version);
102105
const versionTags = version.versionTags.map((t) =>
103-
t === 'latest' ? chalk.green(t) : t
106+
t === 'latest' ? chalk.green(t) : t,
104107
);
105108

106109
return {
Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,58 @@
11
// import ora from 'ora'
2-
import {Injectable} from '@nestjs/common';
3-
import {prompt, Separator} from 'inquirer';
4-
import {getTable} from 'console.table'
2+
import { Injectable } from '@nestjs/common';
3+
import select, { Separator } from '@inquirer/select';
4+
import { getTable } from 'console.table';
5+
import { styleText } from 'util';
56

67
@Injectable()
78
export class UIService {
8-
99
public async table<T>(config: {
10-
name: string,
11-
message: string,
12-
printColNum?: boolean,
13-
rows: Array<{ row: Record<string, unknown>, short: string, value: T }>,
10+
message: string;
11+
printColNum?: boolean;
12+
rows: Array<{ row: Record<string, string>; short: string; value: T }>;
1413
}): Promise<T> {
15-
16-
17-
const table = getTable(config.rows.map(({row}, index: number) => {
18-
return config.printColNum === false ? row : ({'#': index + 1, ...row});
19-
}))
20-
21-
const [header, separator, ...rows] = table.trim().split('\n')
14+
const table: string = getTable(
15+
config.rows.map(({ row }, index: number) => {
16+
return config.printColNum === false ? row : { '#': index + 1, ...row };
17+
}),
18+
);
19+
20+
const [header, separator, ...rows] = table.trim().split('\n');
21+
const dim = (text: string) => styleText('dim', text);
2222
return this.list({
23-
name: config.name,
2423
message: config.message,
2524
choices: [
26-
new Separator(header),
27-
new Separator(separator),
28-
...rows.map((name: string, index: number) => ({
25+
new Separator(dim(header)),
26+
new Separator(dim(separator)),
27+
...rows.map((name, index) => ({
2928
name,
3029
short: config.rows[index].short,
3130
value: config.rows[index].value,
3231
})),
33-
new Separator(separator),
34-
new Separator(' '.repeat(separator.length)),
32+
new Separator(dim(separator)),
33+
new Separator(dim(' '.repeat(separator.length))),
3534
],
36-
})
35+
});
3736
}
3837

3938
public async list<T>(config: {
40-
name: string,
41-
message: string,
42-
choices: Array<{ name: Record<string, unknown>, short?: string, value: T }>,
39+
message: string;
40+
choices: Array<{ name: string; short?: string; value: T } | Separator>;
4341
}): Promise<T> {
44-
45-
const separatorCount = config
46-
.choices
47-
.filter((c) => c instanceof Separator)
48-
.length
49-
50-
const res = await prompt([{
51-
type: 'list',
52-
name: config.name,
53-
pageSize: process.stdout.rows - separatorCount - 1,
54-
message: config.message,
55-
choices: config.choices,
56-
}])
57-
58-
return res[config.name] as T
59-
42+
const pageSize = Math.max(1, process.stdout.rows - 3);
43+
try {
44+
const res = await select({
45+
pageSize,
46+
message: config.message,
47+
choices: config.choices,
48+
});
49+
50+
return res;
51+
} catch (err) {
52+
if (err instanceof Error && err.name === 'ExitPromptError') {
53+
process.exit(0);
54+
}
55+
throw err;
56+
}
6057
}
61-
6258
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
"console.table": "0.10.0",
9393
"fs-extra": "11.3.3",
9494
"glob": "13.x",
95-
"inquirer": "8.2.7",
9695
"jsonpath": "1.2.1",
9796
"proxy-agent": "^6.4.0",
9897
"reflect-metadata": "^0.2.2",
@@ -102,6 +101,7 @@
102101
"devDependencies": {
103102
"@commitlint/cli": "20.4.1",
104103
"@commitlint/config-conventional": "20.4.1",
104+
"@inquirer/select": "5.0.4",
105105
"@nestjs/schematics": "11.0.9",
106106
"@nestjs/testing": "^11.0.16",
107107
"@nx/eslint": "22.5.0",
@@ -114,7 +114,6 @@
114114
"@nx/workspace": "22.5.0",
115115
"@semantic-release/changelog": "6.0.3",
116116
"@types/fs-extra": "11.0.4",
117-
"@types/inquirer": "8.2.12",
118117
"@types/jest": "30.0.0",
119118
"@types/jsonpath": "0.2.4",
120119
"@types/node": "20.19.33",

0 commit comments

Comments
 (0)