Skip to content

Commit

Permalink
Fixed create-app.js script (#1386)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-kulikov authored and NickToropov committed Aug 23, 2018
1 parent 1f86296 commit da7b1fa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Examples/CodePushDemoApp/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class App extends Component<{}> {
<Text style={styles.syncButton}>Press for dialog-driven sync</Text>
</TouchableOpacity>
{progressView}
<Image style={styles.image} resizeMode={Image.resizeMode.contain} source={require("./images/laptop_phone_howitworks.png")}/>
<Image style={styles.image} resizeMode={"contain"} source={require("./images/laptop_phone_howitworks.png")}/>
<TouchableOpacity onPress={this.toggleAllowRestart.bind(this)}>
<Text style={styles.restartToggleButton}>Restart { this.state.restartAllowed ? "allowed" : "forbidden"}</Text>
</TouchableOpacity>
Expand Down
53 changes: 41 additions & 12 deletions Examples/create-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,18 @@ if (fs.existsSync(appName)) {
process.exit();
}

// Checking if yarn is installed
try {
execSync('yarn bin');
} catch (err) {
console.error(`You must install 'yarn' to use this script!`);
process.exit();
}

let appNameAndroid = `${appName}-android`;
let appNameIOS = `${appName}-ios`;
let reactNativeVersion = args[1] || `react-native@${execSync('npm view react-native version')}`.trim();
let reactNativeVersionIsLowerThanV049 = isReactNativeVesionLowerThan(49);
let reactNativeCodePushVersion = args[2] || `react-native-code-push@${execSync('npm view react-native-code-push version')}`.trim();

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

function installCodePush(reactNativeCodePushVersion) {
console.log(`Installing React Native Module for CodePush...`);
execSync(`npm i --save ${reactNativeCodePushVersion}`);
execSync(`yarn add ${reactNativeCodePushVersion}`);
console.log(`React Native Module for CodePush has been installed \n`);
}

Expand All @@ -112,22 +121,30 @@ function linkCodePush(androidStagingDeploymentKey, iosStagingDeploymentKey) {
}

function setupAssets() {
fs.unlinkSync('./index.ios.js');
fs.unlinkSync('./index.android.js');

fs.writeFileSync('demo.js', fs.readFileSync('../CodePushDemoApp/demo.js'));
fs.writeFileSync('index.ios.js', fs.readFileSync('../CodePushDemoApp/index.ios.js'));
fs.writeFileSync('index.android.js', fs.readFileSync('../CodePushDemoApp/index.android.js'));
let fileToEdit;
if (reactNativeVersionIsLowerThanV049) {
fs.unlinkSync('./index.ios.js');
fs.unlinkSync('./index.android.js');

fs.writeFileSync('demo.js', fs.readFileSync('../CodePushDemoApp-pre0.49/demo.js'));
fs.writeFileSync('index.ios.js', fs.readFileSync('../CodePushDemoApp-pre0.49/index.ios.js'));
fs.writeFileSync('index.android.js', fs.readFileSync('../CodePushDemoApp-pre0.49/index.android.js'));
fileToEdit = 'demo.js'
} else {
fs.writeFileSync('index.js', fs.readFileSync('../CodePushDemoApp/index.js'));
fs.writeFileSync('App.js', fs.readFileSync('../CodePushDemoApp/App.js'));
fileToEdit = 'index.js'
}

copyRecursiveSync('../CodePushDemoApp/images', './images');

fs.readFile('demo.js', 'utf8', function (err, data) {
fs.readFile(fileToEdit, 'utf8', function (err, data) {
if (err) {
return console.error(err);
}
var result = data.replace(/CodePushDemoApp/g, appName);

fs.writeFile('demo.js', result, 'utf8', function (err) {
fs.writeFile(fileToEdit, result, 'utf8', function (err) {
if (err) return console.error(err);

if (!/^win/.test(process.platform)) {
Expand All @@ -151,10 +168,12 @@ function optimizeToTestInDebugMode() {
rnXcodeShLocationFolder = 'packager';
}
} catch(e) {}


let rnXcodeShPath = `node_modules/react-native/${rnXcodeShLocationFolder}/react-native-xcode.sh`;
// Replace "if [[ "$PLATFORM_NAME" == *simulator ]]; then" with "if false; then" to force bundling
execSync(`sed -ie 's/if \\[\\[ "\$PLATFORM_NAME" == \\*simulator \\]\\]; then/if false; then/' ${rnXcodeShPath}`);
execSync(`perl -i -p0e 's/#ifdef DEBUG.*?#endif/jsCodeLocation = [CodePush bundleURL];/s' ios/${appName}/AppDelegate.m`);
execSync(`sed -ie '17,20d' node_modules/react-native/${rnXcodeShLocationFolder}/react-native-xcode.sh`);
execSync(`sed -ie 's/targetName.toLowerCase().contains("release")$/true/' node_modules/react-native/react.gradle`);
execSync(`sed -ie 's/targetName.toLowerCase().contains("release")/true/' node_modules/react-native/react.gradle`);
}

function grantAccess(folderPath) {
Expand All @@ -175,4 +194,14 @@ function copyRecursiveSync(src, dest) {
} else {
fs.linkSync(src, dest);
}
}

function isReactNativeVesionLowerThan(version) {
if (!reactNativeVersion ||
reactNativeVersion == "react-native@latest" ||
reactNativeVersion == "react-native@next")
return false;

let reactNativeVersionNumberString = reactNativeVersion.split("@")[1];
return reactNativeVersionNumberString.split('.')[1] < version;
}

0 comments on commit da7b1fa

Please sign in to comment.