@@ -9,14 +9,13 @@ import {promisify} from 'util';
9
9
import { HealthCheckInterface } from '../../types' ;
10
10
11
11
const xcodeEnvFile = '.xcode.env' ;
12
- const pathSeparator = '/' ;
13
12
14
13
function removeLastPathComponent ( pathString : string ) : string {
15
14
return path . dirname ( pathString ) ;
16
15
}
17
16
18
17
function pathHasXcodeEnvFile ( pathString : string ) : boolean {
19
- const xcodeEnvPath = pathString + pathSeparator + xcodeEnvFile ;
18
+ const xcodeEnvPath = path . join ( pathString , xcodeEnvFile ) ;
20
19
return fs . existsSync ( xcodeEnvPath ) ;
21
20
}
22
21
@@ -29,11 +28,16 @@ export default {
29
28
description : 'File to customize Xcode environment' ,
30
29
getDiagnostics : async ( _ , config ) => {
31
30
try {
32
- const projectRoot = config ?. root ?? findProjectRoot ( ) ;
33
- const missingXcodeEnvFile = findPodfilePaths ( projectRoot ) . some ( ( p ) => {
34
- const basePath = path . dirname ( p ) ;
35
- return ! pathHasXcodeEnvFile ( basePath ) ;
36
- } ) ;
31
+ const iosFolderPath = config ?. project . ios ?. sourceDir ?? '' ;
32
+
33
+ const missingXcodeEnvFile = findPodfilePaths ( iosFolderPath ) . some (
34
+ ( podfilePath ) => {
35
+ return ! pathHasXcodeEnvFile (
36
+ removeLastPathComponent ( path . join ( iosFolderPath , podfilePath ) ) ,
37
+ ) ;
38
+ } ,
39
+ ) ;
40
+
37
41
return {
38
42
needsToBeFixed : missingXcodeEnvFile ,
39
43
} ;
@@ -52,15 +56,19 @@ export default {
52
56
projectRoot ,
53
57
'react-native/template/ios' ,
54
58
) ;
55
- const src = templateIosPath + pathSeparator + templateXcodeEnv ;
59
+ const src = path . join ( templateIosPath , templateXcodeEnv ) ;
56
60
const copyFileAsync = promisify ( fs . copyFile ) ;
57
61
58
- findPodfilePaths ( projectRoot )
59
- . map ( removeLastPathComponent )
62
+ const iosFolderPath = config ?. project . ios ?. sourceDir ?? '' ;
63
+
64
+ findPodfilePaths ( iosFolderPath )
65
+ . map ( ( podfilePath ) =>
66
+ removeLastPathComponent ( path . join ( iosFolderPath , podfilePath ) ) ,
67
+ )
60
68
// avoid overriding existing .xcode.env
61
69
. filter ( pathDoesNotHaveXcodeEnvFile )
62
70
. forEach ( async ( pathString : string ) => {
63
- const destFilePath = pathString + pathSeparator + xcodeEnvFile ;
71
+ const destFilePath = path . join ( pathString , xcodeEnvFile ) ;
64
72
await copyFileAsync ( src , destFilePath ) ;
65
73
} ) ;
66
74
loader . succeed ( '.xcode.env file have been created!' ) ;
0 commit comments