@@ -40,25 +40,37 @@ module.exports = () => {
4040 }
4141
4242 // 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 ) {
4846 console . log ( 'Couldn\'t find jsCodeLocation setting in AppDelegate.' ) ;
4947 }
5048 var newJsCodeLocationAssignmentStatement = "jsCodeLocation = [CodePush bundleURL];" ;
5149 if ( ~ appDelegateContents . indexOf ( newJsCodeLocationAssignmentStatement ) ) {
5250 console . log ( `"jsCodeLocation" already pointing to "[CodePush bundleURL]".` ) ;
5351 } 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+ }
6274 }
6375
6476 var plistPath = getPlistPath ( ) ;
0 commit comments