mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-05-09 07:08:57 +08:00
Fixed create-app.js script (#1386)
This commit is contained in:
committed by
Nickolay Toropov
parent
1f862960a0
commit
da7b1faa21
@@ -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>
|
||||
|
||||
@@ -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}`);
|
||||
@@ -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`);
|
||||
}
|
||||
|
||||
@@ -112,22 +121,30 @@ function linkCodePush(androidStagingDeploymentKey, iosStagingDeploymentKey) {
|
||||
}
|
||||
|
||||
function setupAssets() {
|
||||
fs.unlinkSync('./index.ios.js');
|
||||
fs.unlinkSync('./index.android.js');
|
||||
let fileToEdit;
|
||||
if (reactNativeVersionIsLowerThanV049) {
|
||||
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'));
|
||||
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)) {
|
||||
@@ -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) {
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user