@@ -290,21 +290,33 @@ function createDefaultConfigFile(directory: string) {
290
290
` ;
291
291
292
292
const filepath = 'react-native.config.js' ;
293
- if ( ! doesDirectoryExist ( path . join ( directory , filepath ) ) ) {
294
- fs . createFileSync ( filepath ) ;
295
- fs . writeFileSync ( filepath , content , { encoding : 'utf-8' } ) ;
296
- } else {
297
- const tempFilePath = path . join ( directory , 'tempConfig.js' ) ;
298
- fs . writeFileSync ( tempFilePath , content ) ;
299
- const cliConfigFile = require ( tempFilePath ) ;
300
- const existingConfigFile = require ( path . join ( directory , filepath ) ) ;
293
+ try {
294
+ if ( ! doesDirectoryExist ( path . join ( directory , filepath ) ) ) {
295
+ fs . createFileSync ( filepath ) ;
296
+ fs . writeFileSync ( filepath , content , { encoding : 'utf-8' } ) ;
297
+ } else {
298
+ const tempFilePath = path . join ( directory , 'tempConfig.js' ) ;
299
+ fs . writeFileSync ( tempFilePath , content ) ;
300
+ const cliConfigFile = require ( tempFilePath ) ;
301
+ const existingConfigFile = require ( path . join ( directory , filepath ) ) ;
301
302
302
- const mergedConfig = deepmerge ( existingConfigFile , cliConfigFile ) ;
303
+ const mergedConfig = deepmerge ( existingConfigFile , cliConfigFile ) ;
303
304
304
- fs . unlinkSync ( tempFilePath ) ;
305
+ fs . unlinkSync ( tempFilePath ) ;
305
306
306
- const output = `module.exports = ${ JSON . stringify ( mergedConfig , null , 2 ) } ;` ;
307
- fs . writeFileSync ( filepath , output , { encoding : 'utf-8' } ) ;
307
+ const output = `module.exports = ${ JSON . stringify (
308
+ mergedConfig ,
309
+ null ,
310
+ 2 ,
311
+ ) } ;`;
312
+ fs . writeFileSync ( filepath , output , { encoding : 'utf-8' } ) ;
313
+ }
314
+ } catch {
315
+ logger . warn (
316
+ `Could not create custom ${ chalk . bold (
317
+ 'react-native.config.js' ,
318
+ ) } file. You can create it manually in your project's root folder.`,
319
+ ) ;
308
320
}
309
321
}
310
322
0 commit comments