@bravemobile/react-native-code-push 12.0.0-beta.0 → 12.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -23
- package/cli/commands/initCommand/index.js +14 -0
- package/cli/commands/initCommand/initAndroid.js +48 -0
- package/cli/commands/initCommand/initIos.js +128 -0
- package/cli/commands/initCommand/test/initAndroid.test.js +85 -0
- package/cli/commands/initCommand/test/initIos.test.js +98 -0
- package/cli/index.js +6 -0
- package/expo/plugin/withCodePushAndroid.js +1 -1
- package/expo/plugin/withCodePushIos.js +2 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -21,11 +21,13 @@ npm remove react-native-code-push
|
|
|
21
21
|
npm install @bravemobile/react-native-code-push
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
1. Edit `android/app/build.gradle` file to remove the `apply from: "../../node_modules/..../codepush.gradle"` line.
|
|
25
25
|
|
|
26
|
-
The following changes are optional but recommended for cleaning up the old configuration:
|
|
27
|
-
- Since the deployment key is no longer needed due to the retirement of AppCenter, it is recommended to remove it from your `Info.plist`, `strings.xml`, or JavaScript code.
|
|
28
|
-
- Thanks to Auto Linking, you can remove the `react-native-code-push` module settings from `settings.gradle`.
|
|
26
|
+
2. The following changes are optional but recommended for cleaning up the old configuration:
|
|
27
|
+
- Since the deployment key is no longer needed due to the retirement of AppCenter, it is recommended to remove it from your `Info.plist`, `strings.xml`, or JavaScript code.
|
|
28
|
+
- Thanks to Auto Linking, you can remove the `react-native-code-push` module settings from `settings.gradle`.
|
|
29
|
+
|
|
30
|
+
3. Follow the installation guide starting from **'4. "CodePush-ify" your app'**.
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
## ⚙️ Installation
|
|
@@ -35,7 +37,31 @@ The following changes are optional but recommended for cleaning up the old confi
|
|
|
35
37
|
npm install @bravemobile/react-native-code-push
|
|
36
38
|
```
|
|
37
39
|
|
|
38
|
-
### 2.
|
|
40
|
+
### 2. Run init command
|
|
41
|
+
|
|
42
|
+
For React Native CLI projects, you can use the automatic setup command to configure your project for CodePush.
|
|
43
|
+
|
|
44
|
+
This command will automatically edit your `AppDelegate` and `MainApplication` files to integrate CodePush.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npx code-push init
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
And run the following command to install CocoaPods dependencies for iOS:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
cd ios && pod install && cd ..
|
|
54
|
+
```
|
|
55
|
+
(or `npx pod-install`, `bundle exec pod install --project-directory=./ios`, ..)
|
|
56
|
+
|
|
57
|
+
### 2-1. Manual Setup
|
|
58
|
+
|
|
59
|
+
If you prefer manual setup or if the automatic configuration fails, you can follow the manual setup instructions below.
|
|
60
|
+
|
|
61
|
+
<details><summary>Click to see the manual setup instructions.</summary>
|
|
62
|
+
<p>
|
|
63
|
+
|
|
64
|
+
### iOS Manual Setup
|
|
39
65
|
|
|
40
66
|
#### (1) Install CocoaPods Dependencies
|
|
41
67
|
|
|
@@ -54,7 +80,7 @@ Run `cd ios && pod install && cd ..`
|
|
|
54
80
|
|
|
55
81
|
1. Open your project with Xcode (e.g. CodePushDemoApp.xcworkspace)
|
|
56
82
|
2. File → New → File from Template
|
|
57
|
-
3. Select 'Objective-C File' and click 'Next' and write any name as you like.
|
|
83
|
+
3. Select 'Objective-C File' and click 'Next' and write any name as you like.
|
|
58
84
|
4. Then Xcode will ask you to create a bridging header file. Click 'Create'.
|
|
59
85
|
5. Delete the file created in step 3.
|
|
60
86
|
|
|
@@ -110,17 +136,9 @@ Then, edit `AppDelegate.swift` like below.
|
|
|
110
136
|
```
|
|
111
137
|
|
|
112
138
|
|
|
113
|
-
###
|
|
114
|
-
|
|
115
|
-
#### (1) Edit `android/app/build.gradle`
|
|
116
|
-
|
|
117
|
-
Add the following line to the end of the file.
|
|
118
|
-
```diff
|
|
119
|
-
// ...
|
|
120
|
-
+ apply from: "../../node_modules/@bravemobile/react-native-code-push/android/codepush.gradle"
|
|
121
|
-
```
|
|
139
|
+
### Android Manual Setup
|
|
122
140
|
|
|
123
|
-
####
|
|
141
|
+
#### Edit `MainApplication` Code
|
|
124
142
|
|
|
125
143
|
**If you have `MainApplication.kt` (>= RN 0.73)**
|
|
126
144
|
|
|
@@ -161,7 +179,11 @@ Add the following line to the end of the file.
|
|
|
161
179
|
}
|
|
162
180
|
```
|
|
163
181
|
|
|
164
|
-
|
|
182
|
+
</p>
|
|
183
|
+
</details>
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
### 3. Expo Setup
|
|
165
187
|
For Expo projects, you can use the automated config plugin instead of manual setup.
|
|
166
188
|
|
|
167
189
|
**Add plugin to your Expo configuration:**
|
|
@@ -185,7 +207,8 @@ npx expo prebuild
|
|
|
185
207
|
**Requirements**
|
|
186
208
|
Expo SDK: 50.0.0 or higher
|
|
187
209
|
|
|
188
|
-
|
|
210
|
+
|
|
211
|
+
### 4. "CodePush-ify" Your App
|
|
189
212
|
|
|
190
213
|
The root component of your app should be wrapped with a higher-order component.
|
|
191
214
|
|
|
@@ -199,8 +222,8 @@ At runtime, the library fetches this information to keep the app up to date.
|
|
|
199
222
|
|
|
200
223
|
```typescript
|
|
201
224
|
import CodePush, {
|
|
202
|
-
|
|
203
|
-
|
|
225
|
+
ReleaseHistoryInterface,
|
|
226
|
+
UpdateCheckRequest,
|
|
204
227
|
} from "@bravemobile/react-native-code-push";
|
|
205
228
|
|
|
206
229
|
// ... MyApp Component
|
|
@@ -229,7 +252,7 @@ export default CodePush({
|
|
|
229
252
|
> The URL for fetching the release history should point to the resource location generated by the CLI tool.
|
|
230
253
|
|
|
231
254
|
|
|
232
|
-
####
|
|
255
|
+
#### 4-1. Telemetry Callbacks
|
|
233
256
|
|
|
234
257
|
Please refer to the [CodePushOptions](https://github.com/Soomgo-Mobile/react-native-code-push/blob/f0d26f7614af41c6dd4daecd9f7146e2383b2b0d/typings/react-native-code-push.d.ts#L76-L95) type for more details.
|
|
235
258
|
- **onUpdateSuccess:** Triggered when the update bundle is executed successfully.
|
|
@@ -239,7 +262,7 @@ Please refer to the [CodePushOptions](https://github.com/Soomgo-Mobile/react-nat
|
|
|
239
262
|
- **onSyncError:** Triggered when an unknown error occurs during the update process. (`CodePush.SyncStatus.UNKNOWN_ERROR` status)
|
|
240
263
|
|
|
241
264
|
|
|
242
|
-
###
|
|
265
|
+
### 5. Configure the CLI Tool
|
|
243
266
|
|
|
244
267
|
> [!TIP]
|
|
245
268
|
> For a more detailed and practical example, refer to the `CodePushDemoApp` in `example` directory. ([link](https://github.com/Soomgo-Mobile/react-native-code-push/tree/master/Examples/CodePushDemoApp))
|
|
@@ -352,7 +375,7 @@ Create a new release history for a specific binary app version.
|
|
|
352
375
|
This ensures that the library runtime recognizes the binary app as the latest version and determines that no CodePush update is available for it.
|
|
353
376
|
|
|
354
377
|
**Example:**
|
|
355
|
-
- Create a new release history for the binary app version `1.0.0`.
|
|
378
|
+
- Create a new release history for the binary app version `1.0.0`.
|
|
356
379
|
|
|
357
380
|
```bash
|
|
358
381
|
npx code-push create-history --binary-version 1.0.0 --platform ios --identifier staging
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const { initAndroid } = require('./initAndroid');
|
|
2
|
+
const { initIos } = require('./initIos');
|
|
3
|
+
const { program } = require('commander');
|
|
4
|
+
|
|
5
|
+
program
|
|
6
|
+
.command('init')
|
|
7
|
+
.description('Automatically performs iOS/Android native configurations to initialize the CodePush project.')
|
|
8
|
+
.action(async () => {
|
|
9
|
+
console.log('log: Start initializing CodePush...');
|
|
10
|
+
await initAndroid();
|
|
11
|
+
await initIos();
|
|
12
|
+
console.log('log: CodePush has been successfully initialized.');
|
|
13
|
+
});
|
|
14
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { EOL } = require('os');
|
|
4
|
+
|
|
5
|
+
function modifyMainApplicationKt(mainApplicationContent) {
|
|
6
|
+
if (mainApplicationContent.includes('CodePush.getJSBundleFile()')) {
|
|
7
|
+
console.log('log: MainApplication.kt already has CodePush initialized.');
|
|
8
|
+
return mainApplicationContent;
|
|
9
|
+
}
|
|
10
|
+
return mainApplicationContent
|
|
11
|
+
.replace('import com.facebook.react.ReactApplication', `import com.facebook.react.ReactApplication${EOL}import com.microsoft.codepush.react.CodePush`)
|
|
12
|
+
.replace('override fun getJSMainModuleName(): String = "index"', `override fun getJSMainModuleName(): String = "index"${EOL} override fun getJSBundleFile(): String = CodePush.getJSBundleFile()`)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function initAndroid() {
|
|
16
|
+
console.log('log: Running Android setup...');
|
|
17
|
+
await applyMainApplication();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function applyMainApplication() {
|
|
21
|
+
const mainApplicationPath = await findMainApplication();
|
|
22
|
+
if (!mainApplicationPath) {
|
|
23
|
+
console.log('log: Could not find MainApplication.kt');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (mainApplicationPath.endsWith('.java')) {
|
|
28
|
+
console.log('log: MainApplication.java is not supported. Please migrate to MainApplication.kt.');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const mainApplicationContent = fs.readFileSync(mainApplicationPath, 'utf-8');
|
|
33
|
+
const newContent = modifyMainApplicationKt(mainApplicationContent);
|
|
34
|
+
fs.writeFileSync(mainApplicationPath, newContent);
|
|
35
|
+
console.log('log: Successfully updated MainApplication.kt.');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function findMainApplication() {
|
|
39
|
+
const searchPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'java');
|
|
40
|
+
const files = fs.readdirSync(searchPath, { recursive: true });
|
|
41
|
+
const mainApplicationFile = files.find(file => file.endsWith('MainApplication.java') || file.endsWith('MainApplication.kt'));
|
|
42
|
+
return mainApplicationFile ? path.join(searchPath, mainApplicationFile) : null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
initAndroid: initAndroid,
|
|
47
|
+
modifyMainApplicationKt: modifyMainApplicationKt,
|
|
48
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const xcode = require('xcode');
|
|
4
|
+
|
|
5
|
+
async function initIos() {
|
|
6
|
+
console.log('log: Running iOS setup...');
|
|
7
|
+
const projectDir = path.join(process.cwd(), 'ios');
|
|
8
|
+
const files = fs.readdirSync(projectDir);
|
|
9
|
+
const xcodeprojFile = files.find(file => file.endsWith('.xcodeproj'));
|
|
10
|
+
if (!xcodeprojFile) {
|
|
11
|
+
console.log('log: Could not find .xcodeproj file in ios directory');
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const projectName = xcodeprojFile.replace('.xcodeproj', '');
|
|
15
|
+
const appDelegatePath = findAppDelegate(path.join(projectDir, projectName));
|
|
16
|
+
|
|
17
|
+
if (!appDelegatePath) {
|
|
18
|
+
console.log('log: Could not find AppDelegate file');
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (appDelegatePath.endsWith('.swift')) {
|
|
23
|
+
await setupSwift(appDelegatePath, projectDir, projectName);
|
|
24
|
+
} else {
|
|
25
|
+
await setupObjectiveC(appDelegatePath);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
console.log('log: Please run `cd ios && pod install` to complete the setup.');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function findAppDelegate(searchPath) {
|
|
32
|
+
if (!fs.existsSync(searchPath)) return null;
|
|
33
|
+
const files = fs.readdirSync(searchPath);
|
|
34
|
+
const appDelegateFile = files.find(file => file.startsWith('AppDelegate') && (file.endsWith('.m') || file.endsWith('.mm') || file.endsWith('.swift')));
|
|
35
|
+
return appDelegateFile ? path.join(searchPath, appDelegateFile) : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function modifyObjectiveCAppDelegate(appDelegateContent) {
|
|
39
|
+
const IMPORT_STATEMENT = '#import <CodePush/CodePush.h>';
|
|
40
|
+
if (appDelegateContent.includes(IMPORT_STATEMENT)) {
|
|
41
|
+
console.log('log: AppDelegate already has CodePush imported.');
|
|
42
|
+
return appDelegateContent;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return appDelegateContent
|
|
46
|
+
.replace('#import "AppDelegate.h"\n', `#import "AppDelegate.h"\n${IMPORT_STATEMENT}\n`)
|
|
47
|
+
.replace('[[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];', '[CodePush bundleURL];');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function modifySwiftAppDelegate(appDelegateContent) {
|
|
51
|
+
const CODEPUSH_CALL_STATEMENT = 'CodePush.bundleURL()';
|
|
52
|
+
if (appDelegateContent.includes(CODEPUSH_CALL_STATEMENT)) {
|
|
53
|
+
console.log('log: AppDelegate.swift already configured for CodePush.');
|
|
54
|
+
return appDelegateContent;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return appDelegateContent
|
|
58
|
+
.replace('Bundle.main.url(forResource: "main", withExtension: "jsbundle")', CODEPUSH_CALL_STATEMENT);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function setupObjectiveC(appDelegatePath) {
|
|
62
|
+
const appDelegateContent = fs.readFileSync(appDelegatePath, 'utf-8');
|
|
63
|
+
const newContent = modifyObjectiveCAppDelegate(appDelegateContent);
|
|
64
|
+
fs.writeFileSync(appDelegatePath, newContent);
|
|
65
|
+
console.log('log: Successfully updated AppDelegate.m/mm.');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function setupSwift(appDelegatePath, projectDir, projectName) {
|
|
69
|
+
const bridgingHeaderPath = await ensureBridgingHeader(projectDir, projectName);
|
|
70
|
+
if (!bridgingHeaderPath) {
|
|
71
|
+
console.log('log: Failed to create or find bridging header.');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const appDelegateContent = fs.readFileSync(appDelegatePath, 'utf-8');
|
|
76
|
+
const newContent = modifySwiftAppDelegate(appDelegateContent);
|
|
77
|
+
fs.writeFileSync(appDelegatePath, newContent);
|
|
78
|
+
console.log('log: Successfully updated AppDelegate.swift.');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function ensureBridgingHeader(projectDir, projectName) {
|
|
82
|
+
const projectPath = path.join(projectDir, `${projectName}.xcodeproj`, 'project.pbxproj');
|
|
83
|
+
const myProj = xcode.project(projectPath);
|
|
84
|
+
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
myProj.parse(function (err) {
|
|
87
|
+
if (err) {
|
|
88
|
+
console.error(`Error parsing Xcode project: ${err}`);
|
|
89
|
+
return reject(err);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const bridgingHeaderRelativePath = `${projectName}/${projectName}-Bridging-Header.h`;
|
|
93
|
+
const bridgingHeaderAbsolutePath = path.join(projectDir, bridgingHeaderRelativePath);
|
|
94
|
+
|
|
95
|
+
const configurations = myProj.pbxXCBuildConfigurationSection();
|
|
96
|
+
for (const name in configurations) {
|
|
97
|
+
const config = configurations[name];
|
|
98
|
+
if (config.buildSettings) {
|
|
99
|
+
config.buildSettings.SWIFT_OBJC_BRIDGING_HEADER = `"${bridgingHeaderRelativePath}"`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!fs.existsSync(bridgingHeaderAbsolutePath)) {
|
|
104
|
+
fs.mkdirSync(path.dirname(bridgingHeaderAbsolutePath), { recursive: true });
|
|
105
|
+
fs.writeFileSync(bridgingHeaderAbsolutePath, '#import <CodePush/CodePush.h>\n');
|
|
106
|
+
console.log(`log: Created bridging header at ${bridgingHeaderAbsolutePath}`);
|
|
107
|
+
const groupKey = myProj.findPBXGroupKey({ name: projectName });
|
|
108
|
+
myProj.addHeaderFile(bridgingHeaderRelativePath, { public: true }, groupKey);
|
|
109
|
+
} else {
|
|
110
|
+
const headerContent = fs.readFileSync(bridgingHeaderAbsolutePath, 'utf-8');
|
|
111
|
+
if (!headerContent.includes('#import <CodePush/CodePush.h>')) {
|
|
112
|
+
fs.appendFileSync(bridgingHeaderAbsolutePath, '\n#import <CodePush/CodePush.h>\n');
|
|
113
|
+
console.log(`log: Updated bridging header at ${bridgingHeaderAbsolutePath}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fs.writeFileSync(projectPath, myProj.writeSync());
|
|
118
|
+
console.log('log: Updated Xcode project with bridging header path.');
|
|
119
|
+
resolve(bridgingHeaderAbsolutePath);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = {
|
|
125
|
+
initIos: initIos,
|
|
126
|
+
modifyObjectiveCAppDelegate: modifyObjectiveCAppDelegate,
|
|
127
|
+
modifySwiftAppDelegate: modifySwiftAppDelegate,
|
|
128
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { initAndroid, modifyMainApplicationKt } = require('../initAndroid');
|
|
4
|
+
|
|
5
|
+
const tempDir = path.join(__dirname, 'temp');
|
|
6
|
+
|
|
7
|
+
// https://github.com/react-native-community/template/blob/0.80.2/template/android/app/src/main/java/com/helloworld/MainApplication.kt
|
|
8
|
+
const ktTemplate = `
|
|
9
|
+
package com.helloworld
|
|
10
|
+
|
|
11
|
+
import android.app.Application
|
|
12
|
+
import com.facebook.react.PackageList
|
|
13
|
+
import com.facebook.react.ReactApplication
|
|
14
|
+
import com.facebook.react.ReactHost
|
|
15
|
+
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
|
|
16
|
+
import com.facebook.react.ReactNativeHost
|
|
17
|
+
import com.facebook.react.ReactPackage
|
|
18
|
+
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
|
|
19
|
+
import com.facebook.react.defaults.DefaultReactNativeHost
|
|
20
|
+
|
|
21
|
+
class MainApplication : Application(), ReactApplication {
|
|
22
|
+
|
|
23
|
+
override val reactNativeHost: ReactNativeHost =
|
|
24
|
+
object : DefaultReactNativeHost(this) {
|
|
25
|
+
override fun getPackages(): List<ReactPackage> =
|
|
26
|
+
PackageList(this).packages.apply {
|
|
27
|
+
// Packages that cannot be autolinked yet can be added manually here, for example:
|
|
28
|
+
// add(MyReactNativePackage())
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override fun getJSMainModuleName(): String = "index"
|
|
32
|
+
|
|
33
|
+
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
|
|
34
|
+
|
|
35
|
+
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
|
|
36
|
+
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override val reactHost: ReactHost
|
|
40
|
+
get() = getDefaultReactHost(applicationContext, reactNativeHost)
|
|
41
|
+
|
|
42
|
+
override fun onCreate() {
|
|
43
|
+
super.onCreate()
|
|
44
|
+
loadReactNative(this)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
describe('Android init command', () => {
|
|
50
|
+
it('should correctly modify Kotlin MainApplication content', () => {
|
|
51
|
+
const modifiedContent = modifyMainApplicationKt(ktTemplate);
|
|
52
|
+
expect(modifiedContent).toContain('import com.microsoft.codepush.react.CodePush');
|
|
53
|
+
expect(modifiedContent).toContain('override fun getJSBundleFile(): String = CodePush.getJSBundleFile()');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should log a message and exit if MainApplication.java is found', async () => {
|
|
57
|
+
const originalCwd = process.cwd();
|
|
58
|
+
|
|
59
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
60
|
+
process.chdir(tempDir);
|
|
61
|
+
|
|
62
|
+
// Arrange
|
|
63
|
+
const javaAppDir = path.join(tempDir, 'android', 'app', 'src', 'main', 'java', 'com', 'helloworld');
|
|
64
|
+
fs.mkdirSync(javaAppDir, { recursive: true });
|
|
65
|
+
const javaFilePath = path.join(javaAppDir, 'MainApplication.java');
|
|
66
|
+
const originalContent = '// Java file content';
|
|
67
|
+
fs.writeFileSync(javaFilePath, originalContent);
|
|
68
|
+
|
|
69
|
+
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Act
|
|
73
|
+
await initAndroid();
|
|
74
|
+
|
|
75
|
+
// Assert
|
|
76
|
+
expect(consoleSpy).toHaveBeenCalledWith('MainApplication.java is not supported. Please migrate to MainApplication.kt.');
|
|
77
|
+
const finalContent = fs.readFileSync(javaFilePath, 'utf-8');
|
|
78
|
+
expect(finalContent).toBe(originalContent); // Ensure file is not modified
|
|
79
|
+
|
|
80
|
+
consoleSpy.mockRestore();
|
|
81
|
+
|
|
82
|
+
process.chdir(originalCwd);
|
|
83
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const { modifyObjectiveCAppDelegate, modifySwiftAppDelegate } = require('../initIos');
|
|
2
|
+
|
|
3
|
+
// https://github.com/react-native-community/template/blob/0.80.2/template/ios/HelloWorld/AppDelegate.swift
|
|
4
|
+
const swiftTemplate = `
|
|
5
|
+
import UIKit
|
|
6
|
+
import React
|
|
7
|
+
import React_RCTAppDelegate
|
|
8
|
+
import ReactAppDependencyProvider
|
|
9
|
+
|
|
10
|
+
@main
|
|
11
|
+
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
12
|
+
var window: UIWindow?
|
|
13
|
+
var reactNativeDelegate: ReactNativeDelegate?
|
|
14
|
+
var reactNativeFactory: RCTReactNativeFactory?
|
|
15
|
+
|
|
16
|
+
func application(
|
|
17
|
+
_ application: UIApplication,
|
|
18
|
+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
|
|
19
|
+
) -> Bool {
|
|
20
|
+
let delegate = ReactNativeDelegate()
|
|
21
|
+
let factory = RCTReactNativeFactory(delegate: delegate)
|
|
22
|
+
delegate.dependencyProvider = RCTAppDependencyProvider()
|
|
23
|
+
reactNativeDelegate = delegate
|
|
24
|
+
reactNativeFactory = factory
|
|
25
|
+
window = UIWindow(frame: UIScreen.main.bounds)
|
|
26
|
+
factory.startReactNative(
|
|
27
|
+
withModuleName: "HelloWorld",
|
|
28
|
+
in: window,
|
|
29
|
+
launchOptions: launchOptions
|
|
30
|
+
)
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate {
|
|
36
|
+
override func sourceURL(for bridge: RCTBridge) -> URL? {
|
|
37
|
+
self.bundleURL()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override func bundleURL() -> URL? {
|
|
41
|
+
#if DEBUG
|
|
42
|
+
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
|
|
43
|
+
#else
|
|
44
|
+
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
|
|
45
|
+
#endif
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
// https://github.com/react-native-community/template/blob/0.76.9/template/ios/HelloWorld/AppDelegate.mm
|
|
51
|
+
const objcTemplate = `
|
|
52
|
+
#import "AppDelegate.h"
|
|
53
|
+
|
|
54
|
+
#import <React/RCTBundleURLProvider.h>
|
|
55
|
+
|
|
56
|
+
@implementation AppDelegate
|
|
57
|
+
|
|
58
|
+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
59
|
+
{
|
|
60
|
+
self.moduleName = @"HelloWorld";
|
|
61
|
+
// You can add your custom initial props in the dictionary below.
|
|
62
|
+
// They will be passed down to the ViewController used by React Native.
|
|
63
|
+
self.initialProps = @{};
|
|
64
|
+
|
|
65
|
+
return [super application:application didFinishLaunchingWithOptions:launchOptions];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
|
|
69
|
+
{
|
|
70
|
+
return [self bundleURL];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
- (NSURL *)bundleURL
|
|
74
|
+
{
|
|
75
|
+
#if DEBUG
|
|
76
|
+
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
|
|
77
|
+
#else
|
|
78
|
+
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
|
|
79
|
+
#endif
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@end
|
|
83
|
+
`;
|
|
84
|
+
|
|
85
|
+
describe('iOS init command - pure functions', () => {
|
|
86
|
+
it('should correctly modify Swift AppDelegate content', () => {
|
|
87
|
+
const modifiedContent = modifySwiftAppDelegate(swiftTemplate);
|
|
88
|
+
expect(modifiedContent).toContain('CodePush.bundleURL()');
|
|
89
|
+
expect(modifiedContent).not.toContain('Bundle.main.url(forResource: "main", withExtension: "jsbundle")');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should correctly modify Objective-C AppDelegate content', () => {
|
|
93
|
+
const modifiedContent = modifyObjectiveCAppDelegate(objcTemplate);
|
|
94
|
+
expect(modifiedContent).toContain('#import <CodePush/CodePush.h>');
|
|
95
|
+
expect(modifiedContent).toContain('[CodePush bundleURL]');
|
|
96
|
+
expect(modifiedContent).not.toContain('[[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];');
|
|
97
|
+
});
|
|
98
|
+
});
|
package/cli/index.js
CHANGED
|
@@ -21,7 +21,7 @@ function androidMainApplicationApplyImplementation(
|
|
|
21
21
|
Please add "${add.replace(/\n/g, '').trim()}" to the MainApplication.kt.
|
|
22
22
|
Supported format: Expo SDK default template.
|
|
23
23
|
|
|
24
|
-
Android manual setup: https://github.com/Soomgo-Mobile/react-native-code-push#
|
|
24
|
+
Android manual setup: https://github.com/Soomgo-Mobile/react-native-code-push#2-1-manual-setup
|
|
25
25
|
`,
|
|
26
26
|
);
|
|
27
27
|
|
|
@@ -24,7 +24,7 @@ function iosApplyImplementation(
|
|
|
24
24
|
Please ${replace ? 'replace' : 'add'} "${add.replace(/\n/g, '').trim()}" to the AppDelegate.(m|swift).
|
|
25
25
|
Supported format: Expo SDK default template.
|
|
26
26
|
|
|
27
|
-
iOS manual setup: https://github.com/Soomgo-Mobile/react-native-code-push#2-
|
|
27
|
+
iOS manual setup: https://github.com/Soomgo-Mobile/react-native-code-push#2-1-manual-setup
|
|
28
28
|
`,
|
|
29
29
|
);
|
|
30
30
|
|
|
@@ -126,7 +126,7 @@ const withIosBridgingHeader = (config) => {
|
|
|
126
126
|
#import <CodePush/CodePush.h>
|
|
127
127
|
|
|
128
128
|
Supported format: Expo SDK default template.
|
|
129
|
-
iOS manual setup: https://github.com/Soomgo-Mobile/react-native-code-push#2-
|
|
129
|
+
iOS manual setup: https://github.com/Soomgo-Mobile/react-native-code-push#2-1-manual-setup
|
|
130
130
|
`
|
|
131
131
|
);
|
|
132
132
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bravemobile/react-native-code-push",
|
|
3
|
-
"version": "12.0.0-beta.
|
|
3
|
+
"version": "12.0.0-beta.3",
|
|
4
4
|
"description": "React Native plugin for the CodePush service",
|
|
5
5
|
"main": "CodePush.js",
|
|
6
6
|
"typings": "typings/react-native-code-push.d.ts",
|
|
@@ -89,7 +89,8 @@
|
|
|
89
89
|
"ts-node": "^10.9.2",
|
|
90
90
|
"tslint": "^6.1.3",
|
|
91
91
|
"typescript": "5.0.4",
|
|
92
|
-
"typescript-eslint": "^8.11.0"
|
|
92
|
+
"typescript-eslint": "^8.11.0",
|
|
93
|
+
"xcode": "^3.0.1"
|
|
93
94
|
},
|
|
94
95
|
"engines": {
|
|
95
96
|
"node": ">=18"
|