@revopush/react-native-code-push 2.5.1 → 2.5.2

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.
Files changed (41) hide show
  1. package/.claude/settings.local.json +5 -1
  2. package/README.md +2 -1
  3. package/android/build.gradle +12 -1
  4. package/android/codepush.gradle +21 -44
  5. package/android/gradle.properties +2 -0
  6. package/android/proguard-rules.pro +18 -2
  7. package/android/settings.gradle +8 -9
  8. package/android/src/main/java/com/microsoft/codepush/react/BaseBundleStore.java +78 -0
  9. package/android/src/main/java/com/microsoft/codepush/react/CodePush.java +15 -4
  10. package/android/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +2 -0
  11. package/android/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +74 -18
  12. package/android/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +56 -11
  13. package/android/src/main/java/com/microsoft/codepush/react/FileUtils.java +7 -5
  14. package/docs/setup-android.md +27 -1
  15. package/ios/CodePush/CodePush.h +14 -0
  16. package/ios/CodePush/CodePush.m +17 -44
  17. package/ios/CodePush/CodePushBaseBundleStore.m +104 -0
  18. package/ios/CodePush/CodePushPackage.m +82 -9
  19. package/ios/CodePush.xcodeproj/project.pbxproj +6 -0
  20. package/ios/Frameworks/DiffUpdates.xcframework/ios-arm64/DiffUpdates.framework/DiffUpdates +0 -0
  21. package/ios/Frameworks/DiffUpdates.xcframework/ios-arm64/DiffUpdates.framework/Headers/DiffUpdates.h +18 -0
  22. package/ios/Frameworks/DiffUpdates.xcframework/ios-arm64/DiffUpdates.framework/Headers/hpatch_objc.h +23 -0
  23. package/ios/Frameworks/DiffUpdates.xcframework/ios-arm64/DiffUpdates.framework/Info.plist +0 -0
  24. package/ios/Frameworks/DiffUpdates.xcframework/ios-arm64_x86_64-simulator/DiffUpdates.framework/DiffUpdates +0 -0
  25. package/ios/Frameworks/DiffUpdates.xcframework/ios-arm64_x86_64-simulator/DiffUpdates.framework/Headers/DiffUpdates.h +18 -0
  26. package/ios/Frameworks/DiffUpdates.xcframework/ios-arm64_x86_64-simulator/DiffUpdates.framework/Headers/hpatch_objc.h +23 -0
  27. package/ios/Frameworks/DiffUpdates.xcframework/ios-arm64_x86_64-simulator/DiffUpdates.framework/Info.plist +0 -0
  28. package/ios/Frameworks/DiffUpdates.xcframework/ios-arm64_x86_64-simulator/DiffUpdates.framework/_CodeSignature/CodeDirectory +0 -0
  29. package/ios/Frameworks/DiffUpdates.xcframework/ios-arm64_x86_64-simulator/DiffUpdates.framework/_CodeSignature/CodeResources +12 -9
  30. package/package.json +10 -14
  31. package/tsconfig.json +1 -4
  32. package/typings/react-native-code-push.d.ts +18 -0
  33. package/ios/Frameworks/DiffUpdates.xcframework/ios-arm64_x86_64-simulator/DiffUpdates.framework/_CodeSignature/CodeRequirements-1 +0 -0
  34. package/scripts/postlink/android/postlink.js +0 -87
  35. package/scripts/postlink/ios/postlink.js +0 -116
  36. package/scripts/postlink/run.js +0 -11
  37. package/scripts/postunlink/android/postunlink.js +0 -74
  38. package/scripts/postunlink/ios/postunlink.js +0 -87
  39. package/scripts/postunlink/run.js +0 -11
  40. package/scripts/tools/linkToolsAndroid.js +0 -57
  41. package/scripts/tools/linkToolsIos.js +0 -130
@@ -0,0 +1,23 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ @interface hpatcher : NSObject
4
+
5
+ // return THPatchResult, 0 is ok
6
+ // cacheMemory:
7
+ // cacheMemory is used for file IO, different cacheMemory only affects patch speed;
8
+ // recommended 256*1024,1024*1024,... if cacheMemory<0 then default 256*1024;
9
+ // NOTE: if diffFile created by $xdelta3(-S,-S lzma),$open-vcdiff, alloc memory+=sourceWindowSize+targetWindowSize;
10
+ // ( sourceWindowSize & targetWindowSize is set when diff, C API getVcDiffInfo() can got values from diffFile. )
11
+ // if diffFile created by $bsdiff4, and patch very slow,
12
+ // then cacheMemory recommended oldFileSize+256*1024;
13
+
14
+ + (int)patchWithOld:(NSString *)oldFileName
15
+ withDiff:(NSString *)diffFileName
16
+ toNew:(NSString *)outNewFileName;
17
+
18
+ + (int)patchWithOld:(NSString *)oldFileName
19
+ withDiff:(NSString *)diffFileName
20
+ toNew:(NSString *)outNewFileName
21
+ byMemory:(int64_t)cacheMemory;
22
+
23
+ @end
@@ -8,6 +8,12 @@ FOUNDATION_EXPORT const unsigned char DiffUpdatesVersionString[];
8
8
 
9
9
  // In this header, you should import all the public headers of your framework using statements like #import <DiffUpdates/PublicHeader.h>
10
10
 
11
+ #if __has_include(<DiffUpdates/hpatch_objc.h>)
12
+ #import <DiffUpdates/hpatch_objc.h>
13
+ #else
14
+ #import "hpatch_objc.h"
15
+ #endif
16
+
11
17
  @interface CodePushDownloadHandler : NSObject <NSURLConnectionDelegate>
12
18
 
13
19
  @property (strong) NSOutputStream *outputFileStream;
@@ -43,6 +49,18 @@ FOUNDATION_EXPORT const unsigned char DiffUpdatesVersionString[];
43
49
  doneCallback:(void (^)(BOOL))doneCallback
44
50
  failCallback:(void (^)(NSError *err))failCallback;
45
51
 
52
+ /**
53
+ * Patches against baseBundlePath, or against the binary's own bundle when it is nil.
54
+ * The patched bundle always keeps the binary bundle's file name, whatever the base was.
55
+ */
56
+ - (void)downloadWithDiffUrl:(NSString *)diffUrl
57
+ assetsUrl:(NSString * _Nullable)assetsUrl
58
+ assetHash:(NSString * _Nullable)assetHash
59
+ nativeAssetHash:(NSString * _Nullable)nativeAssetHash
60
+ currentPackage:(NSDictionary * _Nullable)currentPackage
61
+ baseBundlePath:(NSString * _Nullable)baseBundlePath;
62
+
63
+ /** Patches against the binary's own bundle. Kept so an older SDK links against a newer framework. */
46
64
  - (void)downloadWithDiffUrl:(NSString *)diffUrl
47
65
  assetsUrl:(NSString * _Nullable)assetsUrl
48
66
  assetHash:(NSString * _Nullable)assetHash
@@ -0,0 +1,23 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ @interface hpatcher : NSObject
4
+
5
+ // return THPatchResult, 0 is ok
6
+ // cacheMemory:
7
+ // cacheMemory is used for file IO, different cacheMemory only affects patch speed;
8
+ // recommended 256*1024,1024*1024,... if cacheMemory<0 then default 256*1024;
9
+ // NOTE: if diffFile created by $xdelta3(-S,-S lzma),$open-vcdiff, alloc memory+=sourceWindowSize+targetWindowSize;
10
+ // ( sourceWindowSize & targetWindowSize is set when diff, C API getVcDiffInfo() can got values from diffFile. )
11
+ // if diffFile created by $bsdiff4, and patch very slow,
12
+ // then cacheMemory recommended oldFileSize+256*1024;
13
+
14
+ + (int)patchWithOld:(NSString *)oldFileName
15
+ withDiff:(NSString *)diffFileName
16
+ toNew:(NSString *)outNewFileName;
17
+
18
+ + (int)patchWithOld:(NSString *)oldFileName
19
+ withDiff:(NSString *)diffFileName
20
+ toNew:(NSString *)outNewFileName
21
+ byMemory:(int64_t)cacheMemory;
22
+
23
+ @end
@@ -6,11 +6,15 @@
6
6
  <dict>
7
7
  <key>Headers/DiffUpdates.h</key>
8
8
  <data>
9
- obtyjOKZntpytQhuejpfeMN0BoI=
9
+ g/pumjyvm0+YW5l1ITg21uE1aks=
10
+ </data>
11
+ <key>Headers/hpatch_objc.h</key>
12
+ <data>
13
+ SaiQblz/yRr77onv7z8Ugu73qD8=
10
14
  </data>
11
15
  <key>Info.plist</key>
12
16
  <data>
13
- 1nTR8o5HkR4SUcF0Z6umqipQPHI=
17
+ 2zKOg08DVcAALLhU4O6Sww/NWPU=
14
18
  </data>
15
19
  <key>Modules/module.modulemap</key>
16
20
  <data>
@@ -21,21 +25,20 @@
21
25
  <dict>
22
26
  <key>Headers/DiffUpdates.h</key>
23
27
  <dict>
24
- <key>hash</key>
28
+ <key>hash2</key>
25
29
  <data>
26
- obtyjOKZntpytQhuejpfeMN0BoI=
30
+ wph2g8VsI7OQgHbVrjlwf1Th3yy7DNGvT17//mXP4JY=
27
31
  </data>
32
+ </dict>
33
+ <key>Headers/hpatch_objc.h</key>
34
+ <dict>
28
35
  <key>hash2</key>
29
36
  <data>
30
- DdvTO8aHHON6ybR/EQTihMgOY9j/pmVw7sekeFl71N4=
37
+ njsIVvkyjrzbeGuTmt0E8DrCRWuM7HykrRewMTqIatw=
31
38
  </data>
32
39
  </dict>
33
40
  <key>Modules/module.modulemap</key>
34
41
  <dict>
35
- <key>hash</key>
36
- <data>
37
- MdjndwGRSccoMYmOwMDjozLG1jc=
38
- </data>
39
42
  <key>hash2</key>
40
43
  <data>
41
44
  TkYpCqgNFTGwSnC7+iZu51GEITzi1EHKvjZj4HupKms=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revopush/react-native-code-push",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
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",
@@ -37,18 +37,14 @@
37
37
  "url": "https://github.com/revopush/react-native-code-push"
38
38
  },
39
39
  "dependencies": {
40
- "@revopush/code-push": "4.4.0",
41
- "glob": "^7.1.7",
42
- "hoist-non-react-statics": "^3.3.2",
43
- "inquirer": "^8.1.5",
44
- "plist": "^3.0.4",
45
- "semver": "^7.3.5",
46
- "xcode": "3.0.1"
40
+ "@revopush/code-push": "4.6.0",
41
+ "hoist-non-react-statics": "^3.3.2"
47
42
  },
48
43
  "devDependencies": {
44
+ "@react-native/gradle-plugin": "0.79.6",
49
45
  "@types/assert": "^1.5.2",
50
46
  "@types/mkdirp": "^1.0.1",
51
- "@types/mocha": "^9.0.0",
47
+ "@types/mocha": "^10.0.0",
52
48
  "@types/node": "^14.0.27",
53
49
  "@types/q": "^1.5.4",
54
50
  "archiver": "latest",
@@ -57,7 +53,7 @@
57
53
  "del": "v6.0.0",
58
54
  "express": "latest",
59
55
  "mkdirp": "latest",
60
- "mocha": "^9.2.0",
56
+ "mocha": "^11.7.6",
61
57
  "q": "^1.5.1",
62
58
  "run-sequence": "latest",
63
59
  "shx": "^0.3.4",
@@ -65,6 +61,10 @@
65
61
  "tslint": "^6.1.3",
66
62
  "typescript": "^4.4.3"
67
63
  },
64
+ "overrides": {
65
+ "serialize-javascript": "^7.0.3",
66
+ "diff": "^8.0.3"
67
+ },
68
68
  "rnpm": {
69
69
  "android": {
70
70
  "packageInstance": "new CodePush(getResources().getString(R.string.CodePushDeploymentKey), getApplicationContext(), BuildConfig.DEBUG)"
@@ -73,10 +73,6 @@
73
73
  "sharedLibraries": [
74
74
  "libz"
75
75
  ]
76
- },
77
- "commands": {
78
- "postlink": "node node_modules/@revopush/react-native-code-push/scripts/postlink/run",
79
- "postunlink": "node node_modules/@revopush/react-native-code-push/scripts/postunlink/run"
80
76
  }
81
77
  }
82
78
  }
package/tsconfig.json CHANGED
@@ -10,8 +10,5 @@
10
10
  "rootDir": "test",
11
11
  "outDir": "bin",
12
12
  "removeComments": true
13
- },
14
- "exclude": [
15
- "Examples"
16
- ]
13
+ }
17
14
  }
@@ -89,6 +89,24 @@ export interface Package {
89
89
  * The size of the code contained within the update, in bytes.
90
90
  */
91
91
  packageSize: number;
92
+
93
+ /**
94
+ * The manifest-scheme hash of this update's JS bundle. Present from server versions that
95
+ * report it; used to match a locally held bundle against a diff's base.
96
+ */
97
+ bundleHash?: string;
98
+
99
+ /**
100
+ * URL of this update's bundle-only archive.
101
+ */
102
+ bundleBlobUrl?: string;
103
+
104
+ /**
105
+ * The base release this update's bundle diff applies to. Absent when the update has no diff.
106
+ */
107
+ basePackage?: {
108
+ packageHash: string;
109
+ };
92
110
  }
93
111
 
94
112
  export interface RemotePackage extends Package {
@@ -1,87 +0,0 @@
1
- var linkTools = require('../../tools/linkToolsAndroid');
2
- var fs = require("fs");
3
- var inquirer = require('inquirer');
4
-
5
- module.exports = () => {
6
-
7
- console.log("Running android postlink script");
8
-
9
- var buildGradlePath = linkTools.getBuildGradlePath();
10
- var mainApplicationPath = linkTools.getMainApplicationLocation();
11
-
12
- // 1. Add the getJSBundleFile override
13
- var getJSBundleFileOverride = linkTools.getJSBundleFileOverride;
14
-
15
- if (mainApplicationPath) {
16
- var mainApplicationContents = fs.readFileSync(mainApplicationPath, "utf8");
17
- if (linkTools.isJsBundleOverridden(mainApplicationContents)) {
18
- console.log(`"getJSBundleFile" is already overridden`);
19
- } else {
20
- var reactNativeHostInstantiation = linkTools.reactNativeHostInstantiation;
21
- mainApplicationContents = mainApplicationContents.replace(reactNativeHostInstantiation,
22
- `${reactNativeHostInstantiation}${getJSBundleFileOverride}`);
23
- fs.writeFileSync(mainApplicationPath, mainApplicationContents);
24
- }
25
- } else {
26
- var mainActivityPath = linkTools.getMainActivityPath();
27
- if (mainActivityPath) {
28
- var mainActivityContents = fs.readFileSync(mainActivityPath, "utf8");
29
- if (linkTools.isJsBundleOverridden(mainActivityContents)) {
30
- console.log(`"getJSBundleFile" is already overridden`);
31
- } else {
32
- var mainActivityClassDeclaration = linkTools.mainActivityClassDeclaration;
33
- mainActivityContents = mainActivityContents.replace(mainActivityClassDeclaration,
34
- `${mainActivityClassDeclaration}${getJSBundleFileOverride}`);
35
- fs.writeFileSync(mainActivityPath, mainActivityContents);
36
- }
37
- } else {
38
- return Promise.reject(`Couldn't find Android application entry point. You might need to update it manually. \
39
- Please refer to plugin configuration section for Android at \
40
- https://github.com/microsoft/react-native-code-push/blob/master/docs/setup-android.md#plugin-configuration-for-react-native-lower-than-060-android for more details`);
41
- }
42
- }
43
-
44
- if (!fs.existsSync(buildGradlePath)) {
45
- return Promise.reject(`Couldn't find build.gradle file. You might need to update it manually. \
46
- Please refer to plugin installation section for Android at \
47
- https://github.com/microsoft/react-native-code-push/blob/master/docs/setup-android.md#plugin-installation-android---manual`);
48
- }
49
-
50
- // 2. Add the codepush.gradle build task definitions
51
- var buildGradleContents = fs.readFileSync(buildGradlePath, "utf8");
52
- var reactGradleLink = buildGradleContents.match(/\napply from: ["'].*?react\.gradle["']/)[0];
53
- var codePushGradleLink = linkTools.codePushGradleLink;
54
- if (~buildGradleContents.indexOf(codePushGradleLink)) {
55
- console.log(`"codepush.gradle" is already linked in the build definition`);
56
- } else {
57
- buildGradleContents = buildGradleContents.replace(reactGradleLink,
58
- `${reactGradleLink}${codePushGradleLink}`);
59
- fs.writeFileSync(buildGradlePath, buildGradleContents);
60
- }
61
-
62
- //3. Add deployment key
63
- var stringsResourcesPath = linkTools.getStringsResourcesPath();
64
- if (!stringsResourcesPath) {
65
- return Promise.reject(new Error(`Couldn't find strings.xml. You might need to update it manually.`));
66
- } else {
67
- var stringsResourcesContent = fs.readFileSync(stringsResourcesPath, "utf8");
68
- var deploymentKeyName = linkTools.deploymentKeyName;
69
- if (~stringsResourcesContent.indexOf(deploymentKeyName)) {
70
- console.log(`${deploymentKeyName} already specified in the strings.xml`);
71
- } else {
72
- return inquirer.prompt({
73
- "type": "input",
74
- "name": "androidDeploymentKey",
75
- "message": "What is your CodePush deployment key for Android (hit <ENTER> to ignore)"
76
- }).then(function(answer) {
77
- var insertAfterString = "<resources>";
78
- var deploymentKeyString = `\t<string moduleConfig="true" name="${deploymentKeyName}">${answer.androidDeploymentKey || "deployment-key-here"}</string>`;
79
- stringsResourcesContent = stringsResourcesContent.replace(insertAfterString,`${insertAfterString}\n${deploymentKeyString}`);
80
- fs.writeFileSync(stringsResourcesPath, stringsResourcesContent);
81
- return Promise.resolve();
82
- });
83
- }
84
- }
85
-
86
- return Promise.resolve();
87
- }
@@ -1,116 +0,0 @@
1
-
2
- var linkTools = require('../../tools/linkToolsIos');
3
- var fs = require("fs");
4
- var inquirer = require('inquirer');
5
- var plist = require("plist");
6
- var semver = require('semver');
7
-
8
- var package = require('../../../../../package.json');
9
-
10
- module.exports = () => {
11
-
12
- console.log("Running ios postlink script");
13
-
14
- var appDelegatePath = linkTools.getAppDeletePath();
15
-
16
- if (!appDelegatePath) {
17
- return Promise.reject(`Couldn't find AppDelegate. You might need to update it manually \
18
- Please refer to plugin configuration section for iOS at \
19
- https://github.com/microsoft/react-native-code-push#plugin-configuration-ios`);
20
- }
21
-
22
- var appDelegateContents = fs.readFileSync(appDelegatePath, "utf8");
23
-
24
- // 1. Add the header import statement
25
- if (~appDelegateContents.indexOf(linkTools.codePushHeaderImportStatement)) {
26
- console.log(`"CodePush.h" header already imported.`);
27
- } else {
28
- var appDelegateHeaderImportStatement = `#import "AppDelegate.h"`;
29
- appDelegateContents = appDelegateContents.replace(appDelegateHeaderImportStatement,
30
- `${appDelegateHeaderImportStatement}${linkTools.codePushHeaderImportStatementFormatted}`);
31
- }
32
-
33
- // 2. Modify jsCodeLocation value assignment
34
- var reactNativeVersion = package && package.dependencies && package.dependencies["react-native"];
35
-
36
- if (!reactNativeVersion) {
37
- console.log(`Can't take react-native version from package.json`);
38
- } else if (semver.gte(semver.coerce(reactNativeVersion), "0.59.0")) {
39
- var oldBundleUrl = linkTools.oldBundleUrl;
40
- var codePushBundleUrl = linkTools.codePushBundleUrl;
41
-
42
- if (~appDelegateContents.indexOf(codePushBundleUrl)) {
43
- console.log(`"BundleUrl" already pointing to "[CodePush bundleURL]".`);
44
- } else {
45
- if (~appDelegateContents.indexOf(oldBundleUrl)) {
46
- appDelegateContents = appDelegateContents.replace(oldBundleUrl, codePushBundleUrl);
47
- } else {
48
- console.log(`AppDelegate isn't compatible for linking`);
49
- }
50
- }
51
- } else {
52
- var jsCodeLocations = appDelegateContents.match(/(jsCodeLocation = .*)/g);
53
-
54
- if (!jsCodeLocations) {
55
- console.log('Couldn\'t find jsCodeLocation setting in AppDelegate.');
56
- }
57
-
58
- var newJsCodeLocationAssignmentStatement = linkTools.codePushGradleLink;
59
- if (~appDelegateContents.indexOf(newJsCodeLocationAssignmentStatement)) {
60
- console.log(`"jsCodeLocation" already pointing to "[CodePush bundleURL]".`);
61
- } else {
62
- if (jsCodeLocations.length === 1) {
63
- // If there is one `jsCodeLocation` it means that react-native app version is not the 0.57.8 or 0.57.0 and lower than 0.59
64
- // and we should replace this line with DEBUG ifdef statement and add CodePush call for Release case
65
-
66
- var oldJsCodeLocationAssignmentStatement = jsCodeLocations[0];
67
- var jsCodeLocationPatch = linkTools.getJsCodeLocationPatch(oldJsCodeLocationAssignmentStatement);
68
- appDelegateContents = appDelegateContents.replace(oldJsCodeLocationAssignmentStatement,
69
- jsCodeLocationPatch);
70
- } else if (jsCodeLocations.length === 2) {
71
- // If there are two `jsCodeLocation` it means that react-native app version is higher than 0.57.8 or equal
72
- // and we should replace the second one(Release case) with CodePush call
73
-
74
- appDelegateContents = appDelegateContents.replace(jsCodeLocations[1],
75
- newJsCodeLocationAssignmentStatement);
76
- } else {
77
- console.log(`AppDelegate isn't compatible for linking`);
78
- }
79
- }
80
- }
81
-
82
- var plistPath = linkTools.getPlistPath();
83
-
84
- if (!plistPath) {
85
- return Promise.reject(`Couldn't find .plist file. You might need to update it manually \
86
- Please refer to plugin configuration section for iOS at \
87
- https://github.com/microsoft/react-native-code-push#plugin-configuration-ios`);
88
- }
89
-
90
- var plistContents = fs.readFileSync(plistPath, "utf8");
91
-
92
- // 3. Add CodePushDeploymentKey to plist file
93
- var parsedInfoPlist = plist.parse(plistContents);
94
- if (parsedInfoPlist.CodePushDeploymentKey) {
95
- console.log(`"CodePushDeploymentKey" already specified in the plist file.`);
96
- writePatches();
97
- return Promise.resolve();
98
- } else {
99
- return inquirer.prompt({
100
- "type": "input",
101
- "name": "iosDeploymentKey",
102
- "message": "What is your CodePush deployment key for iOS (hit <ENTER> to ignore)"
103
- }).then(function(answer) {
104
- parsedInfoPlist.CodePushDeploymentKey = answer.iosDeploymentKey || "deployment-key-here";
105
- plistContents = plist.build(parsedInfoPlist);
106
-
107
- writePatches();
108
- return Promise.resolve();
109
- });
110
- }
111
-
112
- function writePatches() {
113
- fs.writeFileSync(appDelegatePath, appDelegateContents);
114
- fs.writeFileSync(plistPath, plistContents);
115
- }
116
- }
@@ -1,11 +0,0 @@
1
- var postlinks = [
2
- require("./android/postlink"),
3
- require("./ios/postlink")
4
- ];
5
-
6
- //run them sequentially
7
- postlinks
8
- .reduce((p, fn) => p.then(fn), Promise.resolve())
9
- .catch((err) => {
10
- console.error(err.message);
11
- });
@@ -1,74 +0,0 @@
1
- var linkTools = require('../../tools/linkToolsAndroid');
2
- var fs = require("fs");
3
-
4
- module.exports = () => {
5
-
6
- console.log("Running android postunlink script");
7
-
8
- var mainApplicationPath = linkTools.getMainApplicationLocation();
9
-
10
- // 1. Remove the getJSBundleFile override
11
- var getJSBundleFileOverride = linkTools.getJSBundleFileOverride;
12
-
13
- if (mainApplicationPath) {
14
- var mainApplicationContents = fs.readFileSync(mainApplicationPath, "utf8");
15
- if (!linkTools.isJsBundleOverridden(mainApplicationContents)) {
16
- console.log(`"getJSBundleFile" is already removed`);
17
- } else {
18
- mainApplicationContents = mainApplicationContents.replace(`${getJSBundleFileOverride}`, "");
19
- fs.writeFileSync(mainApplicationPath, mainApplicationContents);
20
- }
21
- } else {
22
- var mainActivityPath = linkTools.getMainActivityPath();
23
- if (mainActivityPath) {
24
- var mainActivityContents = fs.readFileSync(mainActivityPath, "utf8");
25
- if (!linkTools.isJsBundleOverridden(mainActivityContents)) {
26
- console.log(`"getJSBundleFile" is already removed`);
27
- } else {
28
- mainActivityContents = mainActivityContents.replace(getJSBundleFileOverride, "");
29
- fs.writeFileSync(mainActivityPath, mainActivityContents);
30
- }
31
- } else {
32
- console.log(`Couldn't find Android application entry point. You might need to update it manually. \
33
- Please refer to plugin configuration section for Android at \
34
- https://github.com/microsoft/react-native-code-push/blob/master/docs/setup-android.md#plugin-configuration-for-react-native-lower-than-060-android for more details`);
35
- }
36
- }
37
-
38
- // 2. Remove the codepush.gradle build task definitions
39
- var buildGradlePath = linkTools.getBuildGradlePath();
40
-
41
- if (!fs.existsSync(buildGradlePath)) {
42
- console.log(`Couldn't find build.gradle file. You might need to update it manually. \
43
- Please refer to plugin installation section for Android at \
44
- https://github.com/microsoft/react-native-code-push/blob/master/docs/setup-android.md#plugin-installation-android---manual`);
45
- } else {
46
- var buildGradleContents = fs.readFileSync(buildGradlePath, "utf8");
47
- var codePushGradleLink = linkTools.codePushGradleLink;
48
- if (!~buildGradleContents.indexOf(codePushGradleLink)) {
49
- console.log(`"codepush.gradle" is already unlinked in the build definition`);
50
- } else {
51
- buildGradleContents = buildGradleContents.replace(`${codePushGradleLink}`,"");
52
- fs.writeFileSync(buildGradlePath, buildGradleContents);
53
- }
54
- }
55
-
56
- // 3. Remove deployment key
57
- var stringsResourcesPath = linkTools.getStringsResourcesPath();
58
- if (!stringsResourcesPath) {
59
- return Promise.reject(new Error("Couldn't find strings.xml. You might need to update it manually."));
60
- } else {
61
- var stringsResourcesContent = fs.readFileSync(stringsResourcesPath, "utf8");
62
- var deploymentKeyName = linkTools.deploymentKeyName;
63
- if (!~stringsResourcesContent.indexOf(deploymentKeyName)) {
64
- console.log(`${deploymentKeyName} already removed from the strings.xml`);
65
- } else {
66
- var AndroidDeploymentKey = stringsResourcesContent.match(/(<string moduleConfig="true" name="CodePushDeploymentKey">.*<\/string>)/);
67
- if (AndroidDeploymentKey) {
68
- stringsResourcesContent = stringsResourcesContent.replace(`\n\t${AndroidDeploymentKey[0]}`,"");
69
- fs.writeFileSync(stringsResourcesPath, stringsResourcesContent);
70
- }
71
- }
72
- }
73
- return Promise.resolve();
74
- }
@@ -1,87 +0,0 @@
1
-
2
- var linkTools = require('../../tools/linkToolsIos');
3
- var fs = require("fs");
4
- var plist = require("plist");
5
- var semver = require('semver');
6
- var packageFile = require('../../../../../package.json');
7
-
8
- module.exports = () => {
9
-
10
- console.log("Running ios postunlink script");
11
-
12
- var appDelegatePath = linkTools.getAppDeletePath();
13
-
14
- if (!appDelegatePath) {
15
- console.log(`Couldn't find AppDelegate. You might need to update it manually \
16
- Please refer to plugin configuration section for iOS at \
17
- https://github.com/microsoft/react-native-code-push#plugin-configuration-ios`);
18
- } else {
19
- var appDelegateContents = fs.readFileSync(appDelegatePath, "utf8");
20
-
21
- // 1. Remove the header import statement
22
- if (!~appDelegateContents.indexOf(linkTools.codePushHeaderImportStatement)) {
23
- console.log(`"CodePush.h" header already removed.`);
24
- } else {
25
- appDelegateContents = appDelegateContents.replace(linkTools.codePushHeaderImportStatementFormatted, "");
26
- }
27
-
28
- // 2. Modify jsCodeLocation value assignment
29
- var codePushBundleUrl = linkTools.codePushBundleUrl;
30
- if (!~appDelegateContents.indexOf(codePushBundleUrl)) {
31
- console.log(`"jsCodeLocation" already not pointing to "[CodePush bundleURL]".`);
32
- } else {
33
- var reactNativeVersion = packageFile && packageFile.dependencies && packageFile.dependencies["react-native"];
34
- if (!reactNativeVersion) {
35
- console.log(`Can't take react-native version from package.json`);
36
- } else if (semver.gte(semver.coerce(reactNativeVersion), "0.59.0")) {
37
- var oldBundleUrl = linkTools.oldBundleUrl;
38
- appDelegateContents = appDelegateContents.replace(codePushBundleUrl, oldBundleUrl);
39
- fs.writeFileSync(appDelegatePath, appDelegateContents);
40
- } else {
41
- var linkedJsCodeLocationAssignmentStatement = linkTools.linkedJsCodeLocationAssignmentStatement;
42
- var jsCodeLocations = appDelegateContents.match(/(jsCodeLocation = .*)/g);
43
- if (!jsCodeLocations || jsCodeLocations.length !== 2 || !~appDelegateContents.indexOf(linkedJsCodeLocationAssignmentStatement)) {
44
- console.log(`AppDelegate isn't compatible for unlinking`);
45
- } else {
46
- if (semver.eq(semver.coerce(reactNativeVersion), "0.57.8") || semver.eq(semver.coerce(reactNativeVersion), "0.57.0")) {
47
- // If version of react-native application is 0.57.8 or 0.57 then by default there are two different
48
- // jsCodeLocation for debug and release and we should replace only release
49
- var unlinkedJsCodeLocations = `jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];`;
50
- appDelegateContents = appDelegateContents.replace(linkedJsCodeLocationAssignmentStatement,
51
- unlinkedJsCodeLocations);
52
- } else {
53
- // If version of react-native application is not 0.57.8 or 0.57 and lower than 0.59.0 then by default there is only one
54
- // jsCodeLocation and we should stay on only it
55
- var defaultJsCodeLocationAssignmentStatement = jsCodeLocations[0];
56
- var linkedCodeLocationPatch = linkTools.getJsCodeLocationPatch(defaultJsCodeLocationAssignmentStatement);
57
- appDelegateContents = appDelegateContents.replace(linkedCodeLocationPatch,
58
- defaultJsCodeLocationAssignmentStatement);
59
- }
60
- fs.writeFileSync(appDelegatePath, appDelegateContents);
61
- }
62
- }
63
- }
64
- }
65
-
66
- var plistPath = linkTools.getPlistPath();
67
-
68
- if (!plistPath) {
69
- return Promise.reject(`Couldn't find .plist file. You might need to update it manually \
70
- Please refer to plugin configuration section for iOS at \
71
- https://github.com/microsoft/react-native-code-push#plugin-configuration-ios`);
72
- }
73
-
74
- var plistContents = fs.readFileSync(plistPath, "utf8");
75
-
76
- // 3. Remove CodePushDeploymentKey from plist file
77
- var parsedInfoPlist = plist.parse(plistContents);
78
- if (!parsedInfoPlist.CodePushDeploymentKey) {
79
- console.log(`"CodePushDeploymentKey" already removed from the plist file.`);
80
- } else {
81
- delete parsedInfoPlist.CodePushDeploymentKey;
82
- plistContents = plist.build(parsedInfoPlist);
83
- fs.writeFileSync(plistPath, plistContents);
84
- }
85
-
86
- return Promise.resolve();
87
- }
@@ -1,11 +0,0 @@
1
- var postunlinks = [
2
- require("./ios/postunlink"),
3
- require("./android/postunlink")
4
- ];
5
-
6
- //run them sequentially
7
- postunlinks
8
- .reduce((p, fn) => p.then(fn), Promise.resolve())
9
- .catch((err) => {
10
- console.error(err.message);
11
- });