@@ -40,25 +40,37 @@ module.exports = () => {
40
40
}
41
41
42
42
// 2. Modify jsCodeLocation value assignment
43
- var jsCodeLocations = appDelegateContents . match ( / ( j s C o d e L o c a t i o n = .* ) / ) ;
44
- var oldJsCodeLocationAssignmentStatement ;
45
- if ( jsCodeLocations ) {
46
- oldJsCodeLocationAssignmentStatement = jsCodeLocations [ 1 ] ;
47
- } else {
43
+ var jsCodeLocations = appDelegateContents . match ( / ( j s C o d e L o c a t i o n = .* ) / g) ;
44
+
45
+ if ( ! jsCodeLocations ) {
48
46
console . log ( 'Couldn\'t find jsCodeLocation setting in AppDelegate.' ) ;
49
47
}
50
48
var newJsCodeLocationAssignmentStatement = "jsCodeLocation = [CodePush bundleURL];" ;
51
49
if ( ~ appDelegateContents . indexOf ( newJsCodeLocationAssignmentStatement ) ) {
52
50
console . log ( `"jsCodeLocation" already pointing to "[CodePush bundleURL]".` ) ;
53
51
} else {
54
- var jsCodeLocationPatch = `
55
- #ifdef DEBUG
56
- ${ oldJsCodeLocationAssignmentStatement }
57
- #else
58
- ${ newJsCodeLocationAssignmentStatement }
59
- #endif` ;
60
- appDelegateContents = appDelegateContents . replace ( oldJsCodeLocationAssignmentStatement ,
61
- jsCodeLocationPatch ) ;
52
+ if ( jsCodeLocations . length === 1 ) {
53
+ // If there is one `jsCodeLocation` it means that react-native app version is lower than 0.57.8
54
+ // and we should replace this line with DEBUG ifdef statement and add CodePush call for Release case
55
+
56
+ var oldJsCodeLocationAssignmentStatement = jsCodeLocations [ 0 ] ;
57
+ var jsCodeLocationPatch = `
58
+ #ifdef DEBUG
59
+ ${ oldJsCodeLocationAssignmentStatement }
60
+ #else
61
+ ${ newJsCodeLocationAssignmentStatement }
62
+ #endif` ;
63
+ appDelegateContents = appDelegateContents . replace ( oldJsCodeLocationAssignmentStatement ,
64
+ jsCodeLocationPatch ) ;
65
+ } else if ( jsCodeLocations . length === 2 ) {
66
+ // If there are two `jsCodeLocation` it means that react-native app version is higher than 0.57.8 or equal
67
+ // and we should replace the second one(Release case) with CodePush call
68
+
69
+ appDelegateContents = appDelegateContents . replace ( jsCodeLocations [ 1 ] ,
70
+ newJsCodeLocationAssignmentStatement ) ;
71
+ } else {
72
+ console . log ( `AppDelegate isn't compatible for linking` ) ;
73
+ }
62
74
}
63
75
64
76
var plistPath = getPlistPath ( ) ;
0 commit comments