Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit da7b1fa

Browse files
yuri-kulikovNickToropov
authored andcommitted
Fixed create-app.js script (#1386)
1 parent 1f86296 commit da7b1fa

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

Examples/CodePushDemoApp/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class App extends Component<{}> {
106106
<Text style={styles.syncButton}>Press for dialog-driven sync</Text>
107107
</TouchableOpacity>
108108
{progressView}
109-
<Image style={styles.image} resizeMode={Image.resizeMode.contain} source={require("./images/laptop_phone_howitworks.png")}/>
109+
<Image style={styles.image} resizeMode={"contain"} source={require("./images/laptop_phone_howitworks.png")}/>
110110
<TouchableOpacity onPress={this.toggleAllowRestart.bind(this)}>
111111
<Text style={styles.restartToggleButton}>Restart { this.state.restartAllowed ? "allowed" : "forbidden"}</Text>
112112
</TouchableOpacity>

Examples/create-app.js

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3543
let appNameAndroid = `${appName}-android`;
3644
let appNameIOS = `${appName}-ios`;
3745
let reactNativeVersion = args[1] || `react-native@${execSync('npm view react-native version')}`.trim();
46+
let reactNativeVersionIsLowerThanV049 = isReactNativeVesionLowerThan(49);
3847
let reactNativeCodePushVersion = args[2] || `react-native-code-push@${execSync('npm view react-native-code-push version')}`.trim();
3948

4049
console.log(`App name: ${appName}`);
@@ -89,7 +98,7 @@ function generatePlainReactNativeApp(appName, reactNativeVersion) {
8998

9099
function 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

114123
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+
}
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(/CodePushDemoApp/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 (!/^win/.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

160179
function 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

Comments
 (0)