@algocare/react-native-code-push 9.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.
Files changed (190) hide show
  1. package/AlertAdapter.js +24 -0
  2. package/CONTRIBUTING.md +134 -0
  3. package/CodePush.js +778 -0
  4. package/CodePush.podspec +27 -0
  5. package/LICENSE.md +13 -0
  6. package/README.md +491 -0
  7. package/SECURITY.md +41 -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 +6 -0
  11. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +441 -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 +35 -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 +714 -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 +383 -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 +268 -0
  26. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java +238 -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 +203 -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/app/src/main/java/com/microsoft/codepush/react/TLSSocketFactory.java +72 -0
  33. package/android/build.gradle +21 -0
  34. package/android/codepush.gradle +162 -0
  35. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  36. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  37. package/android/gradle.properties +20 -0
  38. package/android/gradlew +164 -0
  39. package/android/gradlew.bat +90 -0
  40. package/android/settings.gradle +1 -0
  41. package/babel.config.js +3 -0
  42. package/cli/commands/bundleCommand/bundleCodePush.js +57 -0
  43. package/cli/commands/bundleCommand/index.js +29 -0
  44. package/cli/commands/createHistoryCommand/createReleaseHistory.js +53 -0
  45. package/cli/commands/createHistoryCommand/index.js +29 -0
  46. package/cli/commands/releaseCommand/addToReleaseHistory.js +75 -0
  47. package/cli/commands/releaseCommand/index.js +66 -0
  48. package/cli/commands/releaseCommand/release.js +109 -0
  49. package/cli/commands/showHistoryCommand/index.js +29 -0
  50. package/cli/commands/updateHistoryCommand/index.js +50 -0
  51. package/cli/commands/updateHistoryCommand/updateReleaseHistory.js +62 -0
  52. package/cli/constant.js +6 -0
  53. package/cli/functions/getReactTempDir.js +16 -0
  54. package/cli/functions/makeCodePushBundle.js +28 -0
  55. package/cli/functions/prepareToBundleJS.js +12 -0
  56. package/cli/functions/runHermesEmitBinaryCommand.js +213 -0
  57. package/cli/functions/runReactNativeBundleCommand.js +59 -0
  58. package/cli/index.js +43 -0
  59. package/cli/utils/file-utils.js +42 -0
  60. package/cli/utils/fsUtils.js +49 -0
  61. package/cli/utils/hash-utils.js +227 -0
  62. package/cli/utils/promisfied-fs.js +29 -0
  63. package/cli/utils/showLogo.js +23 -0
  64. package/cli/utils/zip.js +89 -0
  65. package/code-push.config.example.supabase.ts +114 -0
  66. package/docs/api-android.md +83 -0
  67. package/docs/api-ios.md +31 -0
  68. package/docs/api-js.md +592 -0
  69. package/docs/multi-deployment-testing-android.md +148 -0
  70. package/docs/multi-deployment-testing-ios.md +59 -0
  71. package/docs/setup-android.md +482 -0
  72. package/docs/setup-ios.md +280 -0
  73. package/eslint.config.mjs +32 -0
  74. package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +34 -0
  75. package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +252 -0
  76. package/ios/CodePush/Base64/README.md +47 -0
  77. package/ios/CodePush/CodePush.h +235 -0
  78. package/ios/CodePush/CodePush.m +1121 -0
  79. package/ios/CodePush/CodePushConfig.m +116 -0
  80. package/ios/CodePush/CodePushDownloadHandler.m +130 -0
  81. package/ios/CodePush/CodePushErrorUtils.m +20 -0
  82. package/ios/CodePush/CodePushPackage.m +602 -0
  83. package/ios/CodePush/CodePushTelemetryManager.m +175 -0
  84. package/ios/CodePush/CodePushUpdateUtils.m +376 -0
  85. package/ios/CodePush/CodePushUtils.m +9 -0
  86. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +69 -0
  87. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +16 -0
  88. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +51 -0
  89. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +15 -0
  90. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +55 -0
  91. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +24 -0
  92. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +41 -0
  93. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +28 -0
  94. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +205 -0
  95. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +103 -0
  96. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +322 -0
  97. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +37 -0
  98. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +145 -0
  99. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +35 -0
  100. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +551 -0
  101. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +23 -0
  102. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +43 -0
  103. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +230 -0
  104. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +31 -0
  105. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +113 -0
  106. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +38 -0
  107. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +500 -0
  108. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +18 -0
  109. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +214 -0
  110. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +23 -0
  111. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +29 -0
  112. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +19 -0
  113. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +68 -0
  114. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +18 -0
  115. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +72 -0
  116. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +67 -0
  117. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +111 -0
  118. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +119 -0
  119. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +307 -0
  120. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +94 -0
  121. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +619 -0
  122. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +164 -0
  123. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +514 -0
  124. package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +24 -0
  125. package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +11 -0
  126. package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +52 -0
  127. package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +5 -0
  128. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +28 -0
  129. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +70 -0
  130. package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +22 -0
  131. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +34 -0
  132. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +73 -0
  133. package/ios/CodePush/JWT/LICENSE +19 -0
  134. package/ios/CodePush/JWT/README.md +489 -0
  135. package/ios/CodePush/RCTConvert+CodePushInstallMode.m +20 -0
  136. package/ios/CodePush/RCTConvert+CodePushUpdateState.m +20 -0
  137. package/ios/CodePush/SSZipArchive/Common.h +81 -0
  138. package/ios/CodePush/SSZipArchive/README.md +1 -0
  139. package/ios/CodePush/SSZipArchive/SSZipArchive.h +76 -0
  140. package/ios/CodePush/SSZipArchive/SSZipArchive.m +691 -0
  141. package/ios/CodePush/SSZipArchive/aes/aes.h +198 -0
  142. package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +541 -0
  143. package/ios/CodePush/SSZipArchive/aes/aescrypt.c +294 -0
  144. package/ios/CodePush/SSZipArchive/aes/aeskey.c +548 -0
  145. package/ios/CodePush/SSZipArchive/aes/aesopt.h +739 -0
  146. package/ios/CodePush/SSZipArchive/aes/aestab.c +391 -0
  147. package/ios/CodePush/SSZipArchive/aes/aestab.h +173 -0
  148. package/ios/CodePush/SSZipArchive/aes/brg_endian.h +126 -0
  149. package/ios/CodePush/SSZipArchive/aes/brg_types.h +219 -0
  150. package/ios/CodePush/SSZipArchive/aes/entropy.c +54 -0
  151. package/ios/CodePush/SSZipArchive/aes/entropy.h +16 -0
  152. package/ios/CodePush/SSZipArchive/aes/fileenc.c +144 -0
  153. package/ios/CodePush/SSZipArchive/aes/fileenc.h +121 -0
  154. package/ios/CodePush/SSZipArchive/aes/hmac.c +145 -0
  155. package/ios/CodePush/SSZipArchive/aes/hmac.h +103 -0
  156. package/ios/CodePush/SSZipArchive/aes/prng.c +155 -0
  157. package/ios/CodePush/SSZipArchive/aes/prng.h +82 -0
  158. package/ios/CodePush/SSZipArchive/aes/pwd2key.c +103 -0
  159. package/ios/CodePush/SSZipArchive/aes/pwd2key.h +57 -0
  160. package/ios/CodePush/SSZipArchive/aes/sha1.c +258 -0
  161. package/ios/CodePush/SSZipArchive/aes/sha1.h +73 -0
  162. package/ios/CodePush/SSZipArchive/minizip/crypt.h +130 -0
  163. package/ios/CodePush/SSZipArchive/minizip/ioapi.c +369 -0
  164. package/ios/CodePush/SSZipArchive/minizip/ioapi.h +175 -0
  165. package/ios/CodePush/SSZipArchive/minizip/mztools.c +284 -0
  166. package/ios/CodePush/SSZipArchive/minizip/mztools.h +31 -0
  167. package/ios/CodePush/SSZipArchive/minizip/unzip.c +1839 -0
  168. package/ios/CodePush/SSZipArchive/minizip/unzip.h +248 -0
  169. package/ios/CodePush/SSZipArchive/minizip/zip.c +1910 -0
  170. package/ios/CodePush/SSZipArchive/minizip/zip.h +202 -0
  171. package/ios/CodePush.xcodeproj/project.pbxproj +937 -0
  172. package/ios/CodePush.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  173. package/ios/CodePush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  174. package/logging.js +6 -0
  175. package/package-mixins.js +61 -0
  176. package/package.json +84 -0
  177. package/react-native.config.js +12 -0
  178. package/scripts/generateBundledResourcesHash.js +125 -0
  179. package/scripts/getFilesInFolder.js +19 -0
  180. package/scripts/recordFilesBeforeBundleCommand.js +41 -0
  181. package/tsconfig.json +14 -0
  182. package/tslint.json +32 -0
  183. package/typings/react-native-code-push.d.ts +589 -0
  184. package/versioning/BaseVersioning.js +126 -0
  185. package/versioning/BaseVersioning.test.js +15 -0
  186. package/versioning/IncrementalVersioning.js +9 -0
  187. package/versioning/IncrementalVersioning.test.js +186 -0
  188. package/versioning/SemverVersioning.js +10 -0
  189. package/versioning/SemverVersioning.test.js +205 -0
  190. package/versioning/index.js +7 -0
@@ -0,0 +1,227 @@
1
+ /**
2
+ * code based on appcenter-cli
3
+ */
4
+
5
+ /**
6
+ * NOTE!!! This utility file is duplicated for use by the CodePush service (for server-driven hashing/
7
+ * integrity checks) and Management SDK (for end-to-end code signing), please keep them in sync.
8
+ */
9
+
10
+ const crypto = require('crypto');
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+ const { isDirectory } = require('./file-utils');
14
+ const { walk } = require('./promisfied-fs');
15
+
16
+ // Do not throw an exception if either of these modules are missing, as they may not be needed by the
17
+ // consumer of this file.
18
+ const HASH_ALGORITHM = 'sha256';
19
+ class PackageManifest {
20
+ /**
21
+ * @type {Map<string, string>}
22
+ * @private
23
+ */
24
+ _map;
25
+
26
+ /**
27
+ * @param map {Map<string, string>?}
28
+ * @public
29
+ */
30
+ constructor(map) {
31
+ if (map == null) {
32
+ map = new Map();
33
+ }
34
+ this._map = map;
35
+ }
36
+
37
+ /**
38
+ * @return {Map<string, string>}
39
+ * @public
40
+ */
41
+ toMap() {
42
+ return this._map;
43
+ }
44
+
45
+ /**
46
+ * @return {string}
47
+ * @public
48
+ */
49
+ computePackageHash() {
50
+ /**
51
+ * @type {string[]}
52
+ */
53
+ let entries = [];
54
+ this._map.forEach((hash, name) => {
55
+ entries.push(name + ':' + hash);
56
+ });
57
+
58
+ // Make sure this list is alphabetically ordered so that other clients
59
+ // can also compute this hash easily given the update contents.
60
+ entries = entries.sort();
61
+
62
+ return crypto.createHash(HASH_ALGORITHM).update(JSON.stringify(entries)).digest('hex');
63
+ }
64
+
65
+ /**
66
+ * @return {string}
67
+ * @public
68
+ */
69
+ serialize() {
70
+ const obj = {};
71
+
72
+ this._map.forEach(function (value, key) {
73
+ obj[key] = value;
74
+ });
75
+
76
+ return JSON.stringify(obj);
77
+ }
78
+
79
+ /**
80
+ * @param filePath {string}
81
+ * @return {string}
82
+ * @public
83
+ */
84
+ static normalizePath(filePath) {
85
+ //replace all backslashes coming from cli running on windows machines by slashes
86
+ return filePath.replace(/\\/g, '/');
87
+ }
88
+
89
+ /**
90
+ * @param relativeFilePath {string}
91
+ * @return {boolean}
92
+ * @public
93
+ */
94
+ static isIgnored(relativeFilePath) {
95
+ const __MACOSX = '__MACOSX/';
96
+ const DS_STORE = '.DS_Store';
97
+ const CODEPUSH_METADATA = '.codepushrelease';
98
+ return (
99
+ relativeFilePath.startsWith(__MACOSX) ||
100
+ relativeFilePath === DS_STORE ||
101
+ relativeFilePath.endsWith('/' + DS_STORE) ||
102
+ relativeFilePath === CODEPUSH_METADATA ||
103
+ relativeFilePath.endsWith('/' + CODEPUSH_METADATA)
104
+ );
105
+ }
106
+ }
107
+
108
+ /**
109
+ *
110
+ * @param directoryPath {string}
111
+ * @param basePath {string}
112
+ * @return {Promise<string>}
113
+ */
114
+ async function generatePackageHashFromDirectory(directoryPath, basePath) {
115
+ try {
116
+ if (!isDirectory(directoryPath)) {
117
+ throw new Error('Not a directory. Please either create a directory, or use hashFile().');
118
+ }
119
+ } catch (error) {
120
+ throw new Error('Directory does not exist. Please either create a directory, or use hashFile().');
121
+ }
122
+
123
+ /**
124
+ * @type {PackageManifest}
125
+ */
126
+ const manifest = await generatePackageManifestFromDirectory(directoryPath, basePath);
127
+ return manifest.computePackageHash();
128
+ }
129
+
130
+ /**
131
+ *
132
+ * @param directoryPath {string}
133
+ * @param basePath {string}
134
+ * @return {Promise<PackageManifest>}
135
+ */
136
+ function generatePackageManifestFromDirectory(directoryPath, basePath) {
137
+ // eslint-disable-next-line no-async-promise-executor
138
+ return new Promise(async (resolve, reject) => {
139
+ /**
140
+ * @type {Map<string, string>}
141
+ */
142
+ const fileHashesMap = new Map();
143
+
144
+ /**
145
+ * @type {string[]}
146
+ */
147
+ const files = await walk(directoryPath);
148
+
149
+ if (!files || files.length === 0) {
150
+ reject('Error: Cannot sign the release because no files were found.');
151
+ return;
152
+ }
153
+
154
+ /**
155
+ * @type {Promise<void>}
156
+ */
157
+ // Hash the files sequentially, because streaming them in parallel is not necessarily faster
158
+ const generateManifestPromise = files.reduce((soFar, filePath) => {
159
+ return soFar.then(() => {
160
+ /**
161
+ * @type {string}
162
+ */
163
+ const relativePath = PackageManifest.normalizePath(path.relative(basePath, filePath));
164
+ if (!PackageManifest.isIgnored(relativePath)) {
165
+ return hashFile(filePath).then((hash) => {
166
+ fileHashesMap.set(relativePath, hash);
167
+ });
168
+ }
169
+ });
170
+ }, Promise.resolve(null));
171
+
172
+ generateManifestPromise.then(() => {
173
+ resolve(new PackageManifest(fileHashesMap));
174
+ }, reject);
175
+ });
176
+ }
177
+
178
+ /**
179
+ *
180
+ * @param filePath {string}
181
+ * @return {Promise<string>}
182
+ */
183
+ function hashFile(filePath) {
184
+ /**
185
+ * @type {fs.ReadStream}
186
+ */
187
+ const readStream = fs.createReadStream(filePath);
188
+ return hashStream(readStream);
189
+ }
190
+
191
+ /**
192
+ *
193
+ * @param readStream {stream.Readable}
194
+ * @return {Promise<string>}
195
+ */
196
+ function hashStream(readStream) {
197
+ return new Promise((resolve, reject) => {
198
+ /**
199
+ * @type {stream.Transform}
200
+ */
201
+ const _hashStream = crypto.createHash(HASH_ALGORITHM)
202
+
203
+ readStream
204
+ .on('error', (error) => {
205
+ _hashStream.end();
206
+ reject(error);
207
+ })
208
+ .on('end', () => {
209
+ _hashStream.end();
210
+
211
+ /**
212
+ * @type {Buffer}
213
+ */
214
+ const buffer = _hashStream.read();
215
+ /**
216
+ * @type {string}
217
+ */
218
+ const hash = buffer.toString('hex');
219
+
220
+ resolve(hash);
221
+ });
222
+
223
+ readStream.pipe(_hashStream);
224
+ });
225
+ }
226
+
227
+ module.exports = { generatePackageHashFromDirectory };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * code based on appcenter-cli
3
+ */
4
+
5
+ const { promises: fs } = require('fs');
6
+ const path = require('path');
7
+
8
+ /**
9
+ *
10
+ * @param dir {string}
11
+ * @return {Promise<string[]>}
12
+ */
13
+ async function walk(dir) {
14
+ const stats = await fs.stat(dir);
15
+ if (stats.isDirectory()) {
16
+ /**
17
+ * @type {string[]}
18
+ */
19
+ let files = [];
20
+ for (const file of await fs.readdir(dir)) {
21
+ files = files.concat(await walk(path.join(dir, file)));
22
+ }
23
+ return files;
24
+ } else {
25
+ return [dir];
26
+ }
27
+ }
28
+
29
+ module.exports = { walk };
@@ -0,0 +1,23 @@
1
+ function showLogo() {
2
+ const logo = `
3
+
4
+ +------------------------------------------------------------------+
5
+ | |
6
+ | ______ __ ____ __ |
7
+ | / ____/___ ____/ /__ / __ \\__ _______/ /_ |
8
+ | / / / __ \\/ __ / _ \\/ /_/ / / / / ___/ __ \\ |
9
+ | / /___/ /_/ / /_/ / __/ ____/ /_/ (__ ) / / / |
10
+ | \\____/\\____/\\__,_/\\___/_/ \\__,_/____/_/ /_/ |
11
+ | |
12
+ | |
13
+ | 🚀 @algocare/react-native-code-push |
14
+ +------------------------------------------------------------------+
15
+
16
+ Please refer to help command for more information.
17
+
18
+ (interactive mode is not supported yet.)
19
+ `
20
+ console.log(logo)
21
+ }
22
+
23
+ module.exports = { showLogo }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * code based on appcenter-cli
3
+ */
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const yazl = require('yazl');
8
+ const { generateRandomFilename, normalizePath, isDirectory } = require('./file-utils');
9
+ const { walk } = require('./promisfied-fs');
10
+
11
+ /**
12
+ * @typedef {{ sourceLocation: string, targetLocation: string }} ReleaseFile
13
+ */
14
+
15
+ /**
16
+ * @param updateContentsPath {string}
17
+ * @return {Promise<string>}
18
+ */
19
+ function zip(updateContentsPath) {
20
+
21
+ // eslint-disable-next-line no-async-promise-executor
22
+ return new Promise(async (resolve, reject) => {
23
+ /**
24
+ * @type {ReleaseFile[]}
25
+ */
26
+ const releaseFiles = [];
27
+
28
+ try {
29
+ if (!isDirectory(updateContentsPath)) {
30
+ releaseFiles.push({
31
+ sourceLocation: updateContentsPath,
32
+ targetLocation: normalizePath(path.basename(updateContentsPath)), // Put the file in the root
33
+ });
34
+ }
35
+ } catch (error) {
36
+ error.message = error.message + ' Make sure you have added the platform you are making a release to.`.';
37
+ reject(error);
38
+ }
39
+
40
+ /**
41
+ * @type {string}
42
+ */
43
+ const directoryPath = updateContentsPath;
44
+ const baseDirectoryPath = path.join(directoryPath, '..'); // For legacy reasons, put the root directory in the zip
45
+
46
+ /**
47
+ * @type {string[]}
48
+ */
49
+ const files = await walk(updateContentsPath);
50
+
51
+ files.forEach((filePath) => {
52
+ /**
53
+ * @type {string}
54
+ */
55
+ const relativePath = path.relative(baseDirectoryPath, filePath);
56
+ releaseFiles.push({
57
+ sourceLocation: filePath,
58
+ targetLocation: normalizePath(relativePath),
59
+ });
60
+ });
61
+
62
+ /**
63
+ * @type {string}
64
+ */
65
+ const packagePath = path.join(process.cwd(), generateRandomFilename(15) + '.zip');
66
+ const zipFile = new yazl.ZipFile();
67
+ /**
68
+ * @type {fs.WriteStream}
69
+ */
70
+ const writeStream = fs.createWriteStream(packagePath);
71
+
72
+ zipFile.outputStream
73
+ .pipe(writeStream)
74
+ .on('error', (error) => {
75
+ reject(error);
76
+ })
77
+ .on('close', () => {
78
+ resolve(packagePath);
79
+ });
80
+
81
+ releaseFiles.forEach((releaseFile) => {
82
+ zipFile.addFile(releaseFile.sourceLocation, releaseFile.targetLocation);
83
+ });
84
+
85
+ zipFile.end();
86
+ });
87
+ }
88
+
89
+ module.exports = zip;
@@ -0,0 +1,114 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-nocheck
3
+
4
+ import {
5
+ CliConfigInterface,
6
+ ReleaseHistoryInterface,
7
+ } from '@algocare/react-native-code-push'
8
+ import * as fs from 'fs'
9
+ import axios from 'axios' // install as devDependency
10
+ import * as SupabaseSDK from '@supabase/supabase-js' // install as devDependency
11
+
12
+ const SUPABASE_URL = process.env.SUPABASE_URL
13
+ const SUPABASE_KEY = process.env.SUPABASE_KEY
14
+ const supabase = SupabaseSDK.createClient(SUPABASE_URL!, SUPABASE_KEY!)
15
+ const BUCKET_NAME = 'codePush'
16
+ const STORAGE_HOST = `${SUPABASE_URL}/storage/v1/object/public`
17
+
18
+ function historyJsonFileRemotePath(
19
+ platform: 'ios' | 'android',
20
+ identifier: string,
21
+ binaryVersion: string
22
+ ) {
23
+ return `histories/${platform}/${identifier}/${binaryVersion}.json`
24
+ }
25
+
26
+ function bundleFileRemotePath(
27
+ platform: 'ios' | 'android',
28
+ identifier: string,
29
+ fileName: string
30
+ ) {
31
+ return `bundles/${platform}/${identifier}/${fileName}`
32
+ }
33
+
34
+ const Config: CliConfigInterface = {
35
+ bundleUploader: async (
36
+ source: string,
37
+ platform: 'ios' | 'android',
38
+ identifier = 'staging'
39
+ ): Promise<{ downloadUrl: string }> => {
40
+ const fileName = source.split('/').pop()
41
+ const fileStream = fs.createReadStream(source)
42
+ const remotePath = bundleFileRemotePath(platform, identifier, fileName!)
43
+
44
+ const { data, error } = await supabase.storage
45
+ .from(BUCKET_NAME)
46
+ .upload(remotePath, fileStream, {
47
+ contentType: 'application/zip',
48
+ duplex: 'half',
49
+ })
50
+
51
+ if (error) {
52
+ console.error('Error uploading file:', error.message)
53
+ throw error
54
+ }
55
+
56
+ console.log('Bundle File uploaded:', `${STORAGE_HOST}/${data.fullPath}`)
57
+
58
+ return {
59
+ downloadUrl: `${STORAGE_HOST}/${data.fullPath}`,
60
+ }
61
+ },
62
+
63
+ getReleaseHistory: async (
64
+ targetBinaryVersion: string,
65
+ platform: 'ios' | 'android',
66
+ identifier = 'staging'
67
+ ): Promise<ReleaseHistoryInterface> => {
68
+ const remoteJsonPath = historyJsonFileRemotePath(
69
+ platform,
70
+ identifier,
71
+ targetBinaryVersion
72
+ )
73
+ const { data } = await axios.get(
74
+ `${STORAGE_HOST}/${BUCKET_NAME}/${remoteJsonPath}`
75
+ )
76
+ return data as ReleaseHistoryInterface
77
+ },
78
+
79
+ setReleaseHistory: async (
80
+ targetBinaryVersion: string,
81
+ jsonFilePath: string,
82
+ releaseInfo: ReleaseHistoryInterface,
83
+ platform: 'ios' | 'android',
84
+ identifier = 'staging'
85
+ ): Promise<void> => {
86
+ // upload JSON file or call API using `releaseInfo` metadata.
87
+
88
+ const fileContent = fs.readFileSync(jsonFilePath, 'utf8')
89
+ const remoteJsonPath = historyJsonFileRemotePath(
90
+ platform,
91
+ identifier,
92
+ targetBinaryVersion
93
+ )
94
+
95
+ const { data, error } = await supabase.storage
96
+ .from(BUCKET_NAME)
97
+ .upload(remoteJsonPath, Buffer.from(fileContent), {
98
+ contentType: 'application/json',
99
+ cacheControl: '5',
100
+ })
101
+
102
+ if (error) {
103
+ console.error('Error uploading file:', error.message)
104
+ throw error
105
+ }
106
+
107
+ console.log(
108
+ 'Release history File uploaded:',
109
+ `${STORAGE_HOST}/${data.fullPath}`
110
+ )
111
+ },
112
+ }
113
+
114
+ module.exports = Config
@@ -0,0 +1,83 @@
1
+ ### Java API Reference (Android)
2
+
3
+ ### API for React Native 0.60 version and above
4
+
5
+ Since `autolinking` uses `react-native.config.js` to link plugins, constructors are specified in that file. But you can override custom variables to manage the CodePush plugin by placing these values in string resources.
6
+
7
+ * __Public Key__ - used for bundle verification in the Code Signing Feature. Please refer to [Code Signing](setup-android.md#code-signing-setup) section for more details about the Code Signing Feature.
8
+ To set the public key, you should add the content of the public key to `strings.xml` with name `CodePushPublicKey`. CodePush automatically gets this property and enables the Code Signing feature. For example:
9
+ ```xml
10
+ <string moduleConfig="true" name="CodePushPublicKey">your-public-key</string>
11
+ ```
12
+
13
+ * __Server Url__ - used for specifying CodePush Server Url.
14
+ The Default value: "https://codepush.appcenter.ms/" is overridden by adding your path to `strings.xml` with name `CodePushServerUrl`. CodePush automatically gets this property and will use this path to send requests. For example:
15
+ ```xml
16
+ <string moduleConfig="true" name="CodePushServerUrl">https://yourcodepush.server.com</string>
17
+ ```
18
+
19
+ ### API for React Native lower than 0.60
20
+
21
+ The Java API is made available by importing the `com.microsoft.codepush.react.CodePush` class into your `MainActivity.java` file, and consists of a single public class named `CodePush`.
22
+
23
+ #### CodePush
24
+
25
+ Constructs the CodePush client runtime and represents the `ReactPackage` instance that you add to you app's list of packages.
26
+
27
+ ##### Constructors
28
+
29
+ - __CodePush(String deploymentKey, Activity mainActivity)__ - Creates a new instance of the CodePush runtime, that will be used to query the service for updates via the provided deployment key. The `mainActivity` parameter should always be set to `this` when configuring your React packages list inside the `MainActivity` class. This constructor puts the CodePush runtime into "release mode", so if you want to enable debugging behavior, use the following constructor instead.
30
+
31
+ - __CodePush(String deploymentKey, Activity mainActivity, bool isDebugMode)__ - Equivalent to the previous constructor but allows you to specify whether you want the CodePush runtime to be in debug mode or not. When using this constructor, the `isDebugMode` parameter should always be set to `BuildConfig.DEBUG` in order to stay synchronized with your build type. When putting CodePush into debug mode, the following behaviors are enabled:
32
+
33
+ 1. Old CodePush updates aren't deleted from storage whenever a new binary is deployed to the emulator/device. This behavior enables you to deploy new binaries, without bumping the version during development, and without continuously getting the same update every time your app calls `sync`.
34
+
35
+ 2. The local cache that the React Native runtime maintains in debug mode is deleted whenever a CodePush update is installed. This ensures that when the app is restarted after an update is applied, you will see the expected changes. As soon as [this PR](https://github.com/facebook/react-native/pull/4738) is merged, we won't need to do this anymore.
36
+
37
+ - __CodePush(String deploymentKey, Context context, boolean isDebugMode, Integer publicKeyResourceDescriptor)__ - Equivalent to the previous constructor, but allows you to specify the public key resource descriptor needed to read public key content. Please refer to [Code Signing](setup-android.md#code-signing-setup) section for more details about the Code Signing Feature.
38
+
39
+ - __CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl)__ Constructor allows you to specify CodePush Server Url. The Default value: `"https://codepush.appcenter.ms/"` is overridden by value specified in `serverUrl`.
40
+
41
+ ##### Builder
42
+
43
+ As an alternative to constructors *you can also use `CodePushBuilder`* to setup a CodePush instance configured with *only parameters you want*.
44
+
45
+ ```java
46
+ @Override
47
+ protected List<ReactPackage> getPackages() {
48
+ return Arrays.<ReactPackage>asList(
49
+ new MainReactPackage(),
50
+ new CodePushBuilder("deployment-key-here",getApplicationContext())
51
+ .setIsDebugMode(BuildConfig.DEBUG)
52
+ .setPublicKeyResourceDescriptor(R.string.publicKey)
53
+ .setServerUrl("https://yourcodepush.server.com")
54
+ .build() //return configured CodePush instance
55
+ );
56
+ }
57
+ ```
58
+
59
+ `CodePushBuilder` methods:
60
+
61
+ * __public CodePushBuilder(String deploymentKey, Context context)__ - setup same parameters as via __CodePush(String deploymentKey, Activity mainActivity)__
62
+
63
+ * __public CodePushBuilder setIsDebugMode(boolean isDebugMode)__ - allows you to specify whether you want the CodePush runtime to be in debug mode or not. Default value: `false`.
64
+
65
+ * __public CodePushBuilder setServerUrl(String serverUrl)__ - allows you to specify CodePush Server Url. Default value: `"https://codepush.appcenter.ms/"`.
66
+
67
+ * __public CodePushBuilder setPublicKeyResourceDescriptor(int publicKeyResourceDescriptor)__ - allows you to specify Public Key resource descriptor which will be used for reading Public Key content for `strings.xml` file. Please refer to [Code Signing](setup-android.md#code-signing-setup) section for more detailed information about purpose of this parameter.
68
+
69
+ * __public CodePush build()__ - return configured `CodePush` instance.
70
+
71
+ ##### Public Methods
72
+
73
+ - __setDeploymentKey(String deploymentKey)__ - Sets the deployment key that the app should use when querying for updates. This is a dynamic alternative to setting the deployment key in Codepush constructor/builder and/or specifying a deployment key in JS when calling `checkForUpdate` or `sync`.
74
+
75
+ ##### Static Methods
76
+
77
+ - __getBundleUrl()__ - Returns the path to the most recent version of your app's JS bundle file, assuming that the resource name is `index.android.bundle`. If your app is using a different bundle name, then use the overloaded version of this method which allows specifying it. This method has the same resolution behavior as the Objective-C equivalent described above.
78
+
79
+ - __getBundleUrl(String bundleName)__ - Returns the path to the most recent version of your app's JS bundle file, using the specified resource name (like `index.android.bundle`). This method has the same resolution behavior as the Objective-C equivalent described above.
80
+
81
+ - __getPackageFolder()__ - Returns the path to the current update folder.
82
+
83
+ - __overrideAppVersion(String appVersionOverride)__ - Sets the version of the application's binary interface, which would otherwise default to the Play Store version specified as the `versionName` in the `build.gradle`. This should be called a single time, before the CodePush instance is constructed.
@@ -0,0 +1,31 @@
1
+ ### Objective-C API Reference (iOS)
2
+
3
+ The Objective-C API is made available by importing the `CodePush.h` header into your `AppDelegate.m` file, and consists of a single public class named `CodePush`.
4
+
5
+ #### CodePush
6
+
7
+ Contains static methods for retreiving the `NSURL` that represents the most recent JavaScript bundle file, and can be passed to the `RCTRootView`'s `initWithBundleURL` method when bootstrapping your app in the `AppDelegate.m` file.
8
+
9
+ The `CodePush` class' methods can be thought of as composite resolvers which always load the appropriate bundle, in order to accommodate the following scenarios:
10
+
11
+ 1. When an end-user installs your app from the store (like `1.0.0`), they will get the JS bundle that is contained within the binary. This is the behavior you would get without using CodePush, but we make sure it doesn't break :)
12
+
13
+ 2. As soon as you begin releasing CodePush updates, your end-users will get the JS bundle that represents the latest release for the configured deployment. This is the behavior that allows you to iterate beyond what you shipped to the store.
14
+
15
+ 3. As soon as you release an update to the app store (like `1.1.0`), and your end-users update it, they will once again get the JS bundle that is contained within the binary. This behavior ensures that CodePush updates that targetted a previous binary version aren't used (since we don't know if they would work), and your end-users always have a working version of your app.
16
+
17
+ 4. Repeat #2 and #3 as the CodePush releases and app store releases continue on into infinity (and beyond?)
18
+
19
+ Because of this behavior, you can safely deploy updates to both the app store(s) and CodePush as necesary, and rest assured that your end-users will always get the most recent version.
20
+
21
+ ##### Methods
22
+
23
+ - __(NSURL \*)bundleURL__ - Returns the most recent JS bundle `NSURL` as described above. This method assumes that the name of the JS bundle contained within your app binary is `main.jsbundle`.
24
+
25
+ - __(NSURL \*)bundleURLForResource:(NSString \*)resourceName__ - Equivalent to the `bundleURL` method, but also allows customizing the name of the JS bundle that is looked for within the app binary. This is useful if you aren't naming this file `main` (which is the default convention). This method assumes that the JS bundle's extension is `*.jsbundle`.
26
+
27
+ - __(NSURL \*)bundleURLForResource:(NSString \*)resourceName withExtension:(NSString \*)resourceExtension__: Equivalent to the `bundleURLForResource:` method, but also allows customizing the extension used by the JS bundle that is looked for within the app binary. This is useful if you aren't naming this file `*.jsbundle` (which is the default convention).
28
+
29
+ - __(void)overrideAppVersion:(NSString \*)appVersionOverride__ - Sets the version of the application's binary interface, which would otherwise default to the App Store version specified as the `CFBundleShortVersionString` in the `Info.plist`. This should be called a single time, before the bundle URL is loaded.
30
+
31
+ - __(void)setDeploymentKey:(NSString \*)deploymentKey__ - Sets the deployment key that the app should use when querying for updates. This is a dynamic alternative to setting the deployment key in your `Info.plist` and/or specifying a deployment key in JS when calling `checkForUpdate` or `sync`.