1
1
import fs from 'node:fs' ;
2
2
import path from 'node:path' ;
3
+ import dedent from 'dedent' ;
3
4
import xcode from 'xcode' ;
4
5
5
6
import logger from '../utils/logger.js' ;
@@ -41,24 +42,29 @@ function getBundleReactNativePhase(
41
42
return bundleReactNative ;
42
43
}
43
44
44
- function modifyBundleReactNativeShellScript (
45
+ function replaceBundleReactNativeShellScript (
45
46
phase : ShellScriptBuildPhase
46
47
) : ShellScriptBuildPhase {
47
- const shellScriptContent = phase . shellScript ;
48
- const shellScriptContentLines = shellScriptContent . split ( '\\n' ) ;
48
+ const script = dedent `
49
+ set -e
49
50
50
- const bundleCommand = 'export BUNDLE_COMMAND=webpack-bundle' ;
51
+ if [[ -f "$PODS_ROOT/../.xcode.env" ]]; then
52
+ source "$PODS_ROOT/../.xcode.env"
53
+ fi
54
+ if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
55
+ source "$PODS_ROOT/../.xcode.env.local"
56
+ fi
51
57
52
- if ( shellScriptContentLines . includes ( bundleCommand ) ) {
53
- logger . info (
54
- `${ phase . name } phase in project.pbxproj already contains ${ bundleCommand } `
55
- ) ;
56
- return phase ;
57
- }
58
+ export CLI_PATH="$("$NODE_BINARY" --print "require('path').dirname(require.resolve('@react-native-community/cli/package.json')) + '/build/bin.js'")"
59
+
60
+ WITH_ENVIRONMENT="$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh"
61
+ REACT_NATIVE_XCODE="$REACT_NATIVE_PATH/scripts/react-native-xcode.sh"
58
62
59
- shellScriptContentLines . splice ( 1 , 0 , '' , bundleCommand ) ;
63
+ /bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"
64
+ ` ;
65
+
66
+ phase . shellScript = `"${ script . replace ( / " / g, '\\"' ) . split ( '\n' ) . join ( '\\n' ) } \\n"` ;
60
67
61
- phase . shellScript = shellScriptContentLines . join ( '\\n' ) ;
62
68
return phase ;
63
69
}
64
70
@@ -67,7 +73,7 @@ function modifyPbxprojConfig(pbxprojPath: string) {
67
73
project . parseSync ( ) ;
68
74
69
75
const bundleReactNativePhase = getBundleReactNativePhase ( project ) ;
70
- modifyBundleReactNativeShellScript ( bundleReactNativePhase ) ;
76
+ replaceBundleReactNativeShellScript ( bundleReactNativePhase ) ;
71
77
72
78
return project . writeSync ( ) ;
73
79
}
@@ -93,7 +99,10 @@ export default function modifyIOS(cwd: string) {
93
99
const updatedConfig = modifyPbxprojConfig ( projectPbxProjPath ) ;
94
100
95
101
fs . writeFileSync ( projectPbxProjPath , updatedConfig ) ;
96
- logger . success (
97
- `Added "webpack-bundle" as BUNDLE_COMMAND to build phase shellScript in ${ relativeProjectPbxProjPath } `
102
+
103
+ logger . info (
104
+ `Added "@react-native-community/cli" as CLI_PATH to build phase shellScript in ${ relativeProjectPbxProjPath } `
98
105
) ;
106
+
107
+ logger . success ( 'Successfully modified iOS project files' ) ;
99
108
}
0 commit comments