@@ -32,9 +32,18 @@ if (fs.existsSync(appName)) {
32
32
process . exit ( ) ;
33
33
}
34
34
35
+ // Checking if yarn is installed
36
+ try {
37
+ execSync ( 'yarn bin' ) ;
38
+ } catch ( err ) {
39
+ console . error ( `You must install 'yarn' to use this script!` ) ;
40
+ process . exit ( ) ;
41
+ }
42
+
35
43
let appNameAndroid = `${ appName } -android` ;
36
44
let appNameIOS = `${ appName } -ios` ;
37
45
let reactNativeVersion = args [ 1 ] || `react-native@${ execSync ( 'npm view react-native version' ) } ` . trim ( ) ;
46
+ let reactNativeVersionIsLowerThanV049 = isReactNativeVesionLowerThan ( 49 ) ;
38
47
let reactNativeCodePushVersion = args [ 2 ] || `react-native-code-push@${ execSync ( 'npm view react-native-code-push version' ) } ` . trim ( ) ;
39
48
40
49
console . log ( `App name: ${ appName } ` ) ;
@@ -89,7 +98,7 @@ function generatePlainReactNativeApp(appName, reactNativeVersion) {
89
98
90
99
function installCodePush ( reactNativeCodePushVersion ) {
91
100
console . log ( `Installing React Native Module for CodePush...` ) ;
92
- execSync ( `npm i --save ${ reactNativeCodePushVersion } ` ) ;
101
+ execSync ( `yarn add ${ reactNativeCodePushVersion } ` ) ;
93
102
console . log ( `React Native Module for CodePush has been installed \n` ) ;
94
103
}
95
104
@@ -112,22 +121,30 @@ function linkCodePush(androidStagingDeploymentKey, iosStagingDeploymentKey) {
112
121
}
113
122
114
123
function setupAssets ( ) {
115
- fs . unlinkSync ( './index.ios.js' ) ;
116
- fs . unlinkSync ( './index.android.js' ) ;
117
-
118
- fs . writeFileSync ( 'demo.js' , fs . readFileSync ( '../CodePushDemoApp/demo.js' ) ) ;
119
- fs . writeFileSync ( 'index.ios.js' , fs . readFileSync ( '../CodePushDemoApp/index.ios.js' ) ) ;
120
- fs . writeFileSync ( 'index.android.js' , fs . readFileSync ( '../CodePushDemoApp/index.android.js' ) ) ;
124
+ let fileToEdit ;
125
+ if ( reactNativeVersionIsLowerThanV049 ) {
126
+ fs . unlinkSync ( './index.ios.js' ) ;
127
+ fs . unlinkSync ( './index.android.js' ) ;
128
+
129
+ fs . writeFileSync ( 'demo.js' , fs . readFileSync ( '../CodePushDemoApp-pre0.49/demo.js' ) ) ;
130
+ fs . writeFileSync ( 'index.ios.js' , fs . readFileSync ( '../CodePushDemoApp-pre0.49/index.ios.js' ) ) ;
131
+ fs . writeFileSync ( 'index.android.js' , fs . readFileSync ( '../CodePushDemoApp-pre0.49/index.android.js' ) ) ;
132
+ fileToEdit = 'demo.js'
133
+ } else {
134
+ fs . writeFileSync ( 'index.js' , fs . readFileSync ( '../CodePushDemoApp/index.js' ) ) ;
135
+ fs . writeFileSync ( 'App.js' , fs . readFileSync ( '../CodePushDemoApp/App.js' ) ) ;
136
+ fileToEdit = 'index.js'
137
+ }
121
138
122
139
copyRecursiveSync ( '../CodePushDemoApp/images' , './images' ) ;
123
140
124
- fs . readFile ( 'demo.js' , 'utf8' , function ( err , data ) {
141
+ fs . readFile ( fileToEdit , 'utf8' , function ( err , data ) {
125
142
if ( err ) {
126
143
return console . error ( err ) ;
127
144
}
128
145
var result = data . replace ( / C o d e P u s h D e m o A p p / g, appName ) ;
129
146
130
- fs . writeFile ( 'demo.js' , result , 'utf8' , function ( err ) {
147
+ fs . writeFile ( fileToEdit , result , 'utf8' , function ( err ) {
131
148
if ( err ) return console . error ( err ) ;
132
149
133
150
if ( ! / ^ w i n / . test ( process . platform ) ) {
@@ -151,10 +168,12 @@ function optimizeToTestInDebugMode() {
151
168
rnXcodeShLocationFolder = 'packager' ;
152
169
}
153
170
} catch ( e ) { }
154
-
171
+
172
+ let rnXcodeShPath = `node_modules/react-native/${ rnXcodeShLocationFolder } /react-native-xcode.sh` ;
173
+ // Replace "if [[ "$PLATFORM_NAME" == *simulator ]]; then" with "if false; then" to force bundling
174
+ execSync ( `sed -ie 's/if \\[\\[ "\$PLATFORM_NAME" == \\*simulator \\]\\]; then/if false; then/' ${ rnXcodeShPath } ` ) ;
155
175
execSync ( `perl -i -p0e 's/#ifdef DEBUG.*?#endif/jsCodeLocation = [CodePush bundleURL];/s' ios/${ appName } /AppDelegate.m` ) ;
156
- execSync ( `sed -ie '17,20d' node_modules/react-native/${ rnXcodeShLocationFolder } /react-native-xcode.sh` ) ;
157
- execSync ( `sed -ie 's/targetName.toLowerCase().contains("release")$/true/' node_modules/react-native/react.gradle` ) ;
176
+ execSync ( `sed -ie 's/targetName.toLowerCase().contains("release")/true/' node_modules/react-native/react.gradle` ) ;
158
177
}
159
178
160
179
function grantAccess ( folderPath ) {
@@ -175,4 +194,14 @@ function copyRecursiveSync(src, dest) {
175
194
} else {
176
195
fs . linkSync ( src , dest ) ;
177
196
}
197
+ }
198
+
199
+ function isReactNativeVesionLowerThan ( version ) {
200
+ if ( ! reactNativeVersion ||
201
+ reactNativeVersion == "react-native@latest" ||
202
+ reactNativeVersion == "react-native@next" )
203
+ return false ;
204
+
205
+ let reactNativeVersionNumberString = reactNativeVersion . split ( "@" ) [ 1 ] ;
206
+ return reactNativeVersionNumberString . split ( '.' ) [ 1 ] < version ;
178
207
}
0 commit comments