(
bindings: PluginSetupBinding[],
targetDir: string,
{ plugins, yes }: CliArgs,
)
| 16 | * 3. Interactive: checkbox prompt with recommended plugins pre-checked |
| 17 | */ |
| 18 | export async function promptPluginSelection( |
| 19 | bindings: PluginSetupBinding[], |
| 20 | targetDir: string, |
| 21 | { plugins, yes }: CliArgs, |
| 22 | ): Promise<PluginSetupBinding[]> { |
| 23 | if (bindings.length === 0) { |
| 24 | return []; |
| 25 | } |
| 26 | if (plugins != null && plugins.length > 0) { |
| 27 | return bindings.filter(b => plugins.includes(b.slug)); |
| 28 | } |
| 29 | const recommended = await detectRecommended(bindings, targetDir); |
| 30 | if (yes) { |
| 31 | return bindings.filter(({ slug }) => recommended.has(slug)); |
| 32 | } |
| 33 | const selected = await checkbox({ |
| 34 | message: 'Plugins to include:', |
| 35 | required: true, |
| 36 | choices: bindings.map(({ title, slug }) => ({ |
| 37 | name: title, |
| 38 | value: slug, |
| 39 | checked: recommended.has(slug), |
| 40 | })), |
| 41 | }); |
| 42 | const selectedSet = new Set(selected); |
| 43 | return bindings.filter(({ slug }) => selectedSet.has(slug)); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Calls each binding's `isRecommended` callback (if provided) |
no test coverage detected