Skip to content

Commit

Permalink
fix 'Bundle React Native code and images' build phase
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxAst committed Dec 15, 2024
1 parent fa2b0b8 commit df6c921
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions plugin/src/xcode/addBuildPhases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function addBuildPhases(
group: string;
};
resources: string[];
}
},
) {
const buildPath = `"$(CONTENTS_FOLDER_PATH)/ShareExtensions"`;
const targetType = "app_extension";
Expand All @@ -33,7 +33,7 @@ export function addBuildPhases(
shellScript:
'export RCT_METRO_PORT="${RCT_METRO_PORT:=8081}"\necho "export RCT_METRO_PORT=${RCT_METRO_PORT}" > "${SRCROOT}/../node_modules/react-native/scripts/.packager.env"\nif [ -z "${RCT_NO_LAUNCH_PACKAGER+xxx}" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s "http://localhost:${RCT_METRO_PORT}/status" | grep -q "packager-status:running" ; then\n echo "Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly"\n exit 2\n fi\n else\n open "$SRCROOT/../node_modules/react-native/scripts/launchPackager.command" || echo "Can\'t start packager automatically"\n fi\nfi\n',
},
buildPath
buildPath,
);

// Sources build phase
Expand All @@ -43,7 +43,7 @@ export function addBuildPhases(
groupName,
targetUuid,
targetType,
buildPath
buildPath,
);

// Copy files build phase
Expand All @@ -52,15 +52,15 @@ export function addBuildPhases(
"PBXCopyFilesBuildPhase",
groupName,
xcodeProject.getFirstTarget().uuid,
targetType
targetType,
);

xcodeProject.addBuildPhase(
[],
"PBXCopyFilesBuildPhase",
"Copy Files",
xcodeProject.getFirstTarget().uuid,
targetType
targetType,
);
xcodeProject.addToPbxCopyfilesBuildPhase(productFile);

Expand All @@ -71,7 +71,7 @@ export function addBuildPhases(
groupName,
targetUuid,
targetType,
buildPath
buildPath,
);

// Resources build phase
Expand All @@ -81,20 +81,48 @@ export function addBuildPhases(
groupName,
targetUuid,
targetType,
buildPath
buildPath,
);

// Add shell script build phase
xcodeProject.addBuildPhase(
[],
"PBXShellScriptBuildPhase",
"Bundle React Native code and images",
targetUuid,
{
shellPath: "/bin/sh",
shellScript:
'set -e; NODE_BINARY=${NODE_BINARY:-node}; REACT_NATIVE_SCRIPTS_PATH=$("$NODE_BINARY" --print "require(\'path\').dirname(require.resolve(\'react-native/package.json\')) + \'/scripts\'"); WITH_ENVIRONMENT="$REACT_NATIVE_SCRIPTS_PATH/xcode/with-environment.sh"; REACT_NATIVE_XCODE="$REACT_NATIVE_SCRIPTS_PATH/react-native-xcode.sh"; export ENTRY_FILE=index.share.js; /bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE";',
shellScript: `set -e
NODE_BINARY=\${NODE_BINARY:-node}
# Source environment files
if [[ -f "$PODS_ROOT/../.xcode.env" ]]; then
source "$PODS_ROOT/../.xcode.env"
fi
if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
source "$PODS_ROOT/../.xcode.env.local"
fi
# Set project root
export PROJECT_ROOT="$PROJECT_DIR"/..
# Set entry file
export ENTRY_FILE="index.share.js"
# Set up Expo CLI
if [[ -z "$CLI_PATH" ]]; then
export CLI_PATH="$("$NODE_BINARY" --print "require.resolve('@expo/cli', { paths: [require.resolve('expo/package.json')] })")"
fi
if [[ -z "$BUNDLE_COMMAND" ]]; then
export BUNDLE_COMMAND="export:embed"
fi
REACT_NATIVE_SCRIPTS_PATH=$("$NODE_BINARY" --print "require('path').dirname(require.resolve('react-native/package.json')) + '/scripts'")
WITH_ENVIRONMENT="$REACT_NATIVE_SCRIPTS_PATH/xcode/with-environment.sh"
REACT_NATIVE_XCODE="$REACT_NATIVE_SCRIPTS_PATH/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"`,
},
buildPath
buildPath,
);
}

0 comments on commit df6c921

Please sign in to comment.