Skip to content

Commit 81641f1

Browse files
committed
Update CodePush integration to use @srcpush/react-native-code-push and disable new architecture for compatibility
1 parent 5a031ad commit 81641f1

1 file changed

Lines changed: 25 additions & 22 deletions

File tree

test/test.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Platform, PluginTestingFramework, ProjectManager, setupTestRunScenario,
1111
import Q = require("q");
1212

1313
import del = require("del");
14+
import {isOldArchitecture} from "code-push-plugin-testing-framework/script/testConfig";
1415

1516
//////////////////////////////////////////////////////////////////////////////////////////
1617
// Create the platforms to run the tests on.
@@ -78,21 +79,21 @@ class RNAndroid extends Platform.Android implements RNPlatform {
7879
*/
7980
installPlatform(projectDirectory: string): Q.Promise<void> {
8081
const innerprojectDirectory: string = path.join(projectDirectory, TestConfig.TestAppName);
81-
const gradleContent: string = slash(path.join(innerprojectDirectory, "node_modules", "react-native-code-push", "android", "codepush.gradle"));
82+
const gradleContent: string = slash(path.join(innerprojectDirectory, "node_modules", "@srcpush/react-native-code-push", "android", "codepush.gradle"));
8283

8384
//// Set up gradle to build CodePush with the app
8485
// Add CodePush to android/app/build.gradle
8586
const buildGradle = path.join(innerprojectDirectory, "android", "app", "build.gradle");
8687

8788
TestUtil.replaceString(buildGradle,
88-
"apply from: file\\(\"../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle\"\\); applyNativeModulesAppBuildGradle\\(project\\)",
89-
"apply from: file(\"../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle\"); applyNativeModulesAppBuildGradle(project)\napply from: \"" + gradleContent + "\"");
89+
"apply plugin: \"com.facebook.react\"",
90+
"apply plugin: \"com.facebook.react\"\napply from: \"" + gradleContent + "\"");
9091

91-
// Add CodePush to android/settings.gradle
92-
const settingsGradle = path.join(innerprojectDirectory, "android", "settings.gradle");
93-
TestUtil.replaceString(settingsGradle,
94-
"include ':app'",
95-
"include ':app', ':react-native-code-push'\nproject(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')");
92+
// Disable new architecture
93+
if (TestConfig.isOldArchitecture) {
94+
const gradleProperties = path.join(innerprojectDirectory, "android", "gradle.properties");
95+
TestUtil.replaceString(gradleProperties, "newArchEnabled=true", "newArchEnabled=false");
96+
}
9697

9798
//// Set the app version to 1.0.0 instead of 1.0
9899
// Set the app version to 1.0.0 in android/app/build.gradle
@@ -119,14 +120,14 @@ class RNAndroid extends Platform.Android implements RNPlatform {
119120
return TestUtil.getProcessOutput("adb install -r " + this.getBinaryPath(projectDirectory), { cwd: androidDirectory }).then(() => { return null; });
120121
}
121122

122-
/**
123-
* Build function of the test application, the command depends on the OS
124-
*/
123+
/**
124+
* Build function of the test application, the command depends on the OS
125+
*/
125126
buildFunction(androidDirectory: string): Q.Promise<void> {
126127
const gradlewCommand = process.platform === "darwin" || process.platform === "linux" ? "./gradlew" : "gradlew";
127128
return TestUtil.getProcessOutput(`${gradlewCommand} clean`, { noLogStdOut: true, cwd: androidDirectory })
128-
.then(() => TestUtil.getProcessOutput(`${gradlewCommand} assembleRelease --daemon`, { noLogStdOut: true, cwd: androidDirectory }))
129-
.then(() => { return null; });
129+
.then(() => TestUtil.getProcessOutput(`${gradlewCommand} assembleRelease --daemon`, { noLogStdOut: true, cwd: androidDirectory }))
130+
.then(() => { return null; });
130131
}
131132

132133
/**
@@ -177,10 +178,12 @@ class RNIOS extends Platform.IOS implements RNPlatform {
177178
const iOSProject: string = path.join(projectDirectory, TestConfig.TestAppName, "ios");
178179
const infoPlistPath: string = path.join(iOSProject, TestConfig.TestAppName, "Info.plist");
179180
const appDelegatePath: string = path.join(iOSProject, TestConfig.TestAppName, "AppDelegate.mm");
181+
const podfilePath: string = path.join(iOSProject, "Podfile");
180182

181183

182184
// Install the Podfile
183-
return TestUtil.getProcessOutput("pod install", { cwd: iOSProject })
185+
return TestUtil.copyFile(path.join(TestConfig.templatePath, "ios", "Podfile"), podfilePath, true)
186+
.then(() => TestUtil.getProcessOutput(`RCT_NEW_ARCH_ENABLED=${TestConfig.isOldArchitecture ? 0 : 1} pod install`, { cwd: iOSProject }))
184187
// Put the IOS deployment key in the Info.plist
185188
.then(TestUtil.replaceString.bind(undefined, infoPlistPath,
186189
"</dict>\n</plist>",
@@ -195,11 +198,11 @@ class RNIOS extends Platform.IOS implements RNPlatform {
195198
// Add the correct bundle identifier
196199
.then(TestUtil.replaceString.bind(undefined, path.join(iOSProject, TestConfig.TestAppName + ".xcodeproj", "project.pbxproj"),
197200
"PRODUCT_BUNDLE_IDENTIFIER = [^;]*", "PRODUCT_BUNDLE_IDENTIFIER = \"" + TestConfig.TestNamespace + "\""))
198-
// Copy the AppDelegate.mm to the project
201+
// Copy the AppDelegate.swift to the project
199202
.then(TestUtil.copyFile.bind(undefined,
200-
path.join(TestConfig.templatePath, "ios", TestConfig.TestAppName, "AppDelegate.mm"),
203+
path.join(TestConfig.templatePath, "ios", TestConfig.TestAppName, "AppDelegate.swift"),
201204
appDelegatePath, true))
202-
.then<void>(TestUtil.replaceString.bind(undefined, appDelegatePath, TestUtil.CODE_PUSH_TEST_APP_NAME_PLACEHOLDER, TestConfig.TestAppName));
205+
.then(TestUtil.replaceString.bind(undefined, appDelegatePath, TestUtil.CODE_PUSH_TEST_APP_NAME_PLACEHOLDER, TestConfig.TestAppName));
203206
}
204207

205208
/**
@@ -211,7 +214,7 @@ class RNIOS extends Platform.IOS implements RNPlatform {
211214

212215
/**
213216
* Maps project directories to whether or not they have built an IOS project before.
214-
*
217+
*
215218
* The first build of an IOS project does not always succeed, so we always try again when it fails.
216219
*
217220
* EXAMPLE:
@@ -231,7 +234,7 @@ class RNIOS extends Platform.IOS implements RNPlatform {
231234
return this.getEmulatorManager().getTargetEmulator()
232235
.then((targetEmulator: string) => {
233236
return TestUtil.getProcessOutput("xcodebuild -workspace " + path.join(iOSProject, TestConfig.TestAppName) + ".xcworkspace -scheme " + TestConfig.TestAppName +
234-
" -configuration Release -destination \"platform=iOS Simulator,id=" + targetEmulator + "\" -derivedDataPath build EXCLUDED_ARCHS=arm64", { cwd: iOSProject, timeout: 30 * 60 * 1000, maxBuffer: 1024 * 1024 * 5000, noLogStdOut: true });
237+
" -configuration Release -destination \"platform=iOS Simulator,id=" + targetEmulator + "\" -derivedDataPath build", { cwd: iOSProject, timeout: 30 * 60 * 1000, maxBuffer: 1024 * 1024 * 5000, noLogStdOut: true });
235238
})
236239
.then<void>(
237240
() => { return null; },
@@ -307,13 +310,13 @@ class RNProjectManager extends ProjectManager {
307310
}
308311
mkdirp.sync(projectDirectory);
309312

310-
return TestUtil.getProcessOutput("npx react-native init " + appName + " --version 0.71.3 --install-pods", { cwd: projectDirectory, timeout: 30 * 60 * 1000 })
311-
.then((e) => { console.log(`"npx react-native init ${appName}" success. cwd=${projectDirectory}`); return e; })
313+
return TestUtil.getProcessOutput("npx @react-native-community/cli init " + appName + " --version 0.78.0 --install-pods", { cwd: projectDirectory, timeout: 30 * 60 * 1000 })
314+
.then((e) => { console.log(`"npx @react-native-community/cli init ${appName}" success. cwd=${projectDirectory}`); return e; })
312315
.then(this.copyTemplate.bind(this, templatePath, projectDirectory))
313316
.then<void>(TestUtil.getProcessOutput.bind(undefined, TestConfig.thisPluginInstallString, { cwd: path.join(projectDirectory, TestConfig.TestAppName) }))
314317
.then(() => { return null; })
315318
.catch((error) => {
316-
console.log(`"npx react-native init ${appName} failed". cwd=${projectDirectory}`, error);
319+
console.log(`"npx @react-native-community/cli init ${appName} failed". cwd=${projectDirectory}`, error);
317320
throw new Error(error);
318321
});
319322
}

0 commit comments

Comments
 (0)