@algocare/react-native-code-push 12.6.3 → 13.0.0-rc.0

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 (292) hide show
  1. package/CodePush.podspec +6 -8
  2. package/README.md +343 -586
  3. package/android/app/build.gradle +2 -1
  4. package/android/app/proguard-rules.pro +14 -0
  5. package/android/app/src/debug/AndroidManifest.xml +9 -0
  6. package/android/app/src/main/AndroidManifest.xml +1 -2
  7. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +14 -139
  8. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +0 -3
  9. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +108 -63
  10. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +2 -33
  11. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +13 -109
  12. package/android/build.gradle +3 -0
  13. package/app.plugin.js +1 -0
  14. package/bin/code-push.js +6 -0
  15. package/cli/commands/bundleCommand/bundleCodePush.ts +118 -0
  16. package/cli/commands/bundleCommand/index.ts +34 -0
  17. package/cli/commands/createHistoryCommand/createReleaseHistory.ts +37 -0
  18. package/cli/commands/createHistoryCommand/createReleaseHistoryList.ts +40 -0
  19. package/cli/commands/createHistoryCommand/index.ts +44 -0
  20. package/cli/commands/createPullRequestHistoryCommand/createPullRequestHistory.ts +33 -0
  21. package/cli/commands/createPullRequestHistoryCommand/index.ts +31 -0
  22. package/cli/commands/createPullRequestReleaseCommand/addToPullRequestRelease.ts +71 -0
  23. package/cli/commands/createPullRequestReleaseCommand/createPullRequestRelease.ts +75 -0
  24. package/cli/commands/createPullRequestReleaseCommand/index.ts +74 -0
  25. package/cli/commands/getPackageHashCommand/index.ts +45 -0
  26. package/cli/commands/initCommand/index.ts +14 -0
  27. package/cli/commands/initCommand/initAndroid.ts +91 -0
  28. package/cli/commands/initCommand/initIos.ts +123 -0
  29. package/cli/commands/initCommand/test/initAndroid.test.ts +128 -0
  30. package/cli/commands/initCommand/test/initIos.test.ts +99 -0
  31. package/cli/commands/releaseCommand/addToReleaseHistory.ts +57 -0
  32. package/cli/commands/releaseCommand/index.ts +90 -0
  33. package/cli/commands/releaseCommand/release.ts +105 -0
  34. package/cli/commands/removePullRequestHistoryCommand/index.ts +37 -0
  35. package/cli/commands/removePullRequestHistoryCommand/removePullRequestHistory.ts +28 -0
  36. package/cli/commands/showHistoryCommand/index.ts +31 -0
  37. package/cli/commands/updateHistoryCommand/index.ts +55 -0
  38. package/cli/commands/updateHistoryCommand/updateReleaseHistory.ts +42 -0
  39. package/cli/constant.ts +4 -0
  40. package/cli/dist/commands/bundleCommand/bundleCodePush.js +65 -0
  41. package/cli/dist/commands/bundleCommand/index.js +15 -0
  42. package/cli/dist/commands/createHistoryCommand/createReleaseHistory.js +25 -0
  43. package/cli/dist/commands/createHistoryCommand/createReleaseHistoryList.js +27 -0
  44. package/cli/dist/commands/createHistoryCommand/index.js +20 -0
  45. package/cli/dist/commands/createPullRequestHistoryCommand/createPullRequestHistory.js +23 -0
  46. package/cli/dist/commands/createPullRequestHistoryCommand/index.js +15 -0
  47. package/cli/dist/commands/createPullRequestReleaseCommand/addToPullRequestRelease.js +51 -0
  48. package/cli/dist/commands/createPullRequestReleaseCommand/createPullRequestRelease.js +39 -0
  49. package/cli/dist/commands/createPullRequestReleaseCommand/index.js +35 -0
  50. package/cli/dist/commands/getPackageHashCommand/index.js +26 -0
  51. package/cli/dist/commands/initCommand/index.js +12 -0
  52. package/cli/dist/commands/initCommand/initAndroid.js +73 -0
  53. package/cli/dist/commands/initCommand/initIos.js +108 -0
  54. package/cli/dist/commands/initCommand/test/initAndroid.test.js +113 -0
  55. package/cli/dist/commands/initCommand/test/initIos.test.js +95 -0
  56. package/cli/dist/commands/releaseCommand/addToReleaseHistory.js +35 -0
  57. package/cli/dist/commands/releaseCommand/index.js +45 -0
  58. package/cli/dist/commands/releaseCommand/release.js +62 -0
  59. package/cli/dist/commands/removePullRequestHistoryCommand/index.js +19 -0
  60. package/cli/dist/commands/removePullRequestHistoryCommand/removePullRequestHistory.js +18 -0
  61. package/cli/dist/commands/showHistoryCommand/index.js +15 -0
  62. package/cli/dist/commands/updateHistoryCommand/index.js +31 -0
  63. package/cli/dist/commands/updateHistoryCommand/updateReleaseHistory.js +28 -0
  64. package/cli/dist/constant.js +4 -0
  65. package/cli/dist/functions/getReactTempDir.js +10 -0
  66. package/cli/{functions → dist/functions}/makeCodePushBundle.js +5 -11
  67. package/cli/{functions → dist/functions}/prepareToBundleJS.js +2 -5
  68. package/cli/dist/functions/runExpoBundleCommand.js +35 -0
  69. package/cli/{functions → dist/functions}/runHermesEmitBinaryCommand.js +36 -71
  70. package/cli/{functions → dist/functions}/runReactNativeBundleCommand.js +19 -24
  71. package/cli/dist/index.js +54 -0
  72. package/cli/dist/utils/datetime.js +17 -0
  73. package/cli/dist/utils/file-utils.js +19 -0
  74. package/cli/dist/utils/fsUtils.js +44 -0
  75. package/cli/{utils → dist/utils}/hash-utils.js +19 -130
  76. package/cli/{utils → dist/utils}/promisfied-fs.js +5 -16
  77. package/cli/dist/utils/showLogo.js +21 -0
  78. package/cli/dist/utils/unzip.js +41 -0
  79. package/cli/{utils → dist/utils}/zip.js +15 -51
  80. package/cli/functions/{getReactTempDir.js → getReactTempDir.ts} +2 -6
  81. package/cli/functions/makeCodePushBundle.ts +26 -0
  82. package/cli/functions/prepareToBundleJS.ts +10 -0
  83. package/cli/functions/runExpoBundleCommand.ts +45 -0
  84. package/cli/functions/runHermesEmitBinaryCommand.ts +203 -0
  85. package/cli/functions/runReactNativeBundleCommand.ts +67 -0
  86. package/cli/index.ts +68 -0
  87. package/cli/package.json +35 -0
  88. package/cli/utils/datetime.ts +19 -0
  89. package/cli/utils/{file-utils.js → file-utils.ts} +4 -21
  90. package/cli/utils/fsUtils.ts +50 -0
  91. package/cli/utils/hash-utils.ts +143 -0
  92. package/cli/utils/promisfied-fs.ts +19 -0
  93. package/cli/utils/{showLogo.js → showLogo.ts} +4 -6
  94. package/cli/utils/unzip.ts +46 -0
  95. package/cli/utils/zip.ts +65 -0
  96. package/expo/plugin/withCodePush.js +14 -0
  97. package/expo/plugin/withCodePushAndroid.js +92 -0
  98. package/expo/plugin/withCodePushIos.js +143 -0
  99. package/ios/CodePush/CodePush.h +0 -16
  100. package/ios/CodePush/CodePush.m +30 -20
  101. package/ios/CodePush/CodePushConfig.m +1 -11
  102. package/ios/CodePush/CodePushPackage.m +12 -69
  103. package/ios/CodePush/CodePushUpdateUtils.m +1 -91
  104. package/ios/CodePush/SSZipArchive/Info.plist +26 -0
  105. package/ios/CodePush/SSZipArchive/README.md +1 -1
  106. package/ios/CodePush/SSZipArchive/SSZipArchive.h +129 -27
  107. package/ios/CodePush/SSZipArchive/SSZipArchive.m +1119 -314
  108. package/ios/CodePush/SSZipArchive/SSZipCommon.h +71 -0
  109. package/ios/CodePush/SSZipArchive/Supporting Files/PrivacyInfo.xcprivacy +23 -0
  110. package/ios/CodePush/SSZipArchive/include/ZipArchive.h +25 -0
  111. package/ios/CodePush/SSZipArchive/minizip/LICENSE +17 -0
  112. package/ios/CodePush/SSZipArchive/minizip/mz.h +273 -0
  113. package/ios/CodePush/SSZipArchive/minizip/mz_compat.c +1306 -0
  114. package/ios/CodePush/SSZipArchive/minizip/mz_compat.h +346 -0
  115. package/ios/CodePush/SSZipArchive/minizip/mz_crypt.c +187 -0
  116. package/ios/CodePush/SSZipArchive/minizip/mz_crypt.h +65 -0
  117. package/ios/CodePush/SSZipArchive/minizip/mz_crypt_apple.c +526 -0
  118. package/ios/CodePush/SSZipArchive/minizip/mz_os.c +348 -0
  119. package/ios/CodePush/SSZipArchive/minizip/mz_os.h +176 -0
  120. package/ios/CodePush/SSZipArchive/minizip/mz_os_posix.c +350 -0
  121. package/ios/CodePush/SSZipArchive/minizip/mz_strm.c +556 -0
  122. package/ios/CodePush/SSZipArchive/minizip/mz_strm.h +132 -0
  123. package/ios/CodePush/SSZipArchive/minizip/mz_strm_buf.c +383 -0
  124. package/ios/CodePush/SSZipArchive/minizip/mz_strm_buf.h +42 -0
  125. package/ios/CodePush/SSZipArchive/minizip/mz_strm_mem.c +269 -0
  126. package/ios/CodePush/SSZipArchive/minizip/mz_strm_mem.h +48 -0
  127. package/ios/CodePush/SSZipArchive/minizip/mz_strm_os.h +40 -0
  128. package/ios/CodePush/SSZipArchive/minizip/mz_strm_os_posix.c +203 -0
  129. package/ios/CodePush/SSZipArchive/minizip/mz_strm_pkcrypt.c +334 -0
  130. package/ios/CodePush/SSZipArchive/minizip/mz_strm_pkcrypt.h +46 -0
  131. package/ios/CodePush/SSZipArchive/minizip/mz_strm_split.c +429 -0
  132. package/ios/CodePush/SSZipArchive/minizip/mz_strm_split.h +43 -0
  133. package/ios/CodePush/SSZipArchive/minizip/mz_strm_wzaes.c +360 -0
  134. package/ios/CodePush/SSZipArchive/minizip/mz_strm_wzaes.h +46 -0
  135. package/ios/CodePush/SSZipArchive/minizip/mz_strm_zlib.c +389 -0
  136. package/ios/CodePush/SSZipArchive/minizip/mz_strm_zlib.h +43 -0
  137. package/ios/CodePush/SSZipArchive/minizip/mz_zip.c +2782 -0
  138. package/ios/CodePush/SSZipArchive/minizip/mz_zip.h +262 -0
  139. package/ios/CodePush/SSZipArchive/minizip/mz_zip_rw.c +1942 -0
  140. package/ios/CodePush/SSZipArchive/minizip/mz_zip_rw.h +285 -0
  141. package/ios/CodePush.xcodeproj/project.pbxproj +244 -453
  142. package/ios/PrivacyInfo.xcprivacy +31 -0
  143. package/package.json +67 -41
  144. package/react-native.config.js +1 -1
  145. package/{AlertAdapter.js → src/AlertAdapter.js} +5 -5
  146. package/src/CodePush.js +947 -0
  147. package/{package-mixins.js → src/package-mixins.js} +1 -1
  148. package/{versioning → src/versioning}/BaseVersioning.js +12 -1
  149. package/{versioning → src/versioning}/SemverVersioning.test.js +78 -0
  150. package/typings/react-native-code-push.d.ts +559 -495
  151. package/CONTRIBUTING.md +0 -134
  152. package/CodePush.js +0 -972
  153. package/SECURITY.md +0 -41
  154. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +0 -37
  155. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +0 -12
  156. package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +0 -17
  157. package/android/codepush.gradle +0 -162
  158. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  159. package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  160. package/android/gradlew +0 -164
  161. package/android/gradlew.bat +0 -90
  162. package/babel.config.js +0 -3
  163. package/cli/commands/bundleCommand/bundleCodePush.js +0 -57
  164. package/cli/commands/bundleCommand/index.js +0 -55
  165. package/cli/commands/common.js +0 -245
  166. package/cli/commands/createHistoryCommand/createReleaseHistory.js +0 -42
  167. package/cli/commands/createHistoryCommand/createReleaseHistoryList.js +0 -52
  168. package/cli/commands/createHistoryCommand/index.js +0 -95
  169. package/cli/commands/createPullRequestHistoryCommand/createPullRequestHistory.js +0 -34
  170. package/cli/commands/createPullRequestHistoryCommand/index.js +0 -29
  171. package/cli/commands/createPullRequestReleaseCommand/addToPullRequestRelease.js +0 -74
  172. package/cli/commands/createPullRequestReleaseCommand/createPullRequestRelease.js +0 -91
  173. package/cli/commands/createPullRequestReleaseCommand/index.js +0 -68
  174. package/cli/commands/getPackageHashCommand/index.js +0 -42
  175. package/cli/commands/releaseCommand/addToReleaseHistory.js +0 -85
  176. package/cli/commands/releaseCommand/index.js +0 -151
  177. package/cli/commands/releaseCommand/release.js +0 -121
  178. package/cli/commands/removePullRequestHistoryCommand/index.js +0 -28
  179. package/cli/commands/removePullRequestHistoryCommand/removePullRequestHistory.js +0 -23
  180. package/cli/commands/showHistoryCommand/index.js +0 -88
  181. package/cli/commands/updateHistoryCommand/index.js +0 -123
  182. package/cli/commands/updateHistoryCommand/updateReleaseHistory.js +0 -69
  183. package/cli/constant.js +0 -8
  184. package/cli/index.js +0 -63
  185. package/cli/utils/datetime.js +0 -22
  186. package/cli/utils/fsUtils.js +0 -64
  187. package/cli/utils/version.js +0 -26
  188. package/code-push.config.example.supabase.ts +0 -114
  189. package/code-push.config.js +0 -229
  190. package/code-push.config.ts +0 -175
  191. package/docs/api-android.md +0 -83
  192. package/docs/api-ios.md +0 -31
  193. package/docs/api-js.md +0 -592
  194. package/docs/multi-deployment-testing-android.md +0 -148
  195. package/docs/multi-deployment-testing-ios.md +0 -59
  196. package/docs/setup-android.md +0 -482
  197. package/docs/setup-ios.md +0 -280
  198. package/eslint.config.mjs +0 -32
  199. package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +0 -34
  200. package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +0 -252
  201. package/ios/CodePush/Base64/README.md +0 -47
  202. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +0 -69
  203. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +0 -16
  204. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +0 -51
  205. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +0 -15
  206. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +0 -55
  207. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +0 -24
  208. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +0 -41
  209. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +0 -28
  210. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +0 -205
  211. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +0 -103
  212. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +0 -322
  213. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +0 -37
  214. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +0 -145
  215. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +0 -35
  216. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +0 -551
  217. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +0 -23
  218. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +0 -43
  219. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +0 -230
  220. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +0 -31
  221. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +0 -113
  222. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +0 -38
  223. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +0 -500
  224. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +0 -18
  225. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +0 -214
  226. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +0 -23
  227. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +0 -29
  228. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +0 -19
  229. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +0 -68
  230. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +0 -18
  231. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +0 -72
  232. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +0 -67
  233. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +0 -111
  234. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +0 -119
  235. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +0 -307
  236. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +0 -94
  237. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +0 -619
  238. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +0 -164
  239. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +0 -514
  240. package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +0 -24
  241. package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +0 -11
  242. package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +0 -52
  243. package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +0 -5
  244. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +0 -28
  245. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +0 -70
  246. package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +0 -22
  247. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +0 -34
  248. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +0 -73
  249. package/ios/CodePush/JWT/LICENSE +0 -19
  250. package/ios/CodePush/JWT/README.md +0 -489
  251. package/ios/CodePush/SSZipArchive/Common.h +0 -81
  252. package/ios/CodePush/SSZipArchive/aes/aes.h +0 -198
  253. package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +0 -541
  254. package/ios/CodePush/SSZipArchive/aes/aescrypt.c +0 -294
  255. package/ios/CodePush/SSZipArchive/aes/aeskey.c +0 -548
  256. package/ios/CodePush/SSZipArchive/aes/aesopt.h +0 -739
  257. package/ios/CodePush/SSZipArchive/aes/aestab.c +0 -391
  258. package/ios/CodePush/SSZipArchive/aes/aestab.h +0 -173
  259. package/ios/CodePush/SSZipArchive/aes/brg_endian.h +0 -126
  260. package/ios/CodePush/SSZipArchive/aes/brg_types.h +0 -219
  261. package/ios/CodePush/SSZipArchive/aes/entropy.c +0 -54
  262. package/ios/CodePush/SSZipArchive/aes/entropy.h +0 -16
  263. package/ios/CodePush/SSZipArchive/aes/fileenc.c +0 -144
  264. package/ios/CodePush/SSZipArchive/aes/fileenc.h +0 -121
  265. package/ios/CodePush/SSZipArchive/aes/hmac.c +0 -145
  266. package/ios/CodePush/SSZipArchive/aes/hmac.h +0 -103
  267. package/ios/CodePush/SSZipArchive/aes/prng.c +0 -155
  268. package/ios/CodePush/SSZipArchive/aes/prng.h +0 -82
  269. package/ios/CodePush/SSZipArchive/aes/pwd2key.c +0 -103
  270. package/ios/CodePush/SSZipArchive/aes/pwd2key.h +0 -57
  271. package/ios/CodePush/SSZipArchive/aes/sha1.c +0 -258
  272. package/ios/CodePush/SSZipArchive/aes/sha1.h +0 -73
  273. package/ios/CodePush/SSZipArchive/minizip/crypt.h +0 -130
  274. package/ios/CodePush/SSZipArchive/minizip/ioapi.c +0 -369
  275. package/ios/CodePush/SSZipArchive/minizip/ioapi.h +0 -175
  276. package/ios/CodePush/SSZipArchive/minizip/mztools.c +0 -284
  277. package/ios/CodePush/SSZipArchive/minizip/mztools.h +0 -31
  278. package/ios/CodePush/SSZipArchive/minizip/unzip.c +0 -1839
  279. package/ios/CodePush/SSZipArchive/minizip/unzip.h +0 -248
  280. package/ios/CodePush/SSZipArchive/minizip/zip.c +0 -1910
  281. package/ios/CodePush/SSZipArchive/minizip/zip.h +0 -202
  282. package/scripts/generateBundledResourcesHash.js +0 -125
  283. package/scripts/getFilesInFolder.js +0 -19
  284. package/scripts/recordFilesBeforeBundleCommand.js +0 -41
  285. package/tsconfig.json +0 -20
  286. package/tslint.json +0 -32
  287. /package/{logging.js → src/logging.js} +0 -0
  288. /package/{versioning → src/versioning}/BaseVersioning.test.js +0 -0
  289. /package/{versioning → src/versioning}/IncrementalVersioning.js +0 -0
  290. /package/{versioning → src/versioning}/IncrementalVersioning.test.js +0 -0
  291. /package/{versioning → src/versioning}/SemverVersioning.js +0 -0
  292. /package/{versioning → src/versioning}/index.js +0 -0
@@ -1,14 +1,6 @@
1
1
  package com.microsoft.codepush.react;
2
2
 
3
3
  import android.content.Context;
4
- import android.util.Base64;
5
-
6
- import com.nimbusds.jose.JWSVerifier;
7
- import com.nimbusds.jose.crypto.RSASSAVerifier;
8
- import com.nimbusds.jwt.SignedJWT;
9
-
10
- import java.security.interfaces.*;
11
-
12
4
 
13
5
  import org.json.JSONArray;
14
6
  import org.json.JSONException;
@@ -21,14 +13,10 @@ import java.io.FileNotFoundException;
21
13
  import java.io.IOException;
22
14
  import java.io.InputStream;
23
15
  import java.security.DigestInputStream;
24
- import java.security.KeyFactory;
25
16
  import java.security.MessageDigest;
26
17
  import java.security.NoSuchAlgorithmException;
27
- import java.security.PublicKey;
28
- import java.security.spec.X509EncodedKeySpec;
29
18
  import java.util.ArrayList;
30
19
  import java.util.Collections;
31
- import java.util.Map;
32
20
 
33
21
  public class CodePushUpdateUtils {
34
22
 
@@ -39,13 +27,10 @@ public class CodePushUpdateUtils {
39
27
  public static boolean isHashIgnored(String relativeFilePath) {
40
28
  final String __MACOSX = "__MACOSX/";
41
29
  final String DS_STORE = ".DS_Store";
42
- final String CODEPUSH_METADATA = ".codepushrelease";
43
30
 
44
31
  return relativeFilePath.startsWith(__MACOSX)
45
32
  || relativeFilePath.equals(DS_STORE)
46
- || relativeFilePath.endsWith("/" + DS_STORE)
47
- || relativeFilePath.equals(CODEPUSH_METADATA)
48
- || relativeFilePath.endsWith("/" + CODEPUSH_METADATA);
33
+ || relativeFilePath.endsWith("/" + DS_STORE);
49
34
  }
50
35
 
51
36
  private static void addContentsOfFolderToManifest(String folderPath, String pathPrefix, ArrayList<String> manifest) {
@@ -86,8 +71,12 @@ public class CodePushUpdateUtils {
86
71
  throw new CodePushUnknownException("Unable to compute hash of update contents.", e);
87
72
  } finally {
88
73
  try {
89
- if (digestInputStream != null) digestInputStream.close();
90
- if (dataStream != null) dataStream.close();
74
+ if (digestInputStream != null) {
75
+ digestInputStream.close();
76
+ }
77
+ if (dataStream != null) {
78
+ dataStream.close();
79
+ }
91
80
  } catch (IOException e) {
92
81
  e.printStackTrace();
93
82
  }
@@ -98,7 +87,11 @@ public class CodePushUpdateUtils {
98
87
  }
99
88
 
100
89
  public static void copyNecessaryFilesFromCurrentPackage(String diffManifestFilePath, String currentPackageFolderPath, String newPackageFolderPath) throws IOException {
101
- FileUtils.copyDirectoryContents(currentPackageFolderPath, newPackageFolderPath);
90
+ if (currentPackageFolderPath == null || !new File(currentPackageFolderPath).exists()) {
91
+ CodePushUtils.log("Unable to copy files from current package during diff update, because currentPackageFolderPath is invalid.");
92
+ return;
93
+ }
94
+ FileUtils.copyDirectoryContents(currentPackageFolderPath, newPackageFolderPath);
102
95
  JSONObject diffManifest = CodePushUtils.getJsonObjectFromFile(diffManifestFilePath);
103
96
  try {
104
97
  JSONArray deletedFiles = diffManifest.getJSONArray("deletedFiles");
@@ -142,11 +135,6 @@ public class CodePushUpdateUtils {
142
135
  try {
143
136
  return CodePushUtils.getStringFromInputStream(context.getAssets().open(CodePushConstants.CODE_PUSH_OLD_HASH_FILE_NAME));
144
137
  } catch (IOException ex) {
145
- if (!isDebugMode) {
146
- // Only print this message in "Release" mode. In "Debug", we may not have the
147
- // hash if the build skips bundling the files.
148
- CodePushUtils.log("Unable to get the hash of the binary's bundled resources - \"codepush.gradle\" may have not been added to the build definition.");
149
- }
150
138
  }
151
139
  return null;
152
140
  }
@@ -181,88 +169,4 @@ public class CodePushUpdateUtils {
181
169
  CodePushUtils.log("The update contents succeeded the data integrity check.");
182
170
  }
183
171
 
184
- public static Map<String, Object> verifyAndDecodeJWT(String jwt, PublicKey publicKey) {
185
- try {
186
- SignedJWT signedJWT = SignedJWT.parse(jwt);
187
- JWSVerifier verifier = new RSASSAVerifier((RSAPublicKey)publicKey);
188
- if (signedJWT.verify(verifier)) {
189
- Map<String, Object> claims = signedJWT.getJWTClaimsSet().getClaims();
190
- CodePushUtils.log("JWT verification succeeded, payload content: " + claims.toString());
191
- return claims;
192
- }
193
- return null;
194
- } catch (Exception ex) {
195
- CodePushUtils.log(ex.getMessage());
196
- CodePushUtils.log(ex.getStackTrace().toString());
197
- return null;
198
- }
199
- }
200
-
201
- public static PublicKey parsePublicKey(String stringPublicKey) {
202
- try {
203
- //remove unnecessary "begin/end public key" entries from string
204
- stringPublicKey = stringPublicKey
205
- .replace("-----BEGIN PUBLIC KEY-----", "")
206
- .replace("-----END PUBLIC KEY-----", "")
207
- .replace(NEW_LINE, "");
208
- byte[] byteKey = Base64.decode(stringPublicKey.getBytes(), Base64.DEFAULT);
209
- X509EncodedKeySpec X509Key = new X509EncodedKeySpec(byteKey);
210
- KeyFactory kf = KeyFactory.getInstance("RSA");
211
-
212
- return kf.generatePublic(X509Key);
213
- } catch (Exception e) {
214
- CodePushUtils.log(e.getMessage());
215
- CodePushUtils.log(e.getStackTrace().toString());
216
- return null;
217
- }
218
- }
219
-
220
- public static String getSignatureFilePath(String updateFolderPath){
221
- return CodePushUtils.appendPathComponent(
222
- CodePushUtils.appendPathComponent(updateFolderPath, CodePushConstants.CODE_PUSH_FOLDER_PREFIX),
223
- CodePushConstants.BUNDLE_JWT_FILE
224
- );
225
- }
226
-
227
- public static String getSignature(String folderPath) {
228
- final String signatureFilePath = getSignatureFilePath(folderPath);
229
-
230
- try {
231
- return FileUtils.readFileToString(signatureFilePath);
232
- } catch (IOException e) {
233
- CodePushUtils.log(e.getMessage());
234
- CodePushUtils.log(e.getStackTrace().toString());
235
- return null;
236
- }
237
- }
238
-
239
- public static void verifyUpdateSignature(String folderPath, String packageHash, String stringPublicKey) throws CodePushInvalidUpdateException {
240
- CodePushUtils.log("Verifying signature for folder path: " + folderPath);
241
-
242
- final PublicKey publicKey = parsePublicKey(stringPublicKey);
243
- if (publicKey == null) {
244
- throw new CodePushInvalidUpdateException("The update could not be verified because no public key was found.");
245
- }
246
-
247
- final String signature = getSignature(folderPath);
248
- if (signature == null) {
249
- throw new CodePushInvalidUpdateException("The update could not be verified because no signature was found.");
250
- }
251
-
252
- final Map<String, Object> claims = verifyAndDecodeJWT(signature, publicKey);
253
- if (claims == null) {
254
- throw new CodePushInvalidUpdateException("The update could not be verified because it was not signed by a trusted party.");
255
- }
256
-
257
- final String contentHash = (String)claims.get("contentHash");
258
- if (contentHash == null) {
259
- throw new CodePushInvalidUpdateException("The update could not be verified because the signature did not specify a content hash.");
260
- }
261
-
262
- if (!contentHash.equals(packageHash)) {
263
- throw new CodePushInvalidUpdateException("The update contents failed the code signing check.");
264
- }
265
-
266
- CodePushUtils.log("The update contents succeeded the code signing check.");
267
- }
268
- }
172
+ }
@@ -14,6 +14,9 @@ buildscript {
14
14
  }
15
15
 
16
16
  allprojects {
17
+ android {
18
+ namespace "com.microsoft.codepush.react"
19
+ }
17
20
  repositories {
18
21
  mavenLocal()
19
22
  mavenCentral()
package/app.plugin.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("./expo/plugin/withCodePush");
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+
3
+ import('../cli/dist/index.js').catch((error) => {
4
+ console.error(error);
5
+ process.exit(1);
6
+ });
@@ -0,0 +1,118 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { prepareToBundleJS } from "../../functions/prepareToBundleJS.js";
4
+ import { runReactNativeBundleCommand } from "../../functions/runReactNativeBundleCommand.js";
5
+ import { runExpoBundleCommand } from "../../functions/runExpoBundleCommand.js";
6
+ import { getReactTempDir } from "../../functions/getReactTempDir.js";
7
+ import { runHermesEmitBinaryCommand } from "../../functions/runHermesEmitBinaryCommand.js";
8
+ import { makeCodePushBundle } from "../../functions/makeCodePushBundle.js";
9
+ import { ROOT_OUTPUT_DIR } from "../../constant.js";
10
+
11
+ /**
12
+ * @return {Promise<string>} CodePush bundle file name (equals to packageHash)
13
+ */
14
+ export async function bundleCodePush(
15
+ framework: 'expo' | undefined,
16
+ platform: 'ios' | 'android' = 'ios',
17
+ outputRootPath: string = ROOT_OUTPUT_DIR,
18
+ entryFile: string | undefined,
19
+ jsBundleName: string, // JS bundle file name (not CodePush bundle file)
20
+ bundleDirectory: string, // CodePush bundle output directory
21
+ outputMetroDir?: string,
22
+ ): Promise<string> {
23
+ const resolvedEntryFile = resolveEntryFile(entryFile, platform);
24
+
25
+ if (fs.existsSync(outputRootPath)) {
26
+ fs.rmSync(outputRootPath, { recursive: true });
27
+ }
28
+
29
+ const OUTPUT_CONTENT_PATH = `${outputRootPath}/CodePush`;
30
+ const DEFAULT_JS_BUNDLE_NAME = platform === 'ios' ? 'main.jsbundle' : 'index.android.bundle';
31
+ const _jsBundleName = jsBundleName || DEFAULT_JS_BUNDLE_NAME; // react-native JS bundle output name
32
+ const SOURCEMAP_OUTPUT = `${outputRootPath}/${_jsBundleName}.map`;
33
+
34
+ prepareToBundleJS({ deleteDirs: [outputRootPath, getReactTempDir()], makeDir: OUTPUT_CONTENT_PATH });
35
+
36
+ if (framework === 'expo') {
37
+ runExpoBundleCommand(
38
+ _jsBundleName,
39
+ OUTPUT_CONTENT_PATH,
40
+ platform,
41
+ SOURCEMAP_OUTPUT,
42
+ resolvedEntryFile,
43
+ );
44
+ } else {
45
+ runReactNativeBundleCommand(
46
+ _jsBundleName,
47
+ OUTPUT_CONTENT_PATH,
48
+ platform,
49
+ SOURCEMAP_OUTPUT,
50
+ resolvedEntryFile,
51
+ );
52
+ }
53
+
54
+ console.log('log: JS bundling complete');
55
+
56
+ copyMetroOutputsIfNeeded(outputRootPath, outputMetroDir, OUTPUT_CONTENT_PATH, _jsBundleName, SOURCEMAP_OUTPUT);
57
+
58
+ await runHermesEmitBinaryCommand(
59
+ _jsBundleName,
60
+ OUTPUT_CONTENT_PATH,
61
+ SOURCEMAP_OUTPUT,
62
+ );
63
+ console.log('log: Hermes compilation complete');
64
+
65
+ const { bundleFileName: codePushBundleFileName } = await makeCodePushBundle(OUTPUT_CONTENT_PATH, bundleDirectory);
66
+ console.log(`log: CodePush bundle created (file path: ./${bundleDirectory}/${codePushBundleFileName})`);
67
+
68
+ return codePushBundleFileName;
69
+ }
70
+
71
+ function resolveEntryFile(
72
+ entryFile: string | undefined,
73
+ platform: 'ios' | 'android',
74
+ ): string {
75
+ if (entryFile) {
76
+ if (!fs.existsSync(entryFile)) {
77
+ throw new Error(`Entry file "${entryFile}" does not exist.`);
78
+ }
79
+ return entryFile;
80
+ }
81
+
82
+ // 앱마다 엔트리 파일이 다르다 (index.js / index.ts / index.<platform>.js).
83
+ // 명시하지 않으면 react-native CLI 관례 순서로 자동 감지한다.
84
+ const candidates = [`index.${platform}.js`, 'index.js', `index.${platform}.ts`, 'index.ts'];
85
+ const found = candidates.find((candidate) => fs.existsSync(candidate));
86
+ if (!found) {
87
+ throw new Error(
88
+ `Entry file not found. Tried: ${candidates.join(', ')}. Use -e/--entry-file to specify one.`,
89
+ );
90
+ }
91
+ console.log(`log: entry file auto-detected: ${found}`);
92
+ return found;
93
+ }
94
+
95
+ function copyMetroOutputsIfNeeded(
96
+ outputRootPath: string,
97
+ outputMetroDir: string | undefined,
98
+ outputContentPath: string,
99
+ jsBundleName: string,
100
+ sourceMapOutputPath: string,
101
+ ) {
102
+ if (!outputMetroDir) {
103
+ return;
104
+ }
105
+
106
+ const resolvedOutputMetroDir = path.join(outputRootPath, outputMetroDir);
107
+
108
+ fs.mkdirSync(resolvedOutputMetroDir, { recursive: true });
109
+ fs.copyFileSync(
110
+ path.join(outputContentPath, jsBundleName),
111
+ path.join(resolvedOutputMetroDir, jsBundleName),
112
+ );
113
+ fs.copyFileSync(
114
+ sourceMapOutputPath,
115
+ path.join(resolvedOutputMetroDir, path.basename(sourceMapOutputPath)),
116
+ );
117
+ console.log(`log: Metro outputs copied to: ${resolvedOutputMetroDir}`);
118
+ }
@@ -0,0 +1,34 @@
1
+ import { program, Option } from "commander";
2
+ import { bundleCodePush } from "./bundleCodePush.js";
3
+ import { OUTPUT_BUNDLE_DIR, ROOT_OUTPUT_DIR } from "../../constant.js";
4
+
5
+ type Options = {
6
+ framework: 'expo' | undefined;
7
+ platform: 'ios' | 'android';
8
+ outputPath: string;
9
+ entryFile?: string;
10
+ bundleName: string;
11
+ outputBundleDir: string;
12
+ outputMetroDir?: string;
13
+ }
14
+
15
+ program.command('bundle')
16
+ .description('Creates a CodePush bundle file (assumes Hermes is enabled).')
17
+ .addOption(new Option('-f, --framework <type>', 'framework type (expo)').choices(['expo']))
18
+ .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
19
+ .option('-o, --output-path <string>', 'path to output root directory', ROOT_OUTPUT_DIR)
20
+ .option('-e, --entry-file <string>', 'path to JS/TS entry file (default: auto-detect index.<platform>.js → index.js → index.ts)')
21
+ .option('-b, --bundle-name <string>', 'bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")')
22
+ .option('--output-metro-dir <string>', 'name of directory to copy the Metro JS bundle and sourcemap before Hermes compilation')
23
+ .option('--output-bundle-dir <string>', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR)
24
+ .action((options: Options) => {
25
+ bundleCodePush(
26
+ options.framework,
27
+ options.platform,
28
+ options.outputPath,
29
+ options.entryFile,
30
+ options.bundleName,
31
+ `${options.outputPath}/${options.outputBundleDir}`,
32
+ options.outputMetroDir,
33
+ )
34
+ });
@@ -0,0 +1,37 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import type { CliConfigInterface, ReleaseHistoryInterface, ReleaseInfo } from "../../../typings/react-native-code-push.d.ts";
4
+
5
+ export async function createReleaseHistory(
6
+ targetVersion: string,
7
+ setReleaseHistory: CliConfigInterface['setReleaseHistory'],
8
+ platform: 'ios' | 'android',
9
+ identifier?: string,
10
+ app?: string,
11
+ ): Promise<void> {
12
+ const BINARY_RELEASE: ReleaseInfo = {
13
+ enabled: true,
14
+ mandatory: false,
15
+ downloadUrl: "",
16
+ packageHash: "",
17
+ };
18
+
19
+ const INITIAL_HISTORY: ReleaseHistoryInterface = {
20
+ [targetVersion]: BINARY_RELEASE
21
+ };
22
+
23
+ try {
24
+ const JSON_FILE_NAME = `${targetVersion}.json`;
25
+ const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME);
26
+
27
+ console.log(`log: creating JSON file... ("${JSON_FILE_NAME}")\n`, JSON.stringify(INITIAL_HISTORY, null, 2));
28
+ fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(INITIAL_HISTORY));
29
+
30
+ await setReleaseHistory(targetVersion, JSON_FILE_PATH, INITIAL_HISTORY, platform, identifier, app)
31
+
32
+ fs.unlinkSync(JSON_FILE_PATH);
33
+ } catch (error) {
34
+ console.error('Error occurred while creating new history:', error);
35
+ process.exit(1)
36
+ }
37
+ }
@@ -0,0 +1,40 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import type { CliConfigInterface } from "../../../typings/react-native-code-push.d.ts";
4
+
5
+ /**
6
+ * Adds the new binary version to the binary version list file (`list.json`).
7
+ *
8
+ * The list file indexes all binary versions for which a release history exists,
9
+ * so that deploy pipelines can check for an existing history without listing bucket objects.
10
+ * (algocare extension — runs only when the config implements `getBinaryVersionList`/`setBinaryVersionList`.)
11
+ */
12
+ export async function createReleaseHistoryList(
13
+ targetVersion: string,
14
+ getBinaryVersionList: NonNullable<CliConfigInterface['getBinaryVersionList']>,
15
+ setBinaryVersionList: NonNullable<CliConfigInterface['setBinaryVersionList']>,
16
+ platform: 'ios' | 'android',
17
+ identifier?: string,
18
+ app?: string,
19
+ ): Promise<void> {
20
+ try {
21
+ const JSON_FILE_NAME = 'list.json';
22
+ const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME);
23
+
24
+ const currentList = await getBinaryVersionList(platform, identifier, app);
25
+
26
+ if (currentList[targetVersion]) {
27
+ console.error(`Version ${targetVersion} is already released`);
28
+ process.exit(1);
29
+ }
30
+
31
+ fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(currentList));
32
+
33
+ await setBinaryVersionList(targetVersion, JSON_FILE_PATH, platform, identifier, app);
34
+
35
+ fs.unlinkSync(JSON_FILE_PATH);
36
+ } catch (error) {
37
+ console.error('Error occurred while creating new history list:', error);
38
+ process.exit(1);
39
+ }
40
+ }
@@ -0,0 +1,44 @@
1
+ import { program, Option } from "commander";
2
+ import { findAndReadConfigFile } from "../../utils/fsUtils.js";
3
+ import { createReleaseHistory } from "./createReleaseHistory.js";
4
+ import { createReleaseHistoryList } from "./createReleaseHistoryList.js";
5
+ import { CONFIG_FILE_NAME } from "../../constant.js";
6
+
7
+ type Options = {
8
+ binaryVersion: string;
9
+ platform: 'ios' | 'android';
10
+ identifier?: string;
11
+ app?: string;
12
+ config: string;
13
+ }
14
+
15
+ program.command('create-history')
16
+ .description('Creates a new release history for the binary app.')
17
+ .requiredOption('-b, --binary-version <string>', '(Required) The target binary version')
18
+ .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
19
+ .option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
20
+ .option('-a, --app <string>', 'target app name for multi-app repositories. (e.g. home-mobile)')
21
+ .option('-c, --config <path>', 'set config file name (JS/TS)', CONFIG_FILE_NAME)
22
+ .action(async (options: Options) => {
23
+ const config = findAndReadConfigFile(process.cwd(), options.config);
24
+
25
+ await createReleaseHistory(
26
+ options.binaryVersion,
27
+ config.setReleaseHistory,
28
+ options.platform,
29
+ options.identifier,
30
+ options.app,
31
+ );
32
+
33
+ // algocare extension: maintain a `list.json` index of binary versions (only when implemented in config)
34
+ if (config.getBinaryVersionList && config.setBinaryVersionList) {
35
+ await createReleaseHistoryList(
36
+ options.binaryVersion,
37
+ config.getBinaryVersionList,
38
+ config.setBinaryVersionList,
39
+ options.platform,
40
+ options.identifier,
41
+ options.app,
42
+ );
43
+ }
44
+ });
@@ -0,0 +1,33 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import type { CliConfigInterface } from "../../../typings/react-native-code-push.d.ts";
4
+
5
+ /**
6
+ * Creates an empty release history for PR preview releases.
7
+ *
8
+ * Unlike `create-history`, this does NOT seed a binary release entry and does NOT
9
+ * register the version in the `list.json` index, so PR preview histories never
10
+ * pollute the official binary version index.
11
+ */
12
+ export async function createPullRequestHistory(
13
+ setReleaseHistory: CliConfigInterface['setReleaseHistory'],
14
+ binaryVersion: string,
15
+ platform: 'ios' | 'android',
16
+ identifier?: string,
17
+ app?: string,
18
+ ): Promise<void> {
19
+ try {
20
+ const JSON_FILE_NAME = `${binaryVersion}.json`;
21
+ const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME);
22
+
23
+ console.log(`log: creating JSON file... ("${JSON_FILE_NAME}")\n`, JSON.stringify({}, null, 2));
24
+ fs.writeFileSync(JSON_FILE_PATH, JSON.stringify({}));
25
+
26
+ await setReleaseHistory(binaryVersion, JSON_FILE_PATH, {}, platform, identifier, app);
27
+
28
+ fs.unlinkSync(JSON_FILE_PATH);
29
+ } catch (error) {
30
+ console.error('Error occurred while creating new pull request history:', error);
31
+ process.exit(1);
32
+ }
33
+ }
@@ -0,0 +1,31 @@
1
+ import { program, Option } from "commander";
2
+ import { findAndReadConfigFile } from "../../utils/fsUtils.js";
3
+ import { createPullRequestHistory } from "./createPullRequestHistory.js";
4
+ import { CONFIG_FILE_NAME } from "../../constant.js";
5
+
6
+ type Options = {
7
+ binaryVersion: string;
8
+ platform: 'ios' | 'android';
9
+ identifier?: string;
10
+ app?: string;
11
+ config: string;
12
+ }
13
+
14
+ program.command('create-pr-history')
15
+ .description('Creates a new (empty) release history for PR preview releases.')
16
+ .requiredOption('-b, --binary-version <string>', '(Required) The target binary version')
17
+ .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
18
+ .option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
19
+ .option('-a, --app <string>', 'target app name for multi-app repositories. (e.g. home-mobile)')
20
+ .option('-c, --config <path>', 'set config file name (JS/TS)', CONFIG_FILE_NAME)
21
+ .action(async (options: Options) => {
22
+ const config = findAndReadConfigFile(process.cwd(), options.config);
23
+
24
+ await createPullRequestHistory(
25
+ config.setReleaseHistory,
26
+ options.binaryVersion,
27
+ options.platform,
28
+ options.identifier,
29
+ options.app,
30
+ );
31
+ });
@@ -0,0 +1,71 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ import type { CliConfigInterface } from "../../../typings/react-native-code-push.d.ts";
4
+ import { getTimestamp } from "../../utils/datetime.js";
5
+
6
+ /**
7
+ * Appends a PR preview release entry to the release history.
8
+ *
9
+ * PR preview releases are keyed as `{prNumber}-{semver}` (e.g. `1234-1.0.0`) so that
10
+ * the runtime can filter them by PR number (`SyncOptions.prNumber`) while normal
11
+ * clients ignore any key containing `-`.
12
+ */
13
+ export async function addToPullRequestRelease(
14
+ binaryVersion: string,
15
+ prNumber: string,
16
+ bundleDownloadUrl: string,
17
+ packageHash: string,
18
+ getReleaseHistory: CliConfigInterface['getReleaseHistory'],
19
+ setReleaseHistory: CliConfigInterface['setReleaseHistory'],
20
+ platform: 'ios' | 'android',
21
+ identifier: string | undefined,
22
+ app: string | undefined,
23
+ mandatory: boolean,
24
+ enable: boolean,
25
+ ): Promise<void> {
26
+ const releaseHistory = await getReleaseHistory(binaryVersion, platform, identifier, app);
27
+
28
+ const releaseHistoryKeysWithPrNumber = Object.keys(releaseHistory)
29
+ .filter((key) => key.startsWith(`${prNumber}-`));
30
+
31
+ const newReleaseVersionKey = getNewReleaseVersionKey(releaseHistoryKeysWithPrNumber, prNumber);
32
+ const newReleaseHistory = structuredClone(releaseHistory);
33
+
34
+ newReleaseHistory[newReleaseVersionKey] = {
35
+ binaryVersion,
36
+ enabled: enable,
37
+ mandatory,
38
+ downloadUrl: bundleDownloadUrl,
39
+ packageHash,
40
+ createdAt: getTimestamp(),
41
+ };
42
+
43
+ try {
44
+ const JSON_FILE_NAME = `${binaryVersion}.json`;
45
+ const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME);
46
+
47
+ console.log(`log: creating JSON file... ("${JSON_FILE_NAME}")\n`, JSON.stringify(newReleaseHistory, null, 2));
48
+ fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(newReleaseHistory));
49
+
50
+ await setReleaseHistory(binaryVersion, JSON_FILE_PATH, newReleaseHistory, platform, identifier, app);
51
+
52
+ fs.unlinkSync(JSON_FILE_PATH);
53
+ } catch (error) {
54
+ console.error('Error occurred while updating history:', error);
55
+ process.exit(1);
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Determines the next PR release key. (`{prNumber}-1.0.0` → `{prNumber}-2.0.0` → ...)
61
+ */
62
+ function getNewReleaseVersionKey(releaseHistoryKeysWithPrNumber: string[], prNumber: string): string {
63
+ const lastKey = releaseHistoryKeysWithPrNumber.at(-1);
64
+ if (lastKey) {
65
+ const [, latestVersion] = lastKey.split('-');
66
+ const latestMajor = parseInt(latestVersion.split('.')[0], 10);
67
+ return `${prNumber}-${latestMajor + 1}.0.0`;
68
+ } else {
69
+ return `${prNumber}-1.0.0`;
70
+ }
71
+ }