11import type { ToolOpts } from "./types/toolOpts" ;
2- import { askQuestion , packageNameFromPlugin } from "./utils" ;
2+ import { inquirerPrompt , packageNameFromPlugin } from "./utils" ;
33
44export type ConfigNote = { plugin : string ; configNote : string } ;
55
@@ -17,42 +17,33 @@ const askPluginNames = async (opts: ToolOpts): Promise<{ pluginNames: string[];
1717 let pluginNames : string [ ] = [ ] ;
1818 let configNotes : ConfigNote [ ] = [ ] ;
1919
20- const getDefaultFeatures = ( opts : ToolOpts ) : number [ ] => {
21- const inds : number [ ] = [ ] ;
22- opts . pluginGroups . forEach ( ( { plugins } , ind ) => {
23- if ( plugins . some ( plugin => plugin . default ) ) {
24- inds . push ( ind ) ;
25- }
26- } ) ;
27- return inds ;
28- } ;
29-
30- const wantedFeatures = await askQuestion < number [ ] > ( {
20+ const wantedFeatures = await inquirerPrompt < number [ ] > ( {
3121 type : "checkbox" ,
3222 message : "Which features do you need?" ,
33- choices : opts . pluginGroups . map ( ( group , ind ) => ( { name : group . description , value : ind } ) ) ,
34- default : getDefaultFeatures ( opts ) ,
23+ choices : opts . pluginGroups . map ( ( group , ind ) => ( {
24+ name : group . description ,
25+ value : ind ,
26+ checked : group . plugins . some ( plugin => plugin . default ) ,
27+ } ) ) ,
3528 } ) ;
3629
3730 for ( const ind of wantedFeatures ) {
3831 const { description, plugins } = opts . pluginGroups [ ind ] ;
39- const curGroupPlugins = await askQuestion < number [ ] > ( {
32+ const curGroupPlugins = await inquirerPrompt < number [ ] > ( {
4033 type : "checkbox" ,
4134 message : `Plugins: ${ description } ` ,
42- choices : plugins . map ( ( { plugin, description } , index ) => ( {
35+ choices : plugins . map ( ( { plugin, description, default : checked } , index ) => ( {
4336 name : `${ description } (${ packageNameFromPlugin ( plugin ) } )` ,
4437 value : index ,
38+ checked,
4539 } ) ) ,
46- default : plugins . reduce ( ( def : number [ ] , plugin , index ) => {
47- return plugin . default ? def . concat ( index ) : def ;
48- } , [ ] ) ,
4940 } ) ;
5041
5142 const notesIndToAdd = curGroupPlugins . filter ( ind => plugins [ ind ] . configNote ) ;
5243 const pluginNamesToAdd = curGroupPlugins . map ( ind => plugins [ ind ] . plugin ) ;
5344 const notesToAdd : ConfigNote [ ] = notesIndToAdd . map ( ind => ( {
5445 plugin : plugins [ ind ] . plugin ,
55- configNote : plugins [ ind ] . configNote ! ,
46+ configNote : plugins [ ind ] . configNote as string ,
5647 } ) ) ;
5748
5849 pluginNames = pluginNames . concat ( pluginNamesToAdd ) ;
0 commit comments