-
Notifications
You must be signed in to change notification settings - Fork 279
/
Copy pathprompts.ts
66 lines (54 loc) · 1.79 KB
/
prompts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { QuestionCollection } from 'inquirer';
import CheckboxPrompt from 'inquirer/lib/prompts/checkbox';
import { clientAppPrompts, ClientAppAnswer, incompatibleAddonsMsg } from '../../common';
export enum Prerender {
SSG = 'SSG',
SSR = 'SSR',
}
export type NextjsAnswer = ClientAppAnswer & {
prerender: Prerender;
};
const DEFAULT_PRERENDER = Prerender.SSG;
export const prompts: QuestionCollection<NextjsAnswer> = [
...clientAppPrompts,
{
type: 'list',
name: 'prerender',
message: 'How would you like to prerender your application?',
choices: Object.values(Prerender),
default: DEFAULT_PRERENDER,
when: (answers: NextjsAnswer): boolean => {
if (answers.yes && !answers.prerender) {
answers.prerender = DEFAULT_PRERENDER;
}
return !answers.prerender;
},
},
];
/**
* Custom `inquirer` control to support error messages
*/
export class NextjsCheckbox extends CheckboxPrompt {
onSpaceKey() {
super.onSpaceKey();
const isSelected = (initializer: string) =>
this.opt.choices.choices.find((ch) => {
const { value, checked } = ch as { [key: string]: unknown };
return value === initializer && checked;
});
const isPersonalizeSelected = isSelected('nextjs-personalize');
const isTrackingSelected = isSelected('nextjs-styleguide-tracking');
if (isPersonalizeSelected && isTrackingSelected) {
this.onError({
isValid: incompatibleAddonsMsg('nextjs-styleguide-tracking', 'nextjs-personalize'),
});
}
const isSxaSelected = isSelected('nextjs-sxa');
const isStyleguideSelected = isSelected('nextjs-styleguide');
if (isSxaSelected && isStyleguideSelected) {
this.onError({
isValid: incompatibleAddonsMsg('nextjs-sxa', 'nextjs-styleguide'),
});
}
}
}