Skip to content

Commit da7c8c7

Browse files
improved update prompts
1 parent 23d6a5e commit da7c8c7

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

src/ui/display/updatePrompt.ts

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
import chalk from 'chalk';
22
import { type PatchPulseConfig } from '../../services/config';
33
import { type DependencyInfo } from '../../types';
4-
import { pluralize } from '../../utils/pluralize';
54
import { displayHelp } from './help';
65
import { displayVersion } from './version';
76

7+
type UpdateType = 'patch' | 'minor' | 'all';
8+
9+
type OtherOption = 'help' | 'version' | 'quit';
10+
11+
const UPDATE_OPTION_CHARS: Record<UpdateType, string> = {
12+
patch: 'p',
13+
minor: 'm',
14+
all: 'u',
15+
};
16+
17+
const OTHER_OPTION_CHARS: Record<OtherOption, string> = {
18+
help: 'h',
19+
version: 'v',
20+
quit: 'q',
21+
};
22+
823
interface UpdateOption {
924
packageName: string;
1025
latestVersion: string;
@@ -64,7 +79,7 @@ function restoreTerminalSettings({
6479
export function displayUpdatePrompt(
6580
dependencies: DependencyInfo[],
6681
config?: PatchPulseConfig
67-
): Promise<'patch' | 'minor' | 'all' | null> {
82+
): Promise<UpdateType | null> {
6883
return new Promise(resolve => {
6984
const outdatedDeps = dependencies.filter(d => d.isOutdated && !d.isSkipped);
7085

@@ -108,20 +123,12 @@ export function displayUpdatePrompt(
108123
// Show individual options
109124
if (updateOptions.patch.length > 0) {
110125
console.log(
111-
` ${chalk.cyan('p')} - Update ${pluralize({
112-
count: updateOptions.patch.length,
113-
singular: 'outdated patch dependency',
114-
plural: 'outdated patch dependencies',
115-
})}`
126+
` ${chalk.cyan(UPDATE_OPTION_CHARS.patch)} - Update outdated patch dependencies`
116127
);
117128
}
118129
if (updateOptions.minor.length > 0) {
119130
console.log(
120-
` ${chalk.cyan('m')} - Update ${pluralize({
121-
count: updateOptions.minor.length,
122-
singular: 'outdated minor dependency',
123-
plural: 'outdated minor dependencies',
124-
})}`
131+
` ${chalk.cyan(UPDATE_OPTION_CHARS.minor)} - Update outdated minor & patch dependencies`
125132
);
126133
}
127134

@@ -130,25 +137,16 @@ export function displayUpdatePrompt(
130137
updateOptions.all.length > 0 &&
131138
(updateTypesCount > 1 || (!hasPatch && !hasMinor && hasMajor))
132139
) {
133-
const allText =
134-
updateOptions.all.length === 1
135-
? `Update ${updateOptions.all.length} ${pluralize({
136-
count: updateOptions.all.length,
137-
singular: 'outdated dependency',
138-
plural: 'outdated dependencies',
139-
})}`
140-
: `Update all ${updateOptions.all.length} ${pluralize({
141-
count: updateOptions.all.length,
142-
singular: 'outdated dependency',
143-
plural: 'outdated dependencies',
144-
})}`;
145-
146-
console.log(` ${chalk.cyan('a')} - ${allText}`);
140+
console.log(
141+
` ${chalk.cyan(UPDATE_OPTION_CHARS.all)} - update all outdated dependencies`
142+
);
147143
}
148144

149145
console.log();
150146
console.log(
151-
` ${chalk.gray('h')} - Show help | ${chalk.gray('v')} - Show version | ${chalk.gray('q')} - Quit`
147+
` ${chalk.gray(OTHER_OPTION_CHARS.help)} - Show help | ${chalk.gray(
148+
OTHER_OPTION_CHARS.version
149+
)} - Show version | ${chalk.gray(OTHER_OPTION_CHARS.quit)} - Quit`
152150
);
153151
console.log();
154152
console.log(chalk.white('Press a key to select an option...'));
@@ -170,35 +168,35 @@ export function displayUpdatePrompt(
170168
const choice = key.toLowerCase();
171169

172170
switch (choice) {
173-
case 'p':
171+
case UPDATE_OPTION_CHARS.patch:
174172
if (updateOptions.patch.length > 0) {
175173
cleanup();
176174
resolve('patch');
177175
} else {
178176
console.log(chalk.red('\nNo patch updates available'));
179177
}
180178
break;
181-
case 'm':
179+
case UPDATE_OPTION_CHARS.minor:
182180
if (updateOptions.minor.length > 0) {
183181
cleanup();
184182
resolve('minor');
185183
} else {
186184
console.log(chalk.red('\nNo minor updates available'));
187185
}
188186
break;
189-
case 'a':
187+
case UPDATE_OPTION_CHARS.all:
190188
if (updateOptions.all.length > 0) {
191189
cleanup();
192190
resolve('all');
193191
} else {
194192
console.log(chalk.red('\nNo updates available'));
195193
}
196194
break;
197-
case 'q':
195+
case OTHER_OPTION_CHARS.quit:
198196
cleanup();
199197
resolve(null);
200198
break;
201-
case 'h':
199+
case OTHER_OPTION_CHARS.help:
202200
cleanup();
203201
displayHelp();
204202
console.log();
@@ -208,7 +206,7 @@ export function displayUpdatePrompt(
208206
setupRawMode(stdin);
209207
stdin.on('data', handleKeyPress);
210208
break;
211-
case 'v':
209+
case OTHER_OPTION_CHARS.version:
212210
cleanup();
213211
displayVersion();
214212
console.log();

0 commit comments

Comments
 (0)