mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-05-28 23:51:07 +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>
|
<Text style={styles.syncButton}>Press for dialog-driven sync</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
{progressView}
|
{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)}>
|
<TouchableOpacity onPress={this.toggleAllowRestart.bind(this)}>
|
||||||
<Text style={styles.restartToggleButton}>Restart { this.state.restartAllowed ? "allowed" : "forbidden"}</Text>
|
<Text style={styles.restartToggleButton}>Restart { this.state.restartAllowed ? "allowed" : "forbidden"}</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
|||||||
@@ -32,9 +32,18 @@ if (fs.existsSync(appName)) {
|
|||||||
process.exit();
|
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 appNameAndroid = `${appName}-android`;
|
||||||
let appNameIOS = `${appName}-ios`;
|
let appNameIOS = `${appName}-ios`;
|
||||||
let reactNativeVersion = args[1] || `react-native@${execSync('npm view react-native version')}`.trim();
|
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();
|
let reactNativeCodePushVersion = args[2] || `react-native-code-push@${execSync('npm view react-native-code-push version')}`.trim();
|
||||||
|
|
||||||
console.log(`App name: ${appName}`);
|
console.log(`App name: ${appName}`);
|
||||||
@@ -89,7 +98,7 @@ function generatePlainReactNativeApp(appName, reactNativeVersion) {
|
|||||||
|
|
||||||
function installCodePush(reactNativeCodePushVersion) {
|
function installCodePush(reactNativeCodePushVersion) {
|
||||||
console.log(`Installing React Native Module for CodePush...`);
|
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`);
|
console.log(`React Native Module for CodePush has been installed \n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,22 +121,30 @@ function linkCodePush(androidStagingDeploymentKey, iosStagingDeploymentKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupAssets() {
|
function setupAssets() {
|
||||||
fs.unlinkSync('./index.ios.js');
|
let fileToEdit;
|
||||||
fs.unlinkSync('./index.android.js');
|
if (reactNativeVersionIsLowerThanV049) {
|
||||||
|
fs.unlinkSync('./index.ios.js');
|
||||||
|
fs.unlinkSync('./index.android.js');
|
||||||
|
|
||||||
fs.writeFileSync('demo.js', fs.readFileSync('../CodePushDemoApp/demo.js'));
|
fs.writeFileSync('demo.js', fs.readFileSync('../CodePushDemoApp-pre0.49/demo.js'));
|
||||||
fs.writeFileSync('index.ios.js', fs.readFileSync('../CodePushDemoApp/index.ios.js'));
|
fs.writeFileSync('index.ios.js', fs.readFileSync('../CodePushDemoApp-pre0.49/index.ios.js'));
|
||||||
fs.writeFileSync('index.android.js', fs.readFileSync('../CodePushDemoApp/index.android.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');
|
copyRecursiveSync('../CodePushDemoApp/images', './images');
|
||||||
|
|
||||||
fs.readFile('demo.js', 'utf8', function (err, data) {
|
fs.readFile(fileToEdit, 'utf8', function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return console.error(err);
|
return console.error(err);
|
||||||
}
|
}
|
||||||
var result = data.replace(/CodePushDemoApp/g, appName);
|
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 (err) return console.error(err);
|
||||||
|
|
||||||
if (!/^win/.test(process.platform)) {
|
if (!/^win/.test(process.platform)) {
|
||||||
@@ -152,9 +169,11 @@ function optimizeToTestInDebugMode() {
|
|||||||
}
|
}
|
||||||
} catch(e) {}
|
} 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(`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) {
|
function grantAccess(folderPath) {
|
||||||
@@ -176,3 +195,13 @@ function copyRecursiveSync(src, dest) {
|
|||||||
fs.linkSync(src, dest);
|
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