@@ -32,9 +32,18 @@ if (fs.existsSync(appName)) {
3232 process . exit ( ) ;
3333}
3434
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+
3543let appNameAndroid = `${ appName } -android` ;
3644let appNameIOS = `${ appName } -ios` ;
3745let reactNativeVersion = args [ 1 ] || `react-native@${ execSync ( 'npm view react-native version' ) } ` . trim ( ) ;
46+ let reactNativeVersionIsLowerThanV049 = isReactNativeVesionLowerThan ( 49 ) ;
3847let reactNativeCodePushVersion = args [ 2 ] || `react-native-code-push@${ execSync ( 'npm view react-native-code-push version' ) } ` . trim ( ) ;
3948
4049console . log ( `App name: ${ appName } ` ) ;
@@ -89,7 +98,7 @@ function generatePlainReactNativeApp(appName, reactNativeVersion) {
8998
9099function installCodePush ( reactNativeCodePushVersion ) {
91100 console . log ( `Installing React Native Module for CodePush...` ) ;
92- execSync ( `npm i --save ${ reactNativeCodePushVersion } ` ) ;
101+ execSync ( `yarn add ${ reactNativeCodePushVersion } ` ) ;
93102 console . log ( `React Native Module for CodePush has been installed \n` ) ;
94103}
95104
@@ -112,22 +121,30 @@ function linkCodePush(androidStagingDeploymentKey, iosStagingDeploymentKey) {
112121}
113122
114123function 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+ }
121138
122139 copyRecursiveSync ( '../CodePushDemoApp/images' , './images' ) ;
123140
124- fs . readFile ( 'demo.js' , 'utf8' , function ( err , data ) {
141+ fs . readFile ( fileToEdit , 'utf8' , function ( err , data ) {
125142 if ( err ) {
126143 return console . error ( err ) ;
127144 }
128145 var result = data . replace ( / C o d e P u s h D e m o A p p / g, appName ) ;
129146
130- fs . writeFile ( 'demo.js' , result , 'utf8' , function ( err ) {
147+ fs . writeFile ( fileToEdit , result , 'utf8' , function ( err ) {
131148 if ( err ) return console . error ( err ) ;
132149
133150 if ( ! / ^ w i n / . test ( process . platform ) ) {
@@ -151,10 +168,12 @@ function optimizeToTestInDebugMode() {
151168 rnXcodeShLocationFolder = 'packager' ;
152169 }
153170 } 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 } ` ) ;
155175 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` ) ;
158177}
159178
160179function grantAccess ( folderPath ) {
@@ -175,4 +194,14 @@ function copyRecursiveSync(src, dest) {
175194 } else {
176195 fs . linkSync ( src , dest ) ;
177196 }
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 ;
178207}
0 commit comments