Skip to content

Commit b623d6a

Browse files
natemoo-regithub-actions[bot]
authored andcommitted
[ci] format
1 parent 4bfc89a commit b623d6a

File tree

5 files changed

+75
-45
lines changed

5 files changed

+75
-45
lines changed

examples/changesets/index.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,54 @@ async function main() {
2929
{ value: '@scope/x' },
3030
{ value: '@scope/y' },
3131
{ value: '@scope/z' },
32-
]
33-
}
32+
],
33+
},
3434
}),
3535
major: ({ results }) => {
3636
const packages = results.packages ?? [];
3737
return p.multiselect({
3838
message: `Which packages should have a ${color.red('major')} bump?`,
39-
options: packages.map(value => ({ value })),
39+
options: packages.map((value) => ({ value })),
4040
required: false,
41-
})
41+
});
4242
},
4343
minor: ({ results }) => {
4444
const packages = results.packages ?? [];
4545
const major = Array.isArray(results.major) ? results.major : [];
46-
const possiblePackages = packages.filter(pkg => !major.includes(pkg))
46+
const possiblePackages = packages.filter((pkg) => !major.includes(pkg));
4747
if (possiblePackages.length === 0) return;
4848
return p.multiselect({
4949
message: `Which packages should have a ${color.yellow('minor')} bump?`,
50-
options: possiblePackages.map(value => ({ value })),
51-
required: false
52-
})
50+
options: possiblePackages.map((value) => ({ value })),
51+
required: false,
52+
});
5353
},
5454
patch: async ({ results }) => {
5555
const packages = results.packages ?? [];
5656
const major = Array.isArray(results.major) ? results.major : [];
5757
const minor = Array.isArray(results.minor) ? results.minor : [];
58-
const possiblePackages = packages.filter(pkg => !major.includes(pkg) && !minor.includes(pkg));
58+
const possiblePackages = packages.filter(
59+
(pkg) => !major.includes(pkg) && !minor.includes(pkg)
60+
);
5961
if (possiblePackages.length === 0) return;
6062
let note = possiblePackages.join('\n');
61-
63+
6264
p.log.step(`These packages will have a ${color.green('patch')} bump.\n${color.dim(note)}`);
63-
return possiblePackages
64-
}
65+
return possiblePackages;
66+
},
6567
},
6668
{
67-
onCancel
69+
onCancel,
6870
}
6971
);
7072

7173
const message = await p.text({
7274
placeholder: 'Summary',
73-
message: 'Please enter a summary for this change'
74-
})
75+
message: 'Please enter a summary for this change',
76+
});
7577

7678
if (p.isCancel(message)) {
77-
return onCancel()
79+
return onCancel();
7880
}
7981

8082
p.outro(`Changeset added! ${color.underline(color.cyan('.changeset/orange-crabs-sing.md'))}`);

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export { default as ConfirmPrompt } from './prompts/confirm';
2-
export { default as MultiSelectPrompt } from './prompts/multi-select';
32
export { default as GroupMultiSelectPrompt } from './prompts/group-multiselect';
3+
export { default as MultiSelectPrompt } from './prompts/multi-select';
44
export { default as PasswordPrompt } from './prompts/password';
55
export { default as Prompt, isCancel } from './prompts/prompt';
66
export type { State } from './prompts/prompt';

packages/core/src/prompts/group-multiselect.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Prompt, { PromptOptions } from './prompt';
22

3-
interface GroupMultiSelectOptions<T extends { value: any }> extends PromptOptions<GroupMultiSelectPrompt<T>> {
3+
interface GroupMultiSelectOptions<T extends { value: any }>
4+
extends PromptOptions<GroupMultiSelectPrompt<T>> {
45
options: Record<string, T[]>;
56
initialValues?: T['value'][];
67
required?: boolean;
@@ -11,12 +12,12 @@ export default class GroupMultiSelectPrompt<T extends { value: any }> extends Pr
1112
cursor: number = 0;
1213

1314
getGroupItems(group: string): T[] {
14-
return this.options.filter(o => o.group === group);
15+
return this.options.filter((o) => o.group === group);
1516
}
1617

1718
isGroupSelected(group: string) {
1819
const items = this.getGroupItems(group);
19-
return items.every(i => this.value.includes(i.value));
20+
return items.every((i) => this.value.includes(i.value));
2021
}
2122

2223
private toggleValue() {
@@ -25,9 +26,11 @@ export default class GroupMultiSelectPrompt<T extends { value: any }> extends Pr
2526
const group = item.value;
2627
const groupedItems = this.getGroupItems(group);
2728
if (this.isGroupSelected(group)) {
28-
this.value = this.value.filter((v: string) => groupedItems.findIndex(i => i.value === v) === -1);
29+
this.value = this.value.filter(
30+
(v: string) => groupedItems.findIndex((i) => i.value === v) === -1
31+
);
2932
} else {
30-
this.value = [...this.value, ...groupedItems.map(i => i.value)];
33+
this.value = [...this.value, ...groupedItems.map((i) => i.value)];
3134
}
3235
this.value = Array.from(new Set(this.value));
3336
} else {
@@ -42,9 +45,9 @@ export default class GroupMultiSelectPrompt<T extends { value: any }> extends Pr
4245
super(opts, false);
4346
const { options } = opts;
4447
this.options = Object.entries(options).flatMap(([key, option]) => [
45-
{ value: key, group: true, label: key },
46-
...option.map((opt) => ({ ...opt, group: key })),
47-
])
48+
{ value: key, group: true, label: key },
49+
...option.map((opt) => ({ ...opt, group: key })),
50+
]);
4851
this.value = [...(opts.initialValues ?? [])];
4952
this.cursor = Math.max(
5053
this.options.findIndex(({ value }) => value === opts.cursorAt),

packages/core/src/prompts/multi-select.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class MultiSelectPrompt<T extends { value: any }> extends Prompt
1616

1717
private toggleAll() {
1818
const allSelected = this.value.length === this.options.length;
19-
this.value = allSelected ? [] : this.options.map(v => v.value);
19+
this.value = allSelected ? [] : this.options.map((v) => v.value);
2020
}
2121

2222
private toggleValue() {
@@ -37,9 +37,9 @@ export default class MultiSelectPrompt<T extends { value: any }> extends Prompt
3737
);
3838
this.on('key', (char) => {
3939
if (char === 'a') {
40-
this.toggleAll()
40+
this.toggleAll();
4141
}
42-
})
42+
});
4343

4444
this.on('cursor', (key) => {
4545
switch (key) {

packages/prompts/src/index.ts

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
block,
33
ConfirmPrompt,
4+
GroupMultiSelectPrompt,
45
isCancel,
56
MultiSelectPrompt,
6-
GroupMultiSelectPrompt,
77
PasswordPrompt,
88
SelectKeyPrompt,
99
SelectPrompt,
@@ -325,10 +325,12 @@ export const multiselect = <Options extends Option<Value>[], Value extends Primi
325325

326326
switch (this.state) {
327327
case 'submit': {
328-
return `${title}${color.gray(S_BAR)} ${this.options
329-
.filter(({ value }) => this.value.includes(value))
330-
.map((option) => opt(option, 'submitted'))
331-
.join(color.dim(', ')) || color.dim('none')}`;
328+
return `${title}${color.gray(S_BAR)} ${
329+
this.options
330+
.filter(({ value }) => this.value.includes(value))
331+
.map((option) => opt(option, 'submitted'))
332+
.join(color.dim(', ')) || color.dim('none')
333+
}`;
332334
}
333335
case 'cancel': {
334336
const label = this.options
@@ -400,8 +402,16 @@ export const groupMultiselect = <Options extends Option<Value>[], Value extends
400402
) => {
401403
const opt = (
402404
option: Options[number],
403-
state: 'inactive' | 'active' | 'selected' | 'active-selected' | 'group-active' | 'group-active-selected' | 'submitted' | 'cancelled',
404-
options: Options = [] as any,
405+
state:
406+
| 'inactive'
407+
| 'active'
408+
| 'selected'
409+
| 'active-selected'
410+
| 'group-active'
411+
| 'group-active-selected'
412+
| 'submitted'
413+
| 'cancelled',
414+
options: Options = [] as any
405415
) => {
406416
const label = option.label ?? String(option.value);
407417
const isItem = typeof option.group === 'string';
@@ -474,9 +484,14 @@ export const groupMultiselect = <Options extends Option<Value>[], Value extends
474484
.join('\n');
475485
return `${title}${color.yellow(S_BAR)} ${this.options
476486
.map((option, i, options) => {
477-
const selected = this.value.includes(option.value) || (option.group === true && this.isGroupSelected(option.value));
487+
const selected =
488+
this.value.includes(option.value) ||
489+
(option.group === true && this.isGroupSelected(option.value));
478490
const active = i === this.cursor;
479-
const groupActive = !active && typeof option.group === 'string' && this.options[this.cursor].value === option.group;
491+
const groupActive =
492+
!active &&
493+
typeof option.group === 'string' &&
494+
this.options[this.cursor].value === option.group;
480495
if (groupActive) {
481496
return opt(option, selected ? 'group-active-selected' : 'group-active', options);
482497
}
@@ -493,9 +508,14 @@ export const groupMultiselect = <Options extends Option<Value>[], Value extends
493508
default: {
494509
return `${title}${color.cyan(S_BAR)} ${this.options
495510
.map((option, i, options) => {
496-
const selected = this.value.includes(option.value) || (option.group === true && this.isGroupSelected(option.value));
511+
const selected =
512+
this.value.includes(option.value) ||
513+
(option.group === true && this.isGroupSelected(option.value));
497514
const active = i === this.cursor;
498-
const groupActive = !active && typeof option.group === 'string' && this.options[this.cursor].value === option.group;
515+
const groupActive =
516+
!active &&
517+
typeof option.group === 'string' &&
518+
this.options[this.cursor].value === option.group;
499519
if (groupActive) {
500520
return opt(option, selected ? 'group-active-selected' : 'group-active', options);
501521
}
@@ -517,11 +537,14 @@ export const groupMultiselect = <Options extends Option<Value>[], Value extends
517537
const strip = (str: string) => str.replace(ansiRegex(), '');
518538
export const note = (message = '', title = '') => {
519539
const lines = `\n${message}\n`.split('\n');
520-
const len = Math.max(
521-
lines.reduce((sum, ln) => {
522-
ln = strip(ln);
523-
return ln.length > sum ? ln.length : sum;
524-
}, 0), strip(title).length) + 2;
540+
const len =
541+
Math.max(
542+
lines.reduce((sum, ln) => {
543+
ln = strip(ln);
544+
return ln.length > sum ? ln.length : sum;
545+
}, 0),
546+
strip(title).length
547+
) + 2;
525548
const msg = lines
526549
.map(
527550
(ln) =>
@@ -641,7 +664,9 @@ export interface PromptGroupOptions<T> {
641664
}
642665

643666
export type PromptGroup<T> = {
644-
[P in keyof T]: (opts: { results: Partial<PromptGroupAwaitedReturn<T>> }) => void | Promise<T[P] | void>;
667+
[P in keyof T]: (opts: {
668+
results: Partial<PromptGroupAwaitedReturn<T>>;
669+
}) => void | Promise<T[P] | void>;
645670
};
646671

647672
/**

0 commit comments

Comments
 (0)