@@ -4,6 +4,7 @@ var inquirer = require('inquirer');
4
4
var path = require ( "path" ) ;
5
5
var plist = require ( "plist" ) ;
6
6
var xcode = require ( "xcode" ) ;
7
+ var semver = require ( 'semver' ) ;
7
8
8
9
var package = require ( '../../../../../package.json' ) ;
9
10
@@ -40,36 +41,56 @@ module.exports = () => {
40
41
}
41
42
42
43
// 2. Modify jsCodeLocation value assignment
43
- var jsCodeLocations = appDelegateContents . match ( / ( j s C o d e L o c a t i o n = . * ) / g ) ;
44
+ var reactNativeVersion = package && package . dependencies && package . dependencies [ "react-native" ] ;
44
45
45
- if ( ! jsCodeLocations ) {
46
- console . log ( 'Couldn\'t find jsCodeLocation setting in AppDelegate.' ) ;
47
- }
48
- var newJsCodeLocationAssignmentStatement = "jsCodeLocation = [CodePush bundleURL];" ;
49
- if ( ~ appDelegateContents . indexOf ( newJsCodeLocationAssignmentStatement ) ) {
50
- console . log ( `"jsCodeLocation" already pointing to "[CodePush bundleURL]".` ) ;
46
+ if ( ! reactNativeVersion ) {
47
+ console . log ( `Can't take react-native version from package.json` ) ;
48
+ } else if ( semver . gte ( semver . coerce ( reactNativeVersion ) , "0.59.0" ) ) {
49
+ var oldBundleUrl = "[[NSBundle mainBundle] URLForResource:@\"main\" withExtension:@\"jsbundle\"]" ;
50
+ var codePushBundleUrl = "[CodePush bundleURL]" ;
51
+
52
+ if ( ~ appDelegateContents . indexOf ( codePushBundleUrl ) ) {
53
+ console . log ( `"BundleUrl" already pointing to "[CodePush bundleURL]".` ) ;
54
+ } else {
55
+ if ( ~ appDelegateContents . indexOf ( oldBundleUrl ) ) {
56
+ appDelegateContents = appDelegateContents . replace ( oldBundleUrl , codePushBundleUrl ) ;
57
+ } else {
58
+ console . log ( `AppDelegate isn't compatible for linking` ) ;
59
+ }
60
+ }
51
61
} else {
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 ) ;
62
+ var jsCodeLocations = appDelegateContents . match ( / ( j s C o d e L o c a t i o n = .* ) / g) ;
63
+
64
+ if ( ! jsCodeLocations ) {
65
+ console . log ( 'Couldn\'t find jsCodeLocation setting in AppDelegate.' ) ;
66
+ }
67
+
68
+ var newJsCodeLocationAssignmentStatement = "jsCodeLocation = [CodePush bundleURL];" ;
69
+ if ( ~ appDelegateContents . indexOf ( newJsCodeLocationAssignmentStatement ) ) {
70
+ console . log ( `"jsCodeLocation" already pointing to "[CodePush bundleURL]".` ) ;
71
71
} else {
72
- console . log ( `AppDelegate isn't compatible for linking` ) ;
72
+ if ( jsCodeLocations . length === 1 ) {
73
+ // If there is one `jsCodeLocation` it means that react-native app version is lower than 0.57.8
74
+ // and we should replace this line with DEBUG ifdef statement and add CodePush call for Release case
75
+
76
+ var oldJsCodeLocationAssignmentStatement = jsCodeLocations [ 0 ] ;
77
+ var jsCodeLocationPatch = `
78
+ #ifdef DEBUG
79
+ ${ oldJsCodeLocationAssignmentStatement }
80
+ #else
81
+ ${ newJsCodeLocationAssignmentStatement }
82
+ #endif` ;
83
+ appDelegateContents = appDelegateContents . replace ( oldJsCodeLocationAssignmentStatement ,
84
+ jsCodeLocationPatch ) ;
85
+ } else if ( jsCodeLocations . length === 2 ) {
86
+ // If there are two `jsCodeLocation` it means that react-native app version is higher than 0.57.8 or equal
87
+ // and we should replace the second one(Release case) with CodePush call
88
+
89
+ appDelegateContents = appDelegateContents . replace ( jsCodeLocations [ 1 ] ,
90
+ newJsCodeLocationAssignmentStatement ) ;
91
+ } else {
92
+ console . log ( `AppDelegate isn't compatible for linking` ) ;
93
+ }
73
94
}
74
95
}
75
96
@@ -111,7 +132,7 @@ module.exports = () => {
111
132
// Helper that filters an array with AppDelegate.m paths for a path with the app name inside it
112
133
// Should cover nearly all cases
113
134
function findFileByAppName ( array , appName ) {
114
- if ( array . length === 0 || ! appName ) return null ;
135
+ if ( array . length === 0 || ! appName ) return null ;
115
136
116
137
for ( var i = 0 ; i < array . length ; i ++ ) {
117
138
var path = array [ i ] ;
@@ -206,4 +227,4 @@ module.exports = () => {
206
227
//(see https://github.com/Microsoft/react-native-code-push/issues/534#issuecomment-302069326 for details)
207
228
return path . resolve ( path . dirname ( xcodeProjectPath ) , '..' , plistPathValue . replace ( / ^ " ( .* ) " $ / , '$1' ) ) ;
208
229
}
209
- }
230
+ }
0 commit comments