@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
@@ -0,0 +1,75 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { bundleCodePush } from "../bundleCommand/bundleCodePush.js";
4
+ import { addToPullRequestRelease } from "./addToPullRequestRelease.js";
5
+ import type { CliConfigInterface } from "../../../typings/react-native-code-push.d.ts";
6
+
7
+ export async function createPullRequestRelease(
8
+ bundleUploader: CliConfigInterface['bundleUploader'],
9
+ getReleaseHistory: CliConfigInterface['getReleaseHistory'],
10
+ setReleaseHistory: CliConfigInterface['setReleaseHistory'],
11
+ binaryVersion: string,
12
+ prNumber: string,
13
+ framework: 'expo' | undefined,
14
+ platform: 'ios' | 'android',
15
+ identifier: string | undefined,
16
+ app: string | undefined,
17
+ outputPath: string,
18
+ entryFile: string | undefined,
19
+ jsBundleName: string,
20
+ mandatory: boolean,
21
+ enable: boolean,
22
+ skipBundle: boolean,
23
+ skipCleanup: boolean,
24
+ bundleDirectory: string,
25
+ outputMetroDir?: string,
26
+ ): Promise<void> {
27
+ const bundleFileName = skipBundle
28
+ ? readBundleFileNameFrom(bundleDirectory)
29
+ : await bundleCodePush(framework, platform, outputPath, entryFile, jsBundleName, bundleDirectory, outputMetroDir);
30
+ const bundleFilePath = `${bundleDirectory}/${bundleFileName}`;
31
+
32
+ const downloadUrl = await (async () => {
33
+ try {
34
+ console.log('Uploading Bundle File...');
35
+ const { downloadUrl } = await bundleUploader(bundleFilePath, platform, identifier, app);
36
+ console.log('Bundle File uploaded:', downloadUrl);
37
+ return downloadUrl;
38
+ } catch (error) {
39
+ console.error('Failed to upload the bundle file. Exiting the program.\n', error);
40
+ process.exit(1);
41
+ }
42
+ })();
43
+
44
+ await addToPullRequestRelease(
45
+ binaryVersion,
46
+ prNumber,
47
+ downloadUrl,
48
+ bundleFileName, // bundleFileName represents the package hash
49
+ getReleaseHistory,
50
+ setReleaseHistory,
51
+ platform,
52
+ identifier,
53
+ app,
54
+ mandatory,
55
+ enable,
56
+ );
57
+
58
+ if (!skipCleanup) {
59
+ cleanUpOutputs(outputPath);
60
+ }
61
+ }
62
+
63
+ function cleanUpOutputs(dir: string) {
64
+ fs.rmSync(dir, { recursive: true });
65
+ }
66
+
67
+ function readBundleFileNameFrom(bundleDirectory: string): string {
68
+ const files = fs.readdirSync(bundleDirectory);
69
+ if (files.length !== 1) {
70
+ console.error('The bundlePath must contain only one file.');
71
+ process.exit(1);
72
+ }
73
+ const bundleFilePath = path.join(bundleDirectory, files[0]);
74
+ return path.basename(bundleFilePath);
75
+ }
@@ -0,0 +1,74 @@
1
+ import { program, Option } from "commander";
2
+ import { findAndReadConfigFile } from "../../utils/fsUtils.js";
3
+ import { createPullRequestRelease } from "./createPullRequestRelease.js";
4
+ import { OUTPUT_BUNDLE_DIR, CONFIG_FILE_NAME, ROOT_OUTPUT_DIR } from "../../constant.js";
5
+
6
+ type Options = {
7
+ binaryVersion: string;
8
+ prNumber: string;
9
+ framework: 'expo' | undefined;
10
+ platform: 'ios' | 'android';
11
+ identifier?: string;
12
+ app?: string;
13
+ config: string;
14
+ outputPath: string;
15
+ entryFile?: string;
16
+ jsBundleName: string;
17
+ mandatory: boolean;
18
+ enable: boolean;
19
+ skipBundle: boolean;
20
+ skipCleanup: boolean;
21
+ outputBundleDir: string;
22
+ outputMetroDir?: string;
23
+ }
24
+
25
+ program.command('create-pr-release')
26
+ .description('Deploys a PR preview CodePush release.\nThe release is keyed as `{prNumber}-{semver}` in the release history so that only clients syncing with the matching `prNumber` receive it.')
27
+ .requiredOption('-b, --binary-version <string>', '(Required) The target binary version')
28
+ .requiredOption('-r, --pr-number <string>', '(Required) The pull request number')
29
+ .addOption(new Option('-f, --framework <type>', 'framework type (expo)').choices(['expo']))
30
+ .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
31
+ .option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
32
+ .option('-a, --app <string>', 'target app name for multi-app repositories. (e.g. home-mobile)')
33
+ .option('-c, --config <path>', 'set config file name (JS/TS)', CONFIG_FILE_NAME)
34
+ .option('-o, --output-path <string>', 'path to output root directory', ROOT_OUTPUT_DIR)
35
+ .option('-e, --entry-file <string>', 'path to JS/TS entry file (default: auto-detect index.<platform>.js → index.js → index.ts)')
36
+ .option('-j, --js-bundle-name <string>', 'JS bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")')
37
+ .option('-m, --mandatory [bool]', 'make the release to be mandatory', parseBoolean, false)
38
+ .option('--enable [bool]', 'make the release to be enabled', parseBoolean, true)
39
+ .option('--skip-bundle [bool]', 'skip bundle process', parseBoolean, false)
40
+ .option('--skip-cleanup [bool]', 'skip cleanup process', parseBoolean, false)
41
+ .option('--output-metro-dir <string>', 'name of directory to copy the Metro JS bundle and sourcemap before Hermes compilation')
42
+ .option('--output-bundle-dir <string>', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR)
43
+ .action(async (options: Options) => {
44
+ const config = findAndReadConfigFile(process.cwd(), options.config);
45
+
46
+ await createPullRequestRelease(
47
+ config.bundleUploader,
48
+ config.getReleaseHistory,
49
+ config.setReleaseHistory,
50
+ options.binaryVersion,
51
+ options.prNumber,
52
+ options.framework,
53
+ options.platform,
54
+ options.identifier,
55
+ options.app,
56
+ options.outputPath,
57
+ options.entryFile,
58
+ options.jsBundleName,
59
+ options.mandatory,
60
+ options.enable,
61
+ options.skipBundle,
62
+ options.skipCleanup,
63
+ `${options.outputPath}/${options.outputBundleDir}`,
64
+ options.outputMetroDir,
65
+ );
66
+
67
+ console.log('🚀 PR preview release completed.');
68
+ });
69
+
70
+ function parseBoolean(value: string): boolean | undefined {
71
+ if (value === 'true') return true;
72
+ if (value === 'false') return false;
73
+ else return undefined;
74
+ }
@@ -0,0 +1,45 @@
1
+ import { program, Option } from "commander";
2
+ import { findAndReadConfigFile } from "../../utils/fsUtils.js";
3
+ import { CONFIG_FILE_NAME } from "../../constant.js";
4
+
5
+ type Options = {
6
+ binaryVersion: string;
7
+ prNumber?: string;
8
+ platform: 'ios' | 'android';
9
+ identifier?: string;
10
+ app?: string;
11
+ config: string;
12
+ }
13
+
14
+ program.command('get-package-hash')
15
+ .description('Retrieves and prints the package hash of the latest release for a specific binary version.\nWhen --pr-number is given, only PR preview releases (`{prNumber}-*` keys) are considered.\n`getReleaseHistory` function should be implemented in the config file.')
16
+ .requiredOption('-b, --binary-version <string>', '(Required) The target binary version')
17
+ .option('-r, --pr-number <string>', 'pull request number (filters PR preview releases)')
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>', 'configuration file name (JS/TS)', CONFIG_FILE_NAME)
22
+ .action(async (options: Options) => {
23
+ const config = findAndReadConfigFile(process.cwd(), options.config);
24
+
25
+ const releaseHistory = await config.getReleaseHistory(
26
+ options.binaryVersion,
27
+ options.platform,
28
+ options.identifier,
29
+ options.app,
30
+ );
31
+
32
+ const targetKeys = Object.keys(releaseHistory).filter((key) => {
33
+ return options.prNumber
34
+ ? key.startsWith(`${options.prNumber}-`)
35
+ : !key.includes('-');
36
+ });
37
+
38
+ const latestReleaseKey = targetKeys.at(-1);
39
+ if (!latestReleaseKey) {
40
+ console.error('No matching release found.');
41
+ process.exit(1);
42
+ }
43
+
44
+ process.stdout.write(releaseHistory[latestReleaseKey].packageHash);
45
+ });
@@ -0,0 +1,14 @@
1
+ import { initAndroid } from "./initAndroid.js";
2
+ import { initIos } from "./initIos.js";
3
+ import { program } from "commander";
4
+
5
+ program
6
+ .command('init')
7
+ .description('Automatically performs iOS/Android native configurations to initialize the CodePush project.')
8
+ .action(async () => {
9
+ console.log('log: Start initializing CodePush...');
10
+ await initAndroid();
11
+ await initIos();
12
+ console.log('log: CodePush has been successfully initialized.');
13
+ });
14
+
@@ -0,0 +1,91 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ import { EOL } from "os";
4
+
5
+ const IMPORT_CODE_PUSH = 'import com.microsoft.codepush.react.CodePush';
6
+ const RN_LEGACY_MARKER = 'object : DefaultReactNativeHost(this)';
7
+ const RN_082_MARKER = ' getDefaultReactHost(';
8
+
9
+ export function modifyMainApplicationKt(mainApplicationContent: string) {
10
+ const hasCodePushImport = mainApplicationContent.includes(IMPORT_CODE_PUSH);
11
+ const hasGetJSBundleFileFn = mainApplicationContent.includes('CodePush.getJSBundleFile()');
12
+
13
+ if (hasCodePushImport && hasGetJSBundleFileFn) {
14
+ console.log('log: MainApplication.kt already has CodePush initialized.');
15
+ return mainApplicationContent;
16
+ }
17
+
18
+ let updatedContent = mainApplicationContent;
19
+
20
+ if (!hasCodePushImport) {
21
+ updatedContent = mainApplicationContent.replace('import com.facebook.react.ReactApplication', `import com.facebook.react.ReactApplication${EOL}${IMPORT_CODE_PUSH}`);
22
+ }
23
+
24
+ const isExtendingDefaultReactNativeHost = mainApplicationContent.includes(RN_LEGACY_MARKER);
25
+
26
+ // RN <0.82
27
+ if (isExtendingDefaultReactNativeHost) {
28
+ if (!hasGetJSBundleFileFn) {
29
+ updatedContent = updatedContent.replace('override fun getJSMainModuleName(): String = "index"', `override fun getJSMainModuleName(): String = "index"${EOL} override fun getJSBundleFile(): String = CodePush.getJSBundleFile()`);
30
+ }
31
+ return updatedContent;
32
+ }
33
+
34
+ // RN 0.82+
35
+ const isUsingGetDefaultReactHost = mainApplicationContent.includes(RN_082_MARKER);
36
+ if (isUsingGetDefaultReactHost) {
37
+ if (!hasGetJSBundleFileFn) {
38
+ return addJsBundleFilePathArgument(updatedContent);
39
+ }
40
+ return updatedContent;
41
+ }
42
+
43
+ throw new Error('Unsupported MainApplication.kt structure.');
44
+ }
45
+
46
+ function addJsBundleFilePathArgument(mainApplicationContent: string) {
47
+ const packageListArgumentPattern = /(packageList\s*=\s*\n\s*PackageList\(this\)[\s\S]+?\},?\s*\n)/;
48
+
49
+ if (!packageListArgumentPattern.test(mainApplicationContent)) {
50
+ console.log('log: Could not find packageList argument while updating MainApplication.kt.');
51
+ return mainApplicationContent;
52
+ }
53
+
54
+ return mainApplicationContent.replace(packageListArgumentPattern, (match) => {
55
+ if (match.includes('jsBundleFilePath')) {
56
+ return match;
57
+ }
58
+
59
+ return `${match} jsBundleFilePath = CodePush.getJSBundleFile(),${EOL}`;
60
+ });
61
+ }
62
+
63
+ export async function initAndroid() {
64
+ console.log('log: Running Android setup...');
65
+ await applyMainApplication();
66
+ }
67
+
68
+ async function applyMainApplication() {
69
+ const mainApplicationPath = await findMainApplication();
70
+ if (!mainApplicationPath) {
71
+ console.log('log: Could not find MainApplication.kt');
72
+ return;
73
+ }
74
+
75
+ if (mainApplicationPath.endsWith('.java')) {
76
+ console.log('log: MainApplication.java is not supported. Please migrate to MainApplication.kt.');
77
+ return;
78
+ }
79
+
80
+ const mainApplicationContent = fs.readFileSync(mainApplicationPath, 'utf-8');
81
+ const newContent = modifyMainApplicationKt(mainApplicationContent);
82
+ fs.writeFileSync(mainApplicationPath, newContent);
83
+ console.log('log: Successfully updated MainApplication.kt.');
84
+ }
85
+
86
+ async function findMainApplication() {
87
+ const searchPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'java');
88
+ const files = fs.readdirSync(searchPath, { encoding: 'utf-8', recursive: true });
89
+ const mainApplicationFile = files.find(file => file.endsWith('MainApplication.java') || file.endsWith('MainApplication.kt'));
90
+ return mainApplicationFile ? path.join(searchPath, mainApplicationFile) : null;
91
+ }
@@ -0,0 +1,123 @@
1
+ import path from "path";
2
+ import fs from "fs";
3
+ // @ts-expect-error -- types for "xcode" are not available
4
+ import xcode from "xcode";
5
+
6
+ export async function initIos() {
7
+ console.log('log: Running iOS setup...');
8
+ const projectDir = path.join(process.cwd(), 'ios');
9
+ const files = fs.readdirSync(projectDir);
10
+ const xcodeprojFile = files.find(file => file.endsWith('.xcodeproj'));
11
+ if (!xcodeprojFile) {
12
+ console.log('log: Could not find .xcodeproj file in ios directory');
13
+ return;
14
+ }
15
+ const projectName = xcodeprojFile.replace('.xcodeproj', '');
16
+ const appDelegatePath = findAppDelegate(path.join(projectDir, projectName));
17
+
18
+ if (!appDelegatePath) {
19
+ console.log('log: Could not find AppDelegate file');
20
+ return;
21
+ }
22
+
23
+ if (appDelegatePath.endsWith('.swift')) {
24
+ await setupSwift(appDelegatePath, projectDir, projectName);
25
+ } else {
26
+ await setupObjectiveC(appDelegatePath);
27
+ }
28
+
29
+ console.log('log: Please run `cd ios && pod install` to complete the setup.');
30
+ }
31
+
32
+ function findAppDelegate(searchPath: string) {
33
+ if (!fs.existsSync(searchPath)) return null;
34
+ const files = fs.readdirSync(searchPath);
35
+ const appDelegateFile = files.find(file => file.startsWith('AppDelegate') && (file.endsWith('.m') || file.endsWith('.mm') || file.endsWith('.swift')));
36
+ return appDelegateFile ? path.join(searchPath, appDelegateFile) : null;
37
+ }
38
+
39
+ export function modifyObjectiveCAppDelegate(appDelegateContent: string) {
40
+ const IMPORT_STATEMENT = '#import <CodePush/CodePush.h>';
41
+ if (appDelegateContent.includes(IMPORT_STATEMENT)) {
42
+ console.log('log: AppDelegate already has CodePush imported.');
43
+ return appDelegateContent;
44
+ }
45
+
46
+ return appDelegateContent
47
+ .replace('#import "AppDelegate.h"\n', `#import "AppDelegate.h"\n${IMPORT_STATEMENT}\n`)
48
+ .replace('[[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];', '[CodePush bundleURL];');
49
+ }
50
+
51
+ export function modifySwiftAppDelegate(appDelegateContent: string) {
52
+ const CODEPUSH_CALL_STATEMENT = 'CodePush.bundleURL()';
53
+ if (appDelegateContent.includes(CODEPUSH_CALL_STATEMENT)) {
54
+ console.log('log: AppDelegate.swift already configured for CodePush.');
55
+ return appDelegateContent;
56
+ }
57
+
58
+ return appDelegateContent
59
+ .replace('Bundle.main.url(forResource: "main", withExtension: "jsbundle")', CODEPUSH_CALL_STATEMENT);
60
+ }
61
+
62
+ async function setupObjectiveC(appDelegatePath: string) {
63
+ const appDelegateContent = fs.readFileSync(appDelegatePath, 'utf-8');
64
+ const newContent = modifyObjectiveCAppDelegate(appDelegateContent);
65
+ fs.writeFileSync(appDelegatePath, newContent);
66
+ console.log('log: Successfully updated AppDelegate.m/mm.');
67
+ }
68
+
69
+ async function setupSwift(appDelegatePath: string, projectDir: string, projectName: string) {
70
+ const bridgingHeaderPath = await ensureBridgingHeader(projectDir, projectName);
71
+ if (!bridgingHeaderPath) {
72
+ console.log('log: Failed to create or find bridging header.');
73
+ return;
74
+ }
75
+
76
+ const appDelegateContent = fs.readFileSync(appDelegatePath, 'utf-8');
77
+ const newContent = modifySwiftAppDelegate(appDelegateContent);
78
+ fs.writeFileSync(appDelegatePath, newContent);
79
+ console.log('log: Successfully updated AppDelegate.swift.');
80
+ }
81
+
82
+ async function ensureBridgingHeader(projectDir: string, projectName: string) {
83
+ const projectPath = path.join(projectDir, `${projectName}.xcodeproj`, 'project.pbxproj');
84
+ const myProj = xcode.project(projectPath);
85
+
86
+ return new Promise((resolve, reject) => {
87
+ myProj.parse(function (err: unknown) {
88
+ if (err) {
89
+ console.error(`Error parsing Xcode project: ${err}`);
90
+ return reject(err);
91
+ }
92
+
93
+ const bridgingHeaderRelativePath = `${projectName}/${projectName}-Bridging-Header.h`;
94
+ const bridgingHeaderAbsolutePath = path.join(projectDir, bridgingHeaderRelativePath);
95
+
96
+ const configurations = myProj.pbxXCBuildConfigurationSection();
97
+ for (const name in configurations) {
98
+ const config = configurations[name];
99
+ if (config.buildSettings) {
100
+ config.buildSettings.SWIFT_OBJC_BRIDGING_HEADER = `"${bridgingHeaderRelativePath}"`;
101
+ }
102
+ }
103
+
104
+ if (!fs.existsSync(bridgingHeaderAbsolutePath)) {
105
+ fs.mkdirSync(path.dirname(bridgingHeaderAbsolutePath), { recursive: true });
106
+ fs.writeFileSync(bridgingHeaderAbsolutePath, '#import <CodePush/CodePush.h>\n');
107
+ console.log(`log: Created bridging header at ${bridgingHeaderAbsolutePath}`);
108
+ const groupKey = myProj.findPBXGroupKey({ name: projectName });
109
+ myProj.addHeaderFile(bridgingHeaderRelativePath, { public: true }, groupKey);
110
+ } else {
111
+ const headerContent = fs.readFileSync(bridgingHeaderAbsolutePath, 'utf-8');
112
+ if (!headerContent.includes('#import <CodePush/CodePush.h>')) {
113
+ fs.appendFileSync(bridgingHeaderAbsolutePath, '\n#import <CodePush/CodePush.h>\n');
114
+ console.log(`log: Updated bridging header at ${bridgingHeaderAbsolutePath}`);
115
+ }
116
+ }
117
+
118
+ fs.writeFileSync(projectPath, myProj.writeSync());
119
+ console.log('log: Updated Xcode project with bridging header path.');
120
+ resolve(bridgingHeaderAbsolutePath);
121
+ });
122
+ });
123
+ }
@@ -0,0 +1,128 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { initAndroid, modifyMainApplicationKt } from "../initAndroid.js";
4
+ import { jest, expect, describe, it } from "@jest/globals";
5
+
6
+ const tempDir = path.join(__dirname, 'temp');
7
+
8
+ // https://github.com/react-native-community/template/blob/0.80.2/template/android/app/src/main/java/com/helloworld/MainApplication.kt
9
+ const ktTemplate = `
10
+ package com.helloworld
11
+
12
+ import android.app.Application
13
+ import com.facebook.react.PackageList
14
+ import com.facebook.react.ReactApplication
15
+ import com.facebook.react.ReactHost
16
+ import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
17
+ import com.facebook.react.ReactNativeHost
18
+ import com.facebook.react.ReactPackage
19
+ import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
20
+ import com.facebook.react.defaults.DefaultReactNativeHost
21
+
22
+ class MainApplication : Application(), ReactApplication {
23
+
24
+ override val reactNativeHost: ReactNativeHost =
25
+ object : DefaultReactNativeHost(this) {
26
+ override fun getPackages(): List<ReactPackage> =
27
+ PackageList(this).packages.apply {
28
+ // Packages that cannot be autolinked yet can be added manually here, for example:
29
+ // add(MyReactNativePackage())
30
+ }
31
+
32
+ override fun getJSMainModuleName(): String = "index"
33
+
34
+ override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
35
+
36
+ override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
37
+ override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
38
+ }
39
+
40
+ override val reactHost: ReactHost
41
+ get() = getDefaultReactHost(applicationContext, reactNativeHost)
42
+
43
+ override fun onCreate() {
44
+ super.onCreate()
45
+ loadReactNative(this)
46
+ }
47
+ }
48
+ `;
49
+
50
+ // https://github.com/react-native-community/template/blob/0.82.1/template/android/app/src/main/java/com/helloworld/MainApplication.kt
51
+ const ktRN82Template = `
52
+ package com.helloworld
53
+
54
+ import android.app.Application
55
+ import com.facebook.react.PackageList
56
+ import com.facebook.react.ReactApplication
57
+ import com.facebook.react.ReactHost
58
+ import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
59
+ import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
60
+
61
+ class MainApplication : Application(), ReactApplication {
62
+
63
+ override val reactHost: ReactHost by lazy {
64
+ getDefaultReactHost(
65
+ context = applicationContext,
66
+ packageList =
67
+ PackageList(this).packages.apply {
68
+ // Packages that cannot be autolinked yet can be added manually here, for example:
69
+ // add(MyReactNativePackage())
70
+ },
71
+ )
72
+ }
73
+
74
+ override fun onCreate() {
75
+ super.onCreate()
76
+ loadReactNative(this)
77
+ }
78
+ }
79
+ `;
80
+
81
+ describe('Android init command', () => {
82
+ it('should correctly modify Kotlin MainApplication content', () => {
83
+ const modifiedContent = modifyMainApplicationKt(ktTemplate);
84
+ expect(modifiedContent).toContain('import com.microsoft.codepush.react.CodePush');
85
+ expect(modifiedContent).toContain('override fun getJSBundleFile(): String = CodePush.getJSBundleFile()');
86
+ });
87
+
88
+ it('should insert jsBundleFilePath argument for RN 0.82 style MainApplication', () => {
89
+ const modifiedContent = modifyMainApplicationKt(ktRN82Template);
90
+
91
+ expect(modifiedContent).toContain('import com.microsoft.codepush.react.CodePush');
92
+ expect(modifiedContent).toContain('jsBundleFilePath = CodePush.getJSBundleFile()');
93
+
94
+ const packageListIndex = modifiedContent.indexOf('packageList =');
95
+ const jsBundleIndex = modifiedContent.indexOf('jsBundleFilePath = CodePush.getJSBundleFile()');
96
+ expect(jsBundleIndex).toBeGreaterThan(packageListIndex);
97
+ });
98
+
99
+ it('should log a message and exit if MainApplication.java is found', async () => {
100
+ const originalCwd = process.cwd();
101
+
102
+ fs.mkdirSync(tempDir, { recursive: true });
103
+ process.chdir(tempDir);
104
+
105
+ // Arrange
106
+ const javaAppDir = path.join(tempDir, 'android', 'app', 'src', 'main', 'java', 'com', 'helloworld');
107
+ fs.mkdirSync(javaAppDir, { recursive: true });
108
+ const javaFilePath = path.join(javaAppDir, 'MainApplication.java');
109
+ const originalContent = '// Java file content';
110
+ fs.writeFileSync(javaFilePath, originalContent);
111
+
112
+ const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {
113
+ });
114
+
115
+ // Act
116
+ await initAndroid();
117
+
118
+ // Assert
119
+ expect(consoleSpy).toHaveBeenCalledWith('log: MainApplication.java is not supported. Please migrate to MainApplication.kt.');
120
+ const finalContent = fs.readFileSync(javaFilePath, 'utf-8');
121
+ expect(finalContent).toBe(originalContent); // Ensure file is not modified
122
+
123
+ consoleSpy.mockRestore();
124
+
125
+ process.chdir(originalCwd);
126
+ fs.rmSync(tempDir, { recursive: true, force: true });
127
+ });
128
+ });
@@ -0,0 +1,99 @@
1
+ import { modifyObjectiveCAppDelegate, modifySwiftAppDelegate } from "../initIos.js";
2
+ import { expect, describe, it} from "@jest/globals";
3
+
4
+ // https://github.com/react-native-community/template/blob/0.80.2/template/ios/HelloWorld/AppDelegate.swift
5
+ const swiftTemplate = `
6
+ import UIKit
7
+ import React
8
+ import React_RCTAppDelegate
9
+ import ReactAppDependencyProvider
10
+
11
+ @main
12
+ class AppDelegate: UIResponder, UIApplicationDelegate {
13
+ var window: UIWindow?
14
+ var reactNativeDelegate: ReactNativeDelegate?
15
+ var reactNativeFactory: RCTReactNativeFactory?
16
+
17
+ func application(
18
+ _ application: UIApplication,
19
+ didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
20
+ ) -> Bool {
21
+ let delegate = ReactNativeDelegate()
22
+ let factory = RCTReactNativeFactory(delegate: delegate)
23
+ delegate.dependencyProvider = RCTAppDependencyProvider()
24
+ reactNativeDelegate = delegate
25
+ reactNativeFactory = factory
26
+ window = UIWindow(frame: UIScreen.main.bounds)
27
+ factory.startReactNative(
28
+ withModuleName: "HelloWorld",
29
+ in: window,
30
+ launchOptions: launchOptions
31
+ )
32
+ return true
33
+ }
34
+ }
35
+
36
+ class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate {
37
+ override func sourceURL(for bridge: RCTBridge) -> URL? {
38
+ self.bundleURL()
39
+ }
40
+
41
+ override func bundleURL() -> URL? {
42
+ #if DEBUG
43
+ RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
44
+ #else
45
+ Bundle.main.url(forResource: "main", withExtension: "jsbundle")
46
+ #endif
47
+ }
48
+ }
49
+ `;
50
+
51
+ // https://github.com/react-native-community/template/blob/0.76.9/template/ios/HelloWorld/AppDelegate.mm
52
+ const objcTemplate = `
53
+ #import "AppDelegate.h"
54
+
55
+ #import <React/RCTBundleURLProvider.h>
56
+
57
+ @implementation AppDelegate
58
+
59
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
60
+ {
61
+ self.moduleName = @"HelloWorld";
62
+ // You can add your custom initial props in the dictionary below.
63
+ // They will be passed down to the ViewController used by React Native.
64
+ self.initialProps = @{};
65
+
66
+ return [super application:application didFinishLaunchingWithOptions:launchOptions];
67
+ }
68
+
69
+ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
70
+ {
71
+ return [self bundleURL];
72
+ }
73
+
74
+ - (NSURL *)bundleURL
75
+ {
76
+ #if DEBUG
77
+ return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
78
+ #else
79
+ return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
80
+ #endif
81
+ }
82
+
83
+ @end
84
+ `;
85
+
86
+ describe('iOS init command - pure functions', () => {
87
+ it('should correctly modify Swift AppDelegate content', () => {
88
+ const modifiedContent = modifySwiftAppDelegate(swiftTemplate);
89
+ expect(modifiedContent).toContain('CodePush.bundleURL()');
90
+ expect(modifiedContent).not.toContain('Bundle.main.url(forResource: "main", withExtension: "jsbundle")');
91
+ });
92
+
93
+ it('should correctly modify Objective-C AppDelegate content', () => {
94
+ const modifiedContent = modifyObjectiveCAppDelegate(objcTemplate);
95
+ expect(modifiedContent).toContain('#import <CodePush/CodePush.h>');
96
+ expect(modifiedContent).toContain('[CodePush bundleURL]');
97
+ expect(modifiedContent).not.toContain('[[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];');
98
+ });
99
+ });