@@ -16,7 +16,7 @@ import { spawn } from './utils/spawn';
1616import { version } from '../package.json' ;
1717import { addCodegenBuildScript } from './exampleApp/addCodegenBuildScript' ;
1818import { createInitialGitCommit } from './utils/initialCommit' ;
19- import { assertNpx } from './utils/assert' ;
19+ import { assertNpx , assertOptions } from './utils/assert' ;
2020import { resolveBobVersionWithFallback } from './utils/promiseWithFallback' ;
2121import { generateTemplateConfiguration } from './template/config' ;
2222
@@ -218,7 +218,10 @@ const TYPE_CHOICES: {
218218 } ,
219219] ;
220220
221- type Question = Omit < PromptObject < keyof Answers > , 'validate' | 'name' > & {
221+ export type Question = Omit <
222+ PromptObject < keyof Answers > ,
223+ 'validate' | 'name'
224+ > & {
222225 validate ?: ( value : string ) => boolean | string ;
223226 name : keyof Answers ;
224227} ;
@@ -843,56 +846,3 @@ yargs
843846 'strip-dashed' : true ,
844847 } )
845848 . strict ( ) . argv ;
846-
847- /**
848- * Makes sure the answers are in expected form and ends the process with error if they are not
849- */
850- export function assertOptions ( questions : Question [ ] , answers : Answers ) {
851- for ( const [ key , value ] of Object . entries ( answers ) ) {
852- if ( value == null ) {
853- continue ;
854- }
855-
856- const question = questions . find ( ( q ) => q . name === key ) ;
857-
858- if ( question == null ) {
859- continue ;
860- }
861-
862- let valid = question . validate ? question . validate ( String ( value ) ) : true ;
863-
864- // We also need to guard against invalid choices
865- // If we don't already have a validation message to provide a better error
866- if ( typeof valid !== 'string' && 'choices' in question ) {
867- const choices =
868- typeof question . choices === 'function'
869- ? question . choices (
870- undefined ,
871- // @ts -expect-error: it complains about optional values, but it should be fine
872- answers ,
873- question
874- )
875- : question . choices ;
876-
877- if ( choices && ! choices . some ( ( choice ) => choice . value === value ) ) {
878- valid = `Supported values are - ${ choices . map ( ( c ) =>
879- kleur . green ( c . value )
880- ) } `;
881- }
882- }
883-
884- if ( valid !== true ) {
885- let message = `Invalid value ${ kleur . red (
886- String ( value )
887- ) } passed for ${ kleur . blue ( key ) } `;
888-
889- if ( typeof valid === 'string' ) {
890- message += `: ${ valid } ` ;
891- }
892-
893- console . log ( message ) ;
894-
895- process . exit ( 1 ) ;
896- }
897- }
898- }
0 commit comments