@@ -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__' ,
@@ -42,33 +42,23 @@ const PACKAGES_TO_ADD_WEB = {
42
42
} ;
43
43
44
44
export default async function generateExampleApp ( {
45
- type,
46
- dest,
47
- arch,
48
- project,
49
- bobVersion,
45
+ config,
46
+ destination,
50
47
reactNativeVersion = 'latest' ,
51
48
} : {
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 ;
49
+ config : TemplateConfiguration ;
50
+ destination : string ;
61
51
reactNativeVersion ?: string ;
62
52
} ) {
63
- const directory = path . join ( dest , 'example' ) ;
53
+ const directory = path . join ( destination , 'example' ) ;
64
54
65
55
// `npx --package react-native-test-app@latest init --name ${projectName}Example --destination example --version ${reactNativeVersion}`
66
56
const testAppArgs = [
67
57
'--package' ,
68
58
`react-native-test-app@latest` ,
69
59
'init' ,
70
60
'--name' ,
71
- `${ project . name } Example` ,
61
+ `${ config . project . name } Example` ,
72
62
`--destination` ,
73
63
directory ,
74
64
...( reactNativeVersion !== 'latest'
@@ -84,9 +74,9 @@ export default async function generateExampleApp({
84
74
const vanillaArgs = [
85
75
`@react-native-community/cli` ,
86
76
'init' ,
87
- `${ project . name } Example` ,
77
+ `${ config . project . name } Example` ,
88
78
'--package-name' ,
89
- `${ project . package } .example` ,
79
+ `${ config . project . package } .example` ,
90
80
'--directory' ,
91
81
directory ,
92
82
'--version' ,
@@ -107,7 +97,7 @@ export default async function generateExampleApp({
107
97
108
98
let args : string [ ] = [ ] ;
109
99
110
- switch ( type ) {
100
+ switch ( config . example ) {
111
101
case 'vanilla' :
112
102
args = vanillaArgs ;
113
103
break ;
@@ -131,7 +121,7 @@ export default async function generateExampleApp({
131
121
// Patch the example app's package.json
132
122
const pkg = await fs . readJSON ( path . join ( directory , 'package.json' ) ) ;
133
123
134
- pkg . name = `${ project . slug } -example` ;
124
+ pkg . name = `${ config . project . slug } -example` ;
135
125
136
126
// Remove Jest config for now
137
127
delete pkg . jest ;
@@ -144,12 +134,12 @@ export default async function generateExampleApp({
144
134
const SCRIPTS_TO_ADD = {
145
135
'build:android' :
146
136
'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"` ,
137
+ '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
138
} ;
149
139
150
- if ( type === 'vanilla' ) {
140
+ if ( config . example === 'vanilla' ) {
151
141
Object . assign ( scripts , SCRIPTS_TO_ADD ) ;
152
- } else if ( type === 'test-app' ) {
142
+ } else if ( config . example === 'test-app' ) {
153
143
// `react-native-test-app` doesn't bundle application by default in 'Release' mode and also `bundle` command doesn't create a directory.
154
144
// `mkdist` script should be removed after stable React Native major contains this fix: https://github.com/facebook/react-native/pull/45182.
155
145
@@ -173,9 +163,9 @@ export default async function generateExampleApp({
173
163
const app = await fs . readJSON ( path . join ( directory , 'app.json' ) ) ;
174
164
175
165
app . android = app . android || { } ;
176
- app . android . package = `${ project . package } .example` ;
166
+ app . android . package = `${ config . project . package } .example` ;
177
167
app . ios = app . ios || { } ;
178
- app . ios . bundleIdentifier = `${ project . package } .example` ;
168
+ app . ios . bundleIdentifier = `${ config . project . package } .example` ;
179
169
180
170
await fs . writeJSON ( path . join ( directory , 'app.json' ) , app , {
181
171
spaces : 2 ,
@@ -188,12 +178,19 @@ export default async function generateExampleApp({
188
178
} ) ;
189
179
190
180
const PACKAGES_TO_ADD_DEV = {
191
- 'react-native-builder-bob' : `^${ bobVersion } ` ,
181
+ 'react-native-builder-bob' : `^${ config . versions . bob } ` ,
192
182
} ;
193
183
184
+ if ( config . project . moduleConfig === 'nitro-modules' ) {
185
+ const packagesToAddNitro = {
186
+ 'react-native-nitro-modules' : `^${ config . versions . nitroModules } ` ,
187
+ } ;
188
+ Object . assign ( dependencies , packagesToAddNitro ) ;
189
+ }
190
+
194
191
Object . assign ( devDependencies , PACKAGES_TO_ADD_DEV ) ;
195
192
196
- if ( type === 'expo' ) {
193
+ if ( config . example === 'expo' ) {
197
194
const sdkVersion = dependencies . expo . split ( '.' ) [ 0 ] . replace ( / [ ^ \d ] / , '' ) ;
198
195
199
196
let bundledNativeModules : Record < string , string > ;
@@ -231,15 +228,17 @@ export default async function generateExampleApp({
231
228
const app = await fs . readJSON ( path . join ( directory , 'app.json' ) ) ;
232
229
233
230
app . expo . android = app . expo . android || { } ;
234
- app . expo . android . package = `${ project . package } .example` ;
231
+ app . expo . android . package = `${ config . project . package } .example` ;
235
232
app . expo . ios = app . expo . ios || { } ;
236
- app . expo . ios . bundleIdentifier = `${ project . package } .example` ;
233
+ app . expo . ios . bundleIdentifier = `${ config . project . package } .example` ;
237
234
238
235
await fs . writeJSON ( path . join ( directory , 'app.json' ) , app , {
239
236
spaces : 2 ,
240
237
} ) ;
241
238
}
242
239
240
+ // Sort the deps by name to match behavior of package managers
241
+ // This way the package.json doesn't get updated when installing deps
243
242
for ( const field of [ 'dependencies' , 'devDependencies' ] ) {
244
243
if ( pkg [ field ] ) {
245
244
pkg [ field ] = sortObjectKeys ( pkg [ field ] ) ;
@@ -250,7 +249,7 @@ export default async function generateExampleApp({
250
249
spaces : 2 ,
251
250
} ) ;
252
251
253
- if ( type !== 'expo' ) {
252
+ if ( config . example !== 'expo' ) {
254
253
let gradleProperties = await fs . readFile (
255
254
path . join ( directory , 'android' , 'gradle.properties' ) ,
256
255
'utf8'
@@ -264,7 +263,7 @@ export default async function generateExampleApp({
264
263
) ;
265
264
266
265
// If the library is on new architecture, enable new arch for iOS and Android
267
- if ( arch === 'new' ) {
266
+ if ( config . project . arch === 'new' ) {
268
267
// iOS
269
268
// Add ENV['RCT_NEW_ARCH_ENABLED'] = 1 on top of example/ios/Podfile
270
269
const podfile = await fs . readFile (
0 commit comments