@@ -107,10 +107,32 @@ type Answers = {
107
107
const LANGUAGE_CHOICES : {
108
108
title : string ;
109
109
value : ProjectLanguages ;
110
- types ? : ProjectType [ ] ;
110
+ types : ProjectType [ ] ;
111
111
} [ ] = [
112
- { title : 'Java & Objective-C' , value : 'java-objc' } ,
113
- { title : 'Kotlin & Objective-C' , value : 'kotlin-objc' } ,
112
+ {
113
+ title : 'Java & Objective-C' ,
114
+ value : 'java-objc' ,
115
+ types : [
116
+ 'module-legacy' ,
117
+ 'module-new' ,
118
+ 'module-mixed' ,
119
+ 'view-mixed' ,
120
+ 'view-new' ,
121
+ 'view-legacy' ,
122
+ ] ,
123
+ } ,
124
+ {
125
+ title : 'Kotlin & Objective-C' ,
126
+ value : 'kotlin-objc' ,
127
+ types : [
128
+ 'module-legacy' ,
129
+ 'module-new' ,
130
+ 'module-mixed' ,
131
+ 'view-mixed' ,
132
+ 'view-new' ,
133
+ 'view-legacy' ,
134
+ ] ,
135
+ } ,
114
136
{
115
137
title : 'Java & Swift' ,
116
138
value : 'java-swift' ,
@@ -366,6 +388,49 @@ async function create(argv: yargs.Arguments<any>) {
366
388
} ,
367
389
} ;
368
390
391
+ // Validate arguments passed to the CLI
392
+ for ( const [ key , value ] of Object . entries ( argv ) ) {
393
+ if ( value == null ) {
394
+ continue ;
395
+ }
396
+
397
+ const question = questions [ key as ArgName ] ;
398
+
399
+ if ( question == null ) {
400
+ continue ;
401
+ }
402
+
403
+ let valid = question . validate ? question . validate ( String ( value ) ) : true ;
404
+
405
+ // We also need to guard against invalid choices
406
+ if ( valid && 'choices' in question ) {
407
+ const choices =
408
+ typeof question . choices === 'function'
409
+ ? question . choices ( undefined , argv , question )
410
+ : question . choices ;
411
+
412
+ if ( choices && ! choices . some ( ( choice ) => choice . value === value ) ) {
413
+ valid = `Supported values are - ${ choices . map ( ( c ) =>
414
+ kleur . green ( c . value )
415
+ ) } `;
416
+ }
417
+ }
418
+
419
+ if ( valid !== true ) {
420
+ let message = `Invalid value ${ kleur . red (
421
+ String ( value )
422
+ ) } passed for ${ kleur . blue ( key ) } `;
423
+
424
+ if ( typeof valid === 'string' ) {
425
+ message += `: ${ valid } ` ;
426
+ }
427
+
428
+ console . log ( message ) ;
429
+
430
+ process . exit ( 1 ) ;
431
+ }
432
+ }
433
+
369
434
const {
370
435
slug,
371
436
description,
@@ -388,7 +453,7 @@ async function create(argv: yargs.Arguments<any>) {
388
453
389
454
// Skip questions with a single choice
390
455
if ( Array . isArray ( v . choices ) && v . choices . length === 1 ) {
391
- return v ;
456
+ return false ;
392
457
}
393
458
394
459
return true ;
@@ -400,8 +465,8 @@ async function create(argv: yargs.Arguments<any>) {
400
465
if ( type === 'select' && typeof choices === 'function' ) {
401
466
return {
402
467
...v ,
403
- type : ( ... args ) => {
404
- const result = choices ( ...args ) ;
468
+ type : ( prev , values , prompt ) => {
469
+ const result = choices ( prev , { ...argv , ... values } , prompt ) ;
405
470
406
471
if ( result && result . length === 1 ) {
407
472
return null ;
@@ -535,6 +600,20 @@ async function create(argv: yargs.Arguments<any>) {
535
600
536
601
await fs . mkdirp ( folder ) ;
537
602
603
+ if ( reactNativeVersion != null ) {
604
+ if ( example === 'expo' ) {
605
+ console . warn (
606
+ `${ kleur . yellow ( '⚠' ) } Ignoring --react-native-version for Expo example`
607
+ ) ;
608
+ } else {
609
+ console . log (
610
+ `${ kleur . blue ( 'ℹ' ) } Using ${ kleur . cyan (
611
+ `react-native@${ reactNativeVersion } `
612
+ ) } for the example`
613
+ ) ;
614
+ }
615
+ }
616
+
538
617
const spinner = ora ( 'Generating example' ) . start ( ) ;
539
618
540
619
await generateExampleApp ( {
0 commit comments