@@ -70,31 +70,28 @@ type ArgName =
70
70
| 'author-email'
71
71
| 'author-url'
72
72
| 'repo-url'
73
- | 'type' ;
73
+ | 'languages'
74
+ | 'type'
75
+ | 'example' ;
74
76
75
77
type ModuleType = 'module' | 'view' ;
76
78
77
- type LibraryType =
78
- | 'native'
79
- | 'native-swift'
80
- | 'native-kotlin'
81
- | 'native-kotlin-swift'
82
- | 'native-view'
83
- | 'native-view-swift'
84
- | 'native-view-kotlin'
85
- | 'native-view-kotlin-swift'
86
- | 'cpp'
87
- | 'js'
88
- | 'expo' ;
89
-
90
79
type Answers = {
91
80
slug : string ;
92
81
description : string ;
93
82
authorName : string ;
94
83
authorEmail : string ;
95
84
authorUrl : string ;
96
85
repoUrl : string ;
97
- type : LibraryType ;
86
+ languages :
87
+ | 'java-objc'
88
+ | 'java-swift'
89
+ | 'kotlin-objc'
90
+ | 'kotlin-swift'
91
+ | 'cpp'
92
+ | 'js' ;
93
+ type ?: 'module' | 'view' ;
94
+ example ?: 'expo' | 'native' ;
98
95
} ;
99
96
100
97
const args : Record < ArgName , yargs . Options > = {
@@ -122,22 +119,25 @@ const args: Record<ArgName, yargs.Options> = {
122
119
description : 'URL for the repository' ,
123
120
type : 'string' ,
124
121
} ,
125
- 'type ' : {
126
- description : 'Type package do you want to develop ' ,
122
+ 'languages ' : {
123
+ description : 'Languages you want to use ' ,
127
124
choices : [
128
- 'native' ,
129
- 'native-swift' ,
130
- 'native-kotlin' ,
131
- 'native-kotlin-swift' ,
132
- 'native-view' ,
133
- 'native-view-swift' ,
134
- 'native-view-kotlin' ,
135
- 'native-view-kotlin-swift' ,
125
+ 'java-objc' ,
126
+ 'java-swift' ,
127
+ 'kotlin-objc' ,
128
+ 'kotlin-swift' ,
136
129
'cpp' ,
137
130
'js' ,
138
- 'expo' ,
139
131
] ,
140
132
} ,
133
+ 'type' : {
134
+ description : 'Type of library you want to develop' ,
135
+ choices : [ 'module' , 'view' ] ,
136
+ } ,
137
+ 'example' : {
138
+ description : 'Type of example app' ,
139
+ choices : [ 'expo' , 'native' ] ,
140
+ } ,
141
141
} ;
142
142
143
143
async function create ( argv : yargs . Arguments < any > ) {
@@ -245,45 +245,42 @@ async function create(argv: yargs.Arguments<any>) {
245
245
} ,
246
246
validate : ( input ) => / ^ h t t p s ? : \/ \/ / . test ( input ) || 'Must be a valid URL' ,
247
247
} ,
248
- 'type ' : {
248
+ 'languages ' : {
249
249
type : 'select' ,
250
+ name : 'languages' ,
251
+ message : 'Which languages do you want to use?' ,
252
+ choices : [
253
+ { title : 'Java & Objective-C' , value : 'java-objc' } ,
254
+ { title : 'Java & Swift' , value : 'java-swift' } ,
255
+ { title : 'Kotlin & Objective-C' , value : 'kotlin-objc' } ,
256
+ { title : 'Kotlin & Swift' , value : 'kotlin-swift' } ,
257
+ { title : 'C++ for both iOS & Android' , value : 'cpp' } ,
258
+ { title : 'JavaScript only' , value : 'js' } ,
259
+ ] ,
260
+ } ,
261
+ 'type' : {
262
+ type : ( prev : string ) =>
263
+ [ 'java-objc' , 'java-swift' , 'kotlin-objc' , 'kotlin-swift' ] . includes (
264
+ prev
265
+ )
266
+ ? 'select'
267
+ : null ,
250
268
name : 'type' ,
251
- message : 'What type of package do you want to develop?' ,
269
+ message : 'What type of library do you want to develop?' ,
252
270
choices : [
253
- { title : 'Native module in Java and Objective-C' , value : 'native' } ,
254
- { title : 'Native module in Java and Swift' , value : 'native-swift' } ,
255
- {
256
- title : 'Native module in Kotlin and Objective-C' ,
257
- value : 'native-kotlin' ,
258
- } ,
259
- {
260
- title : 'Native module in Kotlin and Swift' ,
261
- value : 'native-kotlin-swift' ,
262
- } ,
263
- { title : 'Native module with C++ code' , value : 'cpp' } ,
264
- {
265
- title : 'Native view in Java and Objective-C' ,
266
- value : 'native-view' ,
267
- } ,
268
- {
269
- title : 'Native view in Java and Swift' ,
270
- value : 'native-view-swift' ,
271
- } ,
272
- {
273
- title : 'Native view in Kotlin and Objective-C' ,
274
- value : 'native-view-kotlin' ,
275
- } ,
276
- {
277
- title : 'Native view in Kotlin and Swift' ,
278
- value : 'native-view-kotlin-swift' ,
279
- } ,
280
- {
281
- title : 'JavaScript library with native example' ,
282
- value : 'js' ,
283
- } ,
271
+ { title : 'Native module (to expose native APIs)' , value : 'module' } ,
272
+ { title : 'Native view (to use as a component)' , value : 'view' } ,
273
+ ] ,
274
+ } ,
275
+ 'example' : {
276
+ type : ( prev : string ) => ( prev === 'js' ? 'select' : null ) ,
277
+ name : 'example' ,
278
+ message : 'What type of example app do you want to generate?' ,
279
+ choices : [
280
+ { title : 'JavaScript only (with Expo and Web support)' , value : 'expo' } ,
284
281
{
285
- title : 'JavaScript library with Expo example and Web support ' ,
286
- value : 'expo ' ,
282
+ title : 'Native (to use other libraries with native code) ' ,
283
+ value : 'native ' ,
287
284
} ,
288
285
] ,
289
286
} ,
@@ -296,7 +293,9 @@ async function create(argv: yargs.Arguments<any>) {
296
293
authorEmail,
297
294
authorUrl,
298
295
repoUrl,
299
- type,
296
+ languages,
297
+ type = 'module' ,
298
+ example = 'native' ,
300
299
} = {
301
300
...argv ,
302
301
...( await prompts (
@@ -312,13 +311,6 @@ async function create(argv: yargs.Arguments<any>) {
312
311
} as Answers ;
313
312
314
313
const project = slug . replace ( / ^ ( r e a c t - n a t i v e - | @ [ ^ / ] + \/ ) / , '' ) ;
315
- const moduleType : ModuleType =
316
- type === 'native-view' ||
317
- type === 'native-view-swift' ||
318
- type === 'native-view-kotlin' ||
319
- type === 'native-view-kotlin-swift'
320
- ? 'view'
321
- : 'module' ;
322
314
323
315
// Get latest version of Bob from NPM
324
316
let version : string ;
@@ -360,29 +352,12 @@ async function create(argv: yargs.Arguments<any>) {
360
352
. slice ( 1 ) } `,
361
353
package : slug . replace ( / [ ^ a - z 0 - 9 ] / g, '' ) . toLowerCase ( ) ,
362
354
podspec : slug . replace ( / [ ^ a - z 0 - 9 ] + / g, '-' ) . replace ( / ^ - / , '' ) ,
363
- native :
364
- type === 'cpp' ||
365
- type === 'native' ||
366
- type === 'native-swift' ||
367
- type === 'native-kotlin' ||
368
- type === 'native-kotlin-swift' ||
369
- type === 'native-view' ||
370
- type === 'native-view-swift' ||
371
- type === 'native-view-kotlin' ||
372
- type === 'native-view-kotlin-swift' ,
373
- cpp : type === 'cpp' ,
374
- kotlin :
375
- type === 'native-kotlin' ||
376
- type === 'native-kotlin-swift' ||
377
- type === 'native-view-kotlin' ||
378
- type === 'native-view-kotlin-swift' ,
379
- swift :
380
- type === 'native-swift' ||
381
- type === 'native-kotlin-swift' ||
382
- type === 'native-view-swift' ||
383
- type === 'native-view-kotlin-swift' ,
384
- module : type !== 'js' ,
385
- moduleType,
355
+ native : languages !== 'js' ,
356
+ cpp : languages === 'cpp' ,
357
+ kotlin : languages === 'kotlin-objc' || languages === 'kotlin-swift' ,
358
+ swift : languages === 'java-swift' || languages === 'kotlin-swift' ,
359
+ module : languages !== 'js' ,
360
+ moduleType : type ,
386
361
} ,
387
362
author : {
388
363
name : authorName ,
@@ -423,15 +398,17 @@ async function create(argv: yargs.Arguments<any>) {
423
398
424
399
await copyDir ( COMMON_FILES , folder ) ;
425
400
426
- if ( type === 'expo ' ) {
401
+ if ( languages === 'js ' ) {
427
402
await copyDir ( JS_FILES , folder ) ;
428
- await copyDir ( EXPO_FILES , folder ) ;
429
- } else if ( type === 'js' ) {
430
- await copyDir ( JS_FILES , folder ) ;
431
- await copyDir (
432
- path . join ( EXAMPLE_FILES , 'example' ) ,
433
- path . join ( folder , 'example' )
434
- ) ;
403
+
404
+ if ( example === 'expo' ) {
405
+ await copyDir ( EXPO_FILES , folder ) ;
406
+ } else {
407
+ await copyDir (
408
+ path . join ( EXAMPLE_FILES , 'example' ) ,
409
+ path . join ( folder , 'example' )
410
+ ) ;
411
+ }
435
412
} else {
436
413
await copyDir (
437
414
path . join ( EXAMPLE_FILES , 'example' ) ,
@@ -445,14 +422,14 @@ async function create(argv: yargs.Arguments<any>) {
445
422
}
446
423
447
424
if ( options . project . swift ) {
448
- await copyDir ( SWIFT_FILES ( moduleType ) , folder ) ;
425
+ await copyDir ( SWIFT_FILES ( type ) , folder ) ;
449
426
} else {
450
- await copyDir ( OBJC_FILES ( moduleType ) , folder ) ;
427
+ await copyDir ( OBJC_FILES ( type ) , folder ) ;
451
428
}
452
429
if ( options . project . kotlin ) {
453
- await copyDir ( KOTLIN_FILES ( moduleType ) , folder ) ;
430
+ await copyDir ( KOTLIN_FILES ( type ) , folder ) ;
454
431
} else {
455
- await copyDir ( JAVA_FILES ( moduleType ) , folder ) ;
432
+ await copyDir ( JAVA_FILES ( type ) , folder ) ;
456
433
}
457
434
}
458
435
@@ -466,10 +443,10 @@ async function create(argv: yargs.Arguments<any>) {
466
443
// Ignore error
467
444
}
468
445
469
- const platforms = {
446
+ const platforms : Record < string , { name : string ; color : string } > = {
470
447
ios : { name : 'iOS' , color : 'cyan' } ,
471
448
android : { name : 'Android' , color : 'green' } ,
472
- ...( type === 'expo' ? { web : { name : 'Web' , color : 'blue' } } : null ) ,
449
+ ...( example === 'expo' ? { web : { name : 'Web' , color : 'blue' } } : null ) ,
473
450
} ;
474
451
475
452
console . log (
0 commit comments