@appzung/react-native-code-push 5.7.1

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 (191) hide show
  1. package/AlertAdapter.js +24 -0
  2. package/CONTRIBUTING.md +136 -0
  3. package/CodePush.js +666 -0
  4. package/CodePush.podspec +27 -0
  5. package/LICENSE.md +13 -0
  6. package/README.md +386 -0
  7. package/RestartManager.js +59 -0
  8. package/android/app/build.gradle +31 -0
  9. package/android/app/proguard-rules.pro +25 -0
  10. package/android/app/src/main/AndroidManifest.xml +10 -0
  11. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +395 -0
  12. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +37 -0
  13. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +34 -0
  14. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +102 -0
  15. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInstallMode.java +16 -0
  16. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +12 -0
  17. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidUpdateException.java +7 -0
  18. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushMalformedDataException.java +12 -0
  19. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +641 -0
  20. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNotInitializedException.java +12 -0
  21. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushTelemetryManager.java +175 -0
  22. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUnknownException.java +12 -0
  23. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +369 -0
  24. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateState.java +15 -0
  25. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +267 -0
  26. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java +236 -0
  27. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +30 -0
  28. package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +5 -0
  29. package/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java +190 -0
  30. package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +17 -0
  31. package/android/app/src/main/java/com/microsoft/codepush/react/SettingsManager.java +173 -0
  32. package/android/build.gradle +20 -0
  33. package/android/codepush.gradle +113 -0
  34. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  35. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  36. package/android/gradle.properties +20 -0
  37. package/android/gradlew +164 -0
  38. package/android/gradlew.bat +90 -0
  39. package/android/settings.gradle +1 -0
  40. package/docs/api-android.md +65 -0
  41. package/docs/api-ios.md +31 -0
  42. package/docs/api-js.md +592 -0
  43. package/docs/multi-deployment-testing-android.md +107 -0
  44. package/docs/multi-deployment-testing-ios.md +53 -0
  45. package/docs/setup-android.md +406 -0
  46. package/docs/setup-ios.md +229 -0
  47. package/docs/setup-windows.md +65 -0
  48. package/gulpfile.js +302 -0
  49. package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +34 -0
  50. package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +252 -0
  51. package/ios/CodePush/Base64/README.md +47 -0
  52. package/ios/CodePush/CodePush.h +235 -0
  53. package/ios/CodePush/CodePush.m +1041 -0
  54. package/ios/CodePush/CodePushConfig.m +116 -0
  55. package/ios/CodePush/CodePushDownloadHandler.m +130 -0
  56. package/ios/CodePush/CodePushErrorUtils.m +20 -0
  57. package/ios/CodePush/CodePushPackage.m +598 -0
  58. package/ios/CodePush/CodePushTelemetryManager.m +175 -0
  59. package/ios/CodePush/CodePushUpdateUtils.m +376 -0
  60. package/ios/CodePush/CodePushUtils.m +9 -0
  61. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +69 -0
  62. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +16 -0
  63. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +51 -0
  64. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +15 -0
  65. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +55 -0
  66. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +24 -0
  67. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +41 -0
  68. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +28 -0
  69. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +205 -0
  70. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +103 -0
  71. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +322 -0
  72. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +37 -0
  73. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +145 -0
  74. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +35 -0
  75. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +551 -0
  76. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +23 -0
  77. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +43 -0
  78. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +230 -0
  79. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +31 -0
  80. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +113 -0
  81. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +38 -0
  82. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +500 -0
  83. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +18 -0
  84. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +214 -0
  85. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +23 -0
  86. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +29 -0
  87. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +19 -0
  88. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +68 -0
  89. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +18 -0
  90. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +72 -0
  91. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +67 -0
  92. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +111 -0
  93. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +119 -0
  94. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +307 -0
  95. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +94 -0
  96. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +619 -0
  97. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +164 -0
  98. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +514 -0
  99. package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +24 -0
  100. package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +11 -0
  101. package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +52 -0
  102. package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +5 -0
  103. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +28 -0
  104. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +70 -0
  105. package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +22 -0
  106. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +34 -0
  107. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +73 -0
  108. package/ios/CodePush/JWT/LICENSE +19 -0
  109. package/ios/CodePush/JWT/README.md +489 -0
  110. package/ios/CodePush/RCTConvert+CodePushInstallMode.m +20 -0
  111. package/ios/CodePush/RCTConvert+CodePushUpdateState.m +20 -0
  112. package/ios/CodePush/SSZipArchive/Common.h +81 -0
  113. package/ios/CodePush/SSZipArchive/README.md +1 -0
  114. package/ios/CodePush/SSZipArchive/SSZipArchive.h +76 -0
  115. package/ios/CodePush/SSZipArchive/SSZipArchive.m +691 -0
  116. package/ios/CodePush/SSZipArchive/aes/aes.h +198 -0
  117. package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +541 -0
  118. package/ios/CodePush/SSZipArchive/aes/aescrypt.c +294 -0
  119. package/ios/CodePush/SSZipArchive/aes/aeskey.c +548 -0
  120. package/ios/CodePush/SSZipArchive/aes/aesopt.h +739 -0
  121. package/ios/CodePush/SSZipArchive/aes/aestab.c +391 -0
  122. package/ios/CodePush/SSZipArchive/aes/aestab.h +173 -0
  123. package/ios/CodePush/SSZipArchive/aes/brg_endian.h +126 -0
  124. package/ios/CodePush/SSZipArchive/aes/brg_types.h +219 -0
  125. package/ios/CodePush/SSZipArchive/aes/entropy.c +54 -0
  126. package/ios/CodePush/SSZipArchive/aes/entropy.h +16 -0
  127. package/ios/CodePush/SSZipArchive/aes/fileenc.c +144 -0
  128. package/ios/CodePush/SSZipArchive/aes/fileenc.h +121 -0
  129. package/ios/CodePush/SSZipArchive/aes/hmac.c +145 -0
  130. package/ios/CodePush/SSZipArchive/aes/hmac.h +103 -0
  131. package/ios/CodePush/SSZipArchive/aes/prng.c +155 -0
  132. package/ios/CodePush/SSZipArchive/aes/prng.h +82 -0
  133. package/ios/CodePush/SSZipArchive/aes/pwd2key.c +103 -0
  134. package/ios/CodePush/SSZipArchive/aes/pwd2key.h +57 -0
  135. package/ios/CodePush/SSZipArchive/aes/sha1.c +258 -0
  136. package/ios/CodePush/SSZipArchive/aes/sha1.h +73 -0
  137. package/ios/CodePush/SSZipArchive/minizip/crypt.h +130 -0
  138. package/ios/CodePush/SSZipArchive/minizip/ioapi.c +369 -0
  139. package/ios/CodePush/SSZipArchive/minizip/ioapi.h +175 -0
  140. package/ios/CodePush/SSZipArchive/minizip/mztools.c +284 -0
  141. package/ios/CodePush/SSZipArchive/minizip/mztools.h +31 -0
  142. package/ios/CodePush/SSZipArchive/minizip/unzip.c +1839 -0
  143. package/ios/CodePush/SSZipArchive/minizip/unzip.h +248 -0
  144. package/ios/CodePush/SSZipArchive/minizip/zip.c +1910 -0
  145. package/ios/CodePush/SSZipArchive/minizip/zip.h +202 -0
  146. package/ios/CodePush.xcodeproj/project.pbxproj +937 -0
  147. package/ios/CodePush.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  148. package/ios/CodePush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  149. package/logging.js +6 -0
  150. package/package-mixins.js +69 -0
  151. package/package.json +47 -0
  152. package/request-fetch-adapter.js +52 -0
  153. package/scripts/generateBundledResourcesHash.js +125 -0
  154. package/scripts/getFilesInFolder.js +19 -0
  155. package/scripts/postlink/android/postlink.js +87 -0
  156. package/scripts/postlink/ios/postlink.js +116 -0
  157. package/scripts/postlink/run.js +11 -0
  158. package/scripts/postunlink/android/postunlink.js +74 -0
  159. package/scripts/postunlink/ios/postunlink.js +87 -0
  160. package/scripts/postunlink/run.js +11 -0
  161. package/scripts/recordFilesBeforeBundleCommand.js +41 -0
  162. package/scripts/tools/linkToolsAndroid.js +57 -0
  163. package/scripts/tools/linkToolsIos.js +130 -0
  164. package/typings/react-native-code-push.d.ts +446 -0
  165. package/windows/CodePush/CodePush.csproj +128 -0
  166. package/windows/CodePush/CodePushUtils.cs +47 -0
  167. package/windows/CodePush/FileUtils.cs +40 -0
  168. package/windows/CodePush/Properties/AssemblyInfo.cs +29 -0
  169. package/windows/CodePush/Properties/CodePush.rd.xml +33 -0
  170. package/windows/CodePush/UpdateManager.cs +305 -0
  171. package/windows/CodePush/UpdateUtils.cs +46 -0
  172. package/windows/CodePush.Net46/Adapters/Http/HttpProgress.cs +28 -0
  173. package/windows/CodePush.Net46/Adapters/Storage/ApplicationDataContainer.cs +106 -0
  174. package/windows/CodePush.Net46/CodePush.Net46.csproj +103 -0
  175. package/windows/CodePush.Net46/CodePushUtils.cs +158 -0
  176. package/windows/CodePush.Net46/FileUtils.cs +55 -0
  177. package/windows/CodePush.Net46/Properties/AssemblyInfo.cs +36 -0
  178. package/windows/CodePush.Net46/UpdateManager.cs +330 -0
  179. package/windows/CodePush.Net46/UpdateUtils.cs +70 -0
  180. package/windows/CodePush.Net46/packages.config +5 -0
  181. package/windows/CodePush.Shared/CodePush.Shared.projitems +22 -0
  182. package/windows/CodePush.Shared/CodePush.Shared.shproj +13 -0
  183. package/windows/CodePush.Shared/CodePushConstants.cs +35 -0
  184. package/windows/CodePush.Shared/CodePushNativeModule.cs +329 -0
  185. package/windows/CodePush.Shared/CodePushReactPackage.cs +235 -0
  186. package/windows/CodePush.Shared/CodePushUtils.cs +70 -0
  187. package/windows/CodePush.Shared/InstallMode.cs +9 -0
  188. package/windows/CodePush.Shared/MinimumBackgroundListener.cs +44 -0
  189. package/windows/CodePush.Shared/SettingsManager.cs +148 -0
  190. package/windows/CodePush.Shared/TelemetryManager.cs +250 -0
  191. package/windows/CodePush.Shared/UpdateState.cs +9 -0
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "self:">
6
+ </FileRef>
7
+ </Workspace>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>IDEDidComputeMac32BitWarning</key>
6
+ <true/>
7
+ </dict>
8
+ </plist>
package/logging.js ADDED
@@ -0,0 +1,6 @@
1
+ /* Logs messages to console with the [CodePush] prefix */
2
+ function log(message) {
3
+ console.log(`[CodePush] ${message}`);
4
+ }
5
+
6
+ module.exports = log;
@@ -0,0 +1,69 @@
1
+ import { NativeEventEmitter } from "react-native";
2
+ import RestartManager from "./RestartManager";
3
+ import log from "./logging";
4
+
5
+ // This function is used to augment remote and local
6
+ // package objects with additional functionality/properties
7
+ // beyond what is included in the metadata sent by the server.
8
+ module.exports = (NativeCodePush) => {
9
+ const remote = (reportStatusDownload) => {
10
+ return {
11
+ async download(downloadProgressCallback) {
12
+ if (!this.downloadUrl) {
13
+ throw new Error("Cannot download an update without a download url");
14
+ }
15
+
16
+ let downloadProgressSubscription;
17
+ if (downloadProgressCallback) {
18
+ const codePushEventEmitter = new NativeEventEmitter(NativeCodePush);
19
+ // Use event subscription to obtain download progress.
20
+ downloadProgressSubscription = codePushEventEmitter.addListener(
21
+ "CodePushDownloadProgress",
22
+ downloadProgressCallback
23
+ );
24
+ }
25
+
26
+ // Use the downloaded package info. Native code will save the package info
27
+ // so that the client knows what the current package version is.
28
+ try {
29
+ const updatePackageCopy = Object.assign({}, this);
30
+ Object.keys(updatePackageCopy).forEach((key) => (typeof updatePackageCopy[key] === 'function') && delete updatePackageCopy[key]);
31
+
32
+ const downloadedPackage = await NativeCodePush.downloadUpdate(updatePackageCopy, !!downloadProgressCallback);
33
+
34
+ if (reportStatusDownload) {
35
+ reportStatusDownload(this)
36
+ .catch((err) => {
37
+ log(`Report download status failed: ${err}`);
38
+ });
39
+ }
40
+
41
+ return { ...downloadedPackage, ...local };
42
+ } finally {
43
+ downloadProgressSubscription && downloadProgressSubscription.remove();
44
+ }
45
+ },
46
+
47
+ isPending: false // A remote package could never be in a pending state
48
+ };
49
+ };
50
+
51
+ const local = {
52
+ async install(installMode = NativeCodePush.codePushInstallModeOnNextRestart, minimumBackgroundDuration = 0, updateInstalledCallback) {
53
+ const localPackage = this;
54
+ const localPackageCopy = Object.assign({}, localPackage); // In dev mode, React Native deep freezes any object queued over the bridge
55
+ await NativeCodePush.installUpdate(localPackageCopy, installMode, minimumBackgroundDuration);
56
+ updateInstalledCallback && updateInstalledCallback();
57
+ if (installMode == NativeCodePush.codePushInstallModeImmediate) {
58
+ RestartManager.restartApp(false);
59
+ } else {
60
+ RestartManager.clearPendingRestart();
61
+ localPackage.isPending = true; // Mark the package as pending since it hasn't been applied yet
62
+ }
63
+ },
64
+
65
+ isPending: false // A local package wouldn't be pending until it was installed
66
+ };
67
+
68
+ return { local, remote };
69
+ };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@appzung/react-native-code-push",
3
+ "version": "5.7.1",
4
+ "description": "React Native plugin for the CodePush service",
5
+ "main": "CodePush.js",
6
+ "typings": "typings/react-native-code-push.d.ts",
7
+ "author": "Louis Lagrange <lagrange.louis@gmail.com> (https://github.com/Minishlink)",
8
+ "license": "MIT",
9
+ "dependencies": {
10
+ "code-push": "^3.0.1",
11
+ "glob": "^5.0.15",
12
+ "hoist-non-react-statics": "^2.3.1",
13
+ "inquirer": "^1.1.2",
14
+ "plist": "3.0.1",
15
+ "semver": "^5.6.0",
16
+ "xcode": "1.0.0"
17
+ },
18
+ "devDependencies": {
19
+ "archiver": "latest",
20
+ "body-parser": "latest",
21
+ "code-push-plugin-testing-framework": "file:./code-push-plugin-testing-framework",
22
+ "del": "latest",
23
+ "express": "latest",
24
+ "gulp-insert": "latest",
25
+ "gulp-tslint": "latest",
26
+ "gulp-typescript": "^5.0.1",
27
+ "mkdirp": "latest",
28
+ "q": "^1.5.1",
29
+ "run-sequence": "latest",
30
+ "tslint": "^5.18.0",
31
+ "typescript": "^2.9.2"
32
+ },
33
+ "rnpm": {
34
+ "android": {
35
+ "packageInstance": "new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG)"
36
+ },
37
+ "ios": {
38
+ "sharedLibraries": [
39
+ "libz"
40
+ ]
41
+ },
42
+ "commands": {
43
+ "postlink": "node node_modules/react-native-code-push/scripts/postlink/run",
44
+ "postunlink": "node node_modules/react-native-code-push/scripts/postunlink/run"
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,52 @@
1
+ const packageJson = require("./package.json");
2
+
3
+ module.exports = {
4
+ async request(verb, url, requestBody, callback) {
5
+ if (typeof requestBody === "function") {
6
+ callback = requestBody;
7
+ requestBody = null;
8
+ }
9
+
10
+ const headers = {
11
+ "Accept": "application/json",
12
+ "Content-Type": "application/json",
13
+ "X-CodePush-Plugin-Name": packageJson.name,
14
+ "X-CodePush-Plugin-Version": packageJson.version,
15
+ "X-CodePush-SDK-Version": packageJson.dependencies["code-push"]
16
+ };
17
+
18
+ if (requestBody && typeof requestBody === "object") {
19
+ requestBody = JSON.stringify(requestBody);
20
+ }
21
+
22
+ try {
23
+ const response = await fetch(url, {
24
+ method: getHttpMethodName(verb),
25
+ headers: headers,
26
+ body: requestBody
27
+ });
28
+
29
+ const statusCode = response.status;
30
+ const body = await response.text();
31
+ callback(null, { statusCode, body });
32
+ } catch (err) {
33
+ callback(err);
34
+ }
35
+ }
36
+ };
37
+
38
+ function getHttpMethodName(verb) {
39
+ // Note: This should stay in sync with the enum definition in
40
+ // https://github.com/Microsoft/code-push/blob/master/sdk/script/acquisition-sdk.ts#L6
41
+ return [
42
+ "GET",
43
+ "HEAD",
44
+ "POST",
45
+ "PUT",
46
+ "DELETE",
47
+ "TRACE",
48
+ "OPTIONS",
49
+ "CONNECT",
50
+ "PATCH"
51
+ ][verb];
52
+ }
@@ -0,0 +1,125 @@
1
+ /*
2
+ * This script generates a hash of all the React Native bundled assets and writes it into
3
+ * into the APK. The hash in "updateCheck" requests to prevent downloading an identical
4
+ * update to the one already present in the binary.
5
+ *
6
+ * It first creates a snapshot of the contents in the resource directory by creating
7
+ * a map with the modified time of all the files in the directory. It then compares this
8
+ * snapshot with the one saved earlier in "recordFilesBeforeBundleCommand.js" to figure
9
+ * out which files were generated by the "react-native bundle" command. It then computes
10
+ * the hash for each file to generate a manifest, and then computes a hash over the entire
11
+ * manifest to generate the final hash, which is saved to the APK's assets directory.
12
+ */
13
+
14
+ var crypto = require("crypto");
15
+ var fs = require("fs");
16
+ var path = require("path");
17
+
18
+ var getFilesInFolder = require("./getFilesInFolder");
19
+
20
+ var CODE_PUSH_FOLDER_PREFIX = "CodePush";
21
+ var CODE_PUSH_HASH_FILE_NAME = "CodePushHash";
22
+ var CODE_PUSH_HASH_OLD_FILE_NAME = "CodePushHash.json";
23
+ var HASH_ALGORITHM = "sha256";
24
+
25
+ var resourcesDir = process.argv[2];
26
+ var jsBundleFilePath = process.argv[3];
27
+ var assetsDir = process.argv[4];
28
+ var tempFileName = process.argv[5];
29
+
30
+ var oldFileToModifiedTimeMap = {};
31
+ var tempFileLocalPath = null;
32
+ if (tempFileName) {
33
+ tempFileLocalPath = path.join(require("os").tmpdir(), tempFileName);
34
+ oldFileToModifiedTimeMap = require(tempFileLocalPath);
35
+ }
36
+ var resourceFiles = [];
37
+
38
+ getFilesInFolder(resourcesDir, resourceFiles);
39
+
40
+ var newFileToModifiedTimeMap = {};
41
+
42
+ resourceFiles.forEach(function(resourceFile) {
43
+ newFileToModifiedTimeMap[resourceFile.path.substring(resourcesDir.length)] = resourceFile.mtime;
44
+ });
45
+
46
+ var bundleGeneratedAssetFiles = [];
47
+
48
+ for (var newFilePath in newFileToModifiedTimeMap) {
49
+ if (!oldFileToModifiedTimeMap[newFilePath] || oldFileToModifiedTimeMap[newFilePath] < newFileToModifiedTimeMap[newFilePath].getTime()) {
50
+ bundleGeneratedAssetFiles.push(newFilePath);
51
+ }
52
+ }
53
+
54
+ var manifest = [];
55
+
56
+ if (bundleGeneratedAssetFiles.length) {
57
+ bundleGeneratedAssetFiles.forEach(function(assetFile) {
58
+ // Generate hash for each asset file
59
+ addFileToManifest(resourcesDir, assetFile, manifest, function() {
60
+ if (manifest.length === bundleGeneratedAssetFiles.length) {
61
+ addJsBundleAndMetaToManifest();
62
+ }
63
+ });
64
+ });
65
+ } else {
66
+ addJsBundleAndMetaToManifest();
67
+ }
68
+
69
+ function addJsBundleAndMetaToManifest() {
70
+ addFileToManifest(path.dirname(jsBundleFilePath), path.basename(jsBundleFilePath), manifest, function() {
71
+ var jsBundleMetaFilePath = jsBundleFilePath + ".meta";
72
+ addFileToManifest(path.dirname(jsBundleMetaFilePath), path.basename(jsBundleMetaFilePath), manifest, function() {
73
+ manifest = manifest.sort();
74
+ var finalHash = crypto.createHash(HASH_ALGORITHM)
75
+ .update(JSON.stringify(manifest))
76
+ .digest("hex");
77
+
78
+ console.log(finalHash);
79
+
80
+ var savedResourcesManifestPath = assetsDir + "/" + CODE_PUSH_HASH_FILE_NAME;
81
+ fs.writeFileSync(savedResourcesManifestPath, finalHash);
82
+
83
+ // "CodePushHash.json" file name breaks flow type checking.
84
+ // To fix the issue we need to delete "CodePushHash.json" file and
85
+ // use "CodePushHash" file name instead to store the hash value.
86
+ // Relates to https://github.com/Microsoft/react-native-code-push/issues/577
87
+ var oldSavedResourcesManifestPath = assetsDir + "/" + CODE_PUSH_HASH_OLD_FILE_NAME;
88
+ if (fs.existsSync(oldSavedResourcesManifestPath)) {
89
+ fs.unlinkSync(oldSavedResourcesManifestPath);
90
+ }
91
+ });
92
+ });
93
+ }
94
+
95
+ function addFileToManifest(folder, assetFile, manifest, done) {
96
+ var fullFilePath = path.join(folder, assetFile);
97
+ if (!fileExists(fullFilePath)) {
98
+ done();
99
+ return;
100
+ }
101
+
102
+ var readStream = fs.createReadStream(path.join(folder, assetFile));
103
+ var hashStream = crypto.createHash(HASH_ALGORITHM);
104
+
105
+ readStream.pipe(hashStream)
106
+ .on("error", function(error) {
107
+ throw error;
108
+ })
109
+ .on("finish", function() {
110
+ hashStream.end();
111
+ var buffer = hashStream.read();
112
+ var fileHash = buffer.toString("hex");
113
+ manifest.push(path.join(CODE_PUSH_FOLDER_PREFIX, assetFile).replace(/\\/g, "/") + ":" + fileHash);
114
+ done();
115
+ });
116
+ }
117
+
118
+ function fileExists(file) {
119
+ try { return fs.statSync(file).isFile(); }
120
+ catch (e) { return false; }
121
+ }
122
+
123
+ if (tempFileLocalPath) {
124
+ fs.unlinkSync(tempFileLocalPath);
125
+ }
@@ -0,0 +1,19 @@
1
+ var fs = require("fs");
2
+ var path = require("path");
3
+
4
+ // Utility function that collects the stats of every file in a directory
5
+ // as well as in its subdirectories.
6
+ function getFilesInFolder(folderName, fileList) {
7
+ var folderFiles = fs.readdirSync(folderName);
8
+ folderFiles.forEach(function(file) {
9
+ var fileStats = fs.statSync(path.join(folderName, file));
10
+ if (fileStats.isDirectory()) {
11
+ getFilesInFolder(path.join(folderName, file), fileList);
12
+ } else {
13
+ fileStats.path = path.join(folderName, file);
14
+ fileList.push(fileStats);
15
+ }
16
+ });
17
+ }
18
+
19
+ module.exports = getFilesInFolder;
@@ -0,0 +1,87 @@
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#plugin-configuration-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#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
+ }
@@ -0,0 +1,116 @@
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
+ }
@@ -0,0 +1,11 @@
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
+ });
@@ -0,0 +1,74 @@
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#plugin-configuration-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#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="reactNativeCodePush_androidDeploymentKey">.*<\/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
+ }