Skip to content

Commit

Permalink
Fix ios postlink (#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandergoncharov-zz authored Dec 21, 2018
1 parent d34a4db commit 7964db1
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions scripts/postlink/ios/postlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,37 @@ module.exports = () => {
}

// 2. Modify jsCodeLocation value assignment
var jsCodeLocations = appDelegateContents.match(/(jsCodeLocation = .*)/);
var oldJsCodeLocationAssignmentStatement;
if (jsCodeLocations) {
oldJsCodeLocationAssignmentStatement = jsCodeLocations[1];
} else {
var jsCodeLocations = appDelegateContents.match(/(jsCodeLocation = .*)/g);

if (!jsCodeLocations) {
console.log('Couldn\'t find jsCodeLocation setting in AppDelegate.');
}
var newJsCodeLocationAssignmentStatement = "jsCodeLocation = [CodePush bundleURL];";
if (~appDelegateContents.indexOf(newJsCodeLocationAssignmentStatement)) {
console.log(`"jsCodeLocation" already pointing to "[CodePush bundleURL]".`);
} else {
var jsCodeLocationPatch = `
#ifdef DEBUG
${oldJsCodeLocationAssignmentStatement}
#else
${newJsCodeLocationAssignmentStatement}
#endif`;
appDelegateContents = appDelegateContents.replace(oldJsCodeLocationAssignmentStatement,
jsCodeLocationPatch);
if (jsCodeLocations.length === 1) {
// If there is one `jsCodeLocation` it means that react-native app version is lower than 0.57.8
// and we should replace this line with DEBUG ifdef statement and add CodePush call for Release case

var oldJsCodeLocationAssignmentStatement = jsCodeLocations[0];
var jsCodeLocationPatch = `
#ifdef DEBUG
${oldJsCodeLocationAssignmentStatement}
#else
${newJsCodeLocationAssignmentStatement}
#endif`;
appDelegateContents = appDelegateContents.replace(oldJsCodeLocationAssignmentStatement,
jsCodeLocationPatch);
} else if (jsCodeLocations.length === 2) {
// If there are two `jsCodeLocation` it means that react-native app version is higher than 0.57.8 or equal
// and we should replace the second one(Release case) with CodePush call

appDelegateContents = appDelegateContents.replace(jsCodeLocations[1],
newJsCodeLocationAssignmentStatement);
} else {
console.log(`AppDelegate isn't compatible for linking`);
}
}

var plistPath = getPlistPath();
Expand Down

0 comments on commit 7964db1

Please sign in to comment.