@@ -2,6 +2,7 @@ import fs from 'fs-extra';
2
2
import path from 'path' ;
3
3
import https from 'https' ;
4
4
import { spawn } from './spawn' ;
5
+ import { ExampleType } from './../index' ;
5
6
6
7
const FILES_TO_DELETE = [
7
8
'__tests__' ,
@@ -55,41 +56,68 @@ export default async function generateExampleApp({
55
56
arch,
56
57
reactNativeVersion = 'latest' ,
57
58
} : {
58
- type : 'expo' | 'native' ;
59
+ type : ExampleType ;
59
60
dest : string ;
60
61
slug : string ;
61
62
projectName : string ;
62
63
arch : 'new' | 'mixed' | 'legacy' ;
63
64
reactNativeVersion ?: string ;
64
65
} ) {
65
66
const directory = path . join ( dest , 'example' ) ;
66
- const args =
67
- type === 'native'
68
- ? // `npx --package react-native-test-app@latest init --name ${projectName}Example --destination example --version ${reactNativeVersion}`
69
- [
70
- '--package' ,
71
- `react-native-test-app@latest` ,
72
- 'init' ,
73
- '--name' ,
74
- `${ projectName } Example` ,
75
- `--destination` ,
76
- directory ,
77
- ...( reactNativeVersion !== 'latest'
78
- ? [ '--version' , reactNativeVersion ]
79
- : [ ] ) ,
80
- '--platform' ,
81
- 'ios' ,
82
- '--platform' ,
83
- 'android' ,
84
- ]
85
- : // `npx create-expo-app example --no-install --template blank`
86
- [
87
- 'create-expo-app@latest' ,
88
- directory ,
89
- '--no-install' ,
90
- '--template' ,
91
- 'blank' ,
92
- ] ;
67
+
68
+ // `npx --package react-native-test-app@latest init --name ${projectName}Example --destination example --version ${reactNativeVersion}`
69
+ const testAppArgs = [
70
+ '--package' ,
71
+ `react-native-test-app@latest` ,
72
+ 'init' ,
73
+ '--name' ,
74
+ `${ projectName } Example` ,
75
+ `--destination` ,
76
+ directory ,
77
+ ...( reactNativeVersion !== 'latest'
78
+ ? [ '--version' , reactNativeVersion ]
79
+ : [ ] ) ,
80
+ '--platform' ,
81
+ 'ios' ,
82
+ '--platform' ,
83
+ 'android' ,
84
+ ] ;
85
+
86
+ // `npx react-native init <projectName> --directory example --skip-install`
87
+ const vanillaArgs = [
88
+ 'react-native@latest' ,
89
+ 'init' ,
90
+ `${ projectName } Example` ,
91
+ '--directory' ,
92
+ directory ,
93
+ '--version' ,
94
+ reactNativeVersion ,
95
+ '--skip-install' ,
96
+ '--npm' ,
97
+ ] ;
98
+
99
+ // `npx create-expo-app example --no-install --template blank`
100
+ const expoArgs = [
101
+ 'create-expo-app@latest' ,
102
+ directory ,
103
+ '--no-install' ,
104
+ '--template' ,
105
+ 'blank' ,
106
+ ] ;
107
+
108
+ let args : string [ ] = [ ] ;
109
+
110
+ switch ( type ) {
111
+ case ExampleType . Vanilla :
112
+ args = vanillaArgs ;
113
+ break ;
114
+ case ExampleType . TestApp :
115
+ args = testAppArgs ;
116
+ break ;
117
+ case ExampleType . Expo :
118
+ args = expoArgs ;
119
+ break ;
120
+ }
93
121
94
122
await spawn ( 'npx' , args , {
95
123
env : { ...process . env , npm_config_yes : 'true' } ,
@@ -121,7 +149,7 @@ export default async function generateExampleApp({
121
149
'build:ios' : `cd ios && xcodebuild -workspace ${ projectName } Example.xcworkspace -scheme ${ projectName } Example -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO` ,
122
150
} ;
123
151
124
- if ( type === 'native' ) {
152
+ if ( type !== ExampleType . Expo ) {
125
153
Object . assign ( scripts , SCRIPTS_TO_ADD ) ;
126
154
}
127
155
@@ -132,7 +160,7 @@ export default async function generateExampleApp({
132
160
133
161
Object . assign ( devDependencies , PACKAGES_TO_ADD_DEV ) ;
134
162
135
- if ( type === 'expo' ) {
163
+ if ( type === ExampleType . Expo ) {
136
164
const sdkVersion = dependencies . expo . split ( '.' ) [ 0 ] . replace ( / [ ^ \d ] / , '' ) ;
137
165
138
166
let bundledNativeModules : Record < string , string > ;
@@ -176,7 +204,7 @@ export default async function generateExampleApp({
176
204
spaces : 2 ,
177
205
} ) ;
178
206
179
- if ( type === 'native' ) {
207
+ if ( type !== ExampleType . Expo ) {
180
208
let gradleProperties = await fs . readFile (
181
209
path . join ( directory , 'android' , 'gradle.properties' ) ,
182
210
'utf8'
0 commit comments