@@ -3,7 +3,7 @@ import path from 'path';
3
3
import https from 'https' ;
4
4
import { spawn } from '../utils/spawn' ;
5
5
import sortObjectKeys from '../utils/sortObjectKeys' ;
6
- import type { ExampleApp } from '../input ' ;
6
+ import type { TemplateConfiguration } from '../template ' ;
7
7
8
8
const FILES_TO_DELETE = [
9
9
'__tests__' ,
@@ -35,40 +35,34 @@ const PACKAGES_TO_REMOVE = [
35
35
'typescript' ,
36
36
] ;
37
37
38
- const PACKAGES_TO_ADD_WEB = {
38
+ const PACKAGES_TO_ADD_EXPO_WEB = {
39
39
'@expo/metro-runtime' : '~3.2.1' ,
40
40
'react-dom' : '18.2.0' ,
41
41
'react-native-web' : '~0.18.10' ,
42
42
} ;
43
43
44
+ const PACKAGES_TO_ADD_DEV_EXPO_NATIVE = {
45
+ 'expo-dev-client' : '~5.0.3' ,
46
+ } ;
47
+
44
48
export default async function generateExampleApp ( {
45
- type,
46
- dest,
47
- arch,
48
- project,
49
- bobVersion,
49
+ config,
50
+ destination,
50
51
reactNativeVersion = 'latest' ,
51
52
} : {
52
- type : ExampleApp ;
53
- dest : string ;
54
- arch : 'new' | 'legacy' ;
55
- project : {
56
- slug : string ;
57
- name : string ;
58
- package : string ;
59
- } ;
60
- bobVersion : string ;
61
- reactNativeVersion ?: string ;
53
+ config : TemplateConfiguration ;
54
+ destination : string ;
55
+ reactNativeVersion : string | undefined ;
62
56
} ) {
63
- const directory = path . join ( dest , 'example' ) ;
57
+ const directory = path . join ( destination , 'example' ) ;
64
58
65
59
// `npx --package react-native-test-app@latest init --name ${projectName}Example --destination example --version ${reactNativeVersion}`
66
60
const testAppArgs = [
67
61
'--package' ,
68
62
`react-native-test-app@latest` ,
69
63
'init' ,
70
64
'--name' ,
71
- `${ project . name } Example` ,
65
+ `${ config . project . name } Example` ,
72
66
`--destination` ,
73
67
directory ,
74
68
...( reactNativeVersion !== 'latest'
@@ -84,9 +78,9 @@ export default async function generateExampleApp({
84
78
const vanillaArgs = [
85
79
`@react-native-community/cli` ,
86
80
'init' ,
87
- `${ project . name } Example` ,
81
+ `${ config . project . name } Example` ,
88
82
'--package-name' ,
89
- `${ project . package } .example` ,
83
+ `${ config . project . package } .example` ,
90
84
'--directory' ,
91
85
directory ,
92
86
'--version' ,
@@ -107,7 +101,7 @@ export default async function generateExampleApp({
107
101
108
102
let args : string [ ] = [ ] ;
109
103
110
- switch ( type ) {
104
+ switch ( config . example ) {
111
105
case 'vanilla' :
112
106
args = vanillaArgs ;
113
107
break ;
@@ -131,7 +125,7 @@ export default async function generateExampleApp({
131
125
// Patch the example app's package.json
132
126
const pkg = await fs . readJSON ( path . join ( directory , 'package.json' ) ) ;
133
127
134
- pkg . name = `${ project . slug } -example` ;
128
+ pkg . name = `${ config . project . slug } -example` ;
135
129
136
130
// Remove Jest config for now
137
131
delete pkg . jest ;
@@ -144,12 +138,12 @@ export default async function generateExampleApp({
144
138
const SCRIPTS_TO_ADD = {
145
139
'build:android' :
146
140
'react-native build-android --extra-params "--no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a"' ,
147
- 'build:ios' : `react-native build-ios --scheme ${ project . name } Example --mode Debug --extra-params "-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"` ,
141
+ 'build:ios' : `react-native build-ios --scheme ${ config . project . name } Example --mode Debug --extra-params "-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"` ,
148
142
} ;
149
143
150
- if ( type === 'vanilla' ) {
144
+ if ( config . example === 'vanilla' ) {
151
145
Object . assign ( scripts , SCRIPTS_TO_ADD ) ;
152
- } else if ( type === 'test-app' ) {
146
+ } else if ( config . example === 'test-app' ) {
153
147
// `react-native-test-app` doesn't bundle application by default in 'Release' mode and also `bundle` command doesn't create a directory.
154
148
// `mkdist` script should be removed after stable React Native major contains this fix: https://github.com/facebook/react-native/pull/45182.
155
149
@@ -173,9 +167,9 @@ export default async function generateExampleApp({
173
167
const app = await fs . readJSON ( path . join ( directory , 'app.json' ) ) ;
174
168
175
169
app . android = app . android || { } ;
176
- app . android . package = `${ project . package } .example` ;
170
+ app . android . package = `${ config . project . package } .example` ;
177
171
app . ios = app . ios || { } ;
178
- app . ios . bundleIdentifier = `${ project . package } .example` ;
172
+ app . ios . bundleIdentifier = `${ config . project . package } .example` ;
179
173
180
174
await fs . writeJSON ( path . join ( directory , 'app.json' ) , app , {
181
175
spaces : 2 ,
@@ -188,12 +182,12 @@ export default async function generateExampleApp({
188
182
} ) ;
189
183
190
184
const PACKAGES_TO_ADD_DEV = {
191
- 'react-native-builder-bob' : `^${ bobVersion } ` ,
185
+ 'react-native-builder-bob' : `^${ config . bob . version } ` ,
192
186
} ;
193
187
194
188
Object . assign ( devDependencies , PACKAGES_TO_ADD_DEV ) ;
195
189
196
- if ( type === 'expo' ) {
190
+ if ( config . example === 'expo' ) {
197
191
const sdkVersion = dependencies . expo . split ( '.' ) [ 0 ] . replace ( / [ ^ \d ] / , '' ) ;
198
192
199
193
let bundledNativeModules : Record < string , string > ;
@@ -222,18 +216,34 @@ export default async function generateExampleApp({
222
216
bundledNativeModules = { } ;
223
217
}
224
218
225
- Object . entries ( PACKAGES_TO_ADD_WEB ) . forEach ( ( [ name , version ] ) => {
226
- dependencies [ name ] = bundledNativeModules [ name ] || version ;
227
- } ) ;
219
+ if ( config . project . native ) {
220
+ Object . entries ( PACKAGES_TO_ADD_DEV_EXPO_NATIVE ) . forEach (
221
+ ( [ name , version ] ) => {
222
+ devDependencies [ name ] = bundledNativeModules [ name ] || version ;
223
+ }
224
+ ) ;
228
225
229
- scripts . web = 'expo start --web' ;
226
+ scripts . start = 'expo start --dev-client' ;
227
+ scripts . android = 'expo run:android' ;
228
+ scripts . ios = 'expo run:ios' ;
229
+
230
+ delete scripts . web ;
231
+ } else {
232
+ Object . entries ( PACKAGES_TO_ADD_EXPO_WEB ) . forEach ( ( [ name , version ] ) => {
233
+ dependencies [ name ] = bundledNativeModules [ name ] || version ;
234
+ } ) ;
235
+
236
+ scripts . web = 'expo start --web' ;
237
+ }
230
238
231
239
const app = await fs . readJSON ( path . join ( directory , 'app.json' ) ) ;
232
240
241
+ app . expo . name = `${ config . project . name } Example` ;
242
+ app . expo . slug = `${ config . project . slug } -example` ;
233
243
app . expo . android = app . expo . android || { } ;
234
- app . expo . android . package = `${ project . package } .example` ;
244
+ app . expo . android . package = `${ config . project . package } .example` ;
235
245
app . expo . ios = app . expo . ios || { } ;
236
- app . expo . ios . bundleIdentifier = `${ project . package } .example` ;
246
+ app . expo . ios . bundleIdentifier = `${ config . project . package } .example` ;
237
247
238
248
await fs . writeJSON ( path . join ( directory , 'app.json' ) , app , {
239
249
spaces : 2 ,
@@ -250,7 +260,7 @@ export default async function generateExampleApp({
250
260
spaces : 2 ,
251
261
} ) ;
252
262
253
- if ( type !== 'expo' ) {
263
+ if ( config . example !== 'expo' ) {
254
264
let gradleProperties = await fs . readFile (
255
265
path . join ( directory , 'android' , 'gradle.properties' ) ,
256
266
'utf8'
@@ -264,7 +274,7 @@ export default async function generateExampleApp({
264
274
) ;
265
275
266
276
// If the library is on new architecture, enable new arch for iOS and Android
267
- if ( arch === 'new' ) {
277
+ if ( config . project . arch === 'new' ) {
268
278
// iOS
269
279
// Add ENV['RCT_NEW_ARCH_ENABLED'] = 1 on top of example/ios/Podfile
270
280
const podfile = await fs . readFile (
0 commit comments