@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,29 @@
1
+ const { program, Option } = require("commander");
2
+ const { findAndReadConfigFile } = require("../../utils/fsUtils");
3
+ const { CONFIG_FILE_NAME } = require('../../constant');
4
+
5
+ program.command('show-history')
6
+ .description('Retrieves and prints the release history of a specific binary version.\n`getReleaseHistory` function should be implemented in the config file.')
7
+ .requiredOption('-b, --binary-version <string>', '(Required) The target binary version for retrieving the release history.')
8
+ .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
9
+ .option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
10
+ .option('-c, --config <path>', 'configuration file name (JS/TS)', CONFIG_FILE_NAME)
11
+ /**
12
+ * @param {Object} options
13
+ * @param {string} options.binaryVersion
14
+ * @param {string} options.platform
15
+ * @param {string} options.identifier
16
+ * @param {string} options.config
17
+ * @return {void}
18
+ */
19
+ .action(async (options) => {
20
+ const config = findAndReadConfigFile(process.cwd(), options.config);
21
+
22
+ const releaseHistory = await config.getReleaseHistory(
23
+ options.binaryVersion,
24
+ options.platform,
25
+ options.identifier
26
+ );
27
+
28
+ console.log(JSON.stringify(releaseHistory, null, 2));
29
+ });
@@ -0,0 +1,50 @@
1
+ const { program, Option } = require("commander");
2
+ const { findAndReadConfigFile } = require("../../utils/fsUtils");
3
+ const { updateReleaseHistory } = require("./updateReleaseHistory");
4
+ const { CONFIG_FILE_NAME } = require('../../constant');
5
+
6
+ program.command('update-history')
7
+ .description('Updates the release history for a specific binary version.\n`getReleaseHistory`, `setReleaseHistory` functions should be implemented in the config file.')
8
+ .requiredOption('-v, --app-version <string>', '(Required) The app version for which update information is to be modified.')
9
+ .requiredOption('-b, --binary-version <string>', '(Required) The target binary version of the app for which update information is to be modified.')
10
+ .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
11
+ .option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
12
+ .option('-c, --config <path>', 'set config file name (JS/TS)', CONFIG_FILE_NAME)
13
+ .option('-m, --mandatory <bool>', 'make the release to be mandatory', parseBoolean, undefined)
14
+ .option('-e, --enable <bool>', 'make the release to be enabled', parseBoolean, undefined)
15
+ /**
16
+ * @param {Object} options
17
+ * @param {string} options.appVersion
18
+ * @param {string} options.binaryVersion
19
+ * @param {string} options.platform
20
+ * @param {string} options.identifier
21
+ * @param {string} options.config
22
+ * @param {string} options.mandatory
23
+ * @param {string} options.enable
24
+ * @return {void}
25
+ */
26
+ .action(async (options) => {
27
+ const config = findAndReadConfigFile(process.cwd(), options.config);
28
+
29
+ if (typeof options.mandatory !== "boolean" && typeof options.enable !== "boolean") {
30
+ console.error('No options specified. Exiting the program.')
31
+ process.exit(1)
32
+ }
33
+
34
+ await updateReleaseHistory(
35
+ options.appVersion,
36
+ options.binaryVersion,
37
+ config.getReleaseHistory,
38
+ config.setReleaseHistory,
39
+ options.platform,
40
+ options.identifier,
41
+ options.mandatory,
42
+ options.enable,
43
+ )
44
+ });
45
+
46
+ function parseBoolean(value) {
47
+ if (value === 'true') return true;
48
+ if (value === 'false') return false;
49
+ else return undefined;
50
+ }
@@ -0,0 +1,62 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ /**
5
+ *
6
+ * @param appVersion {string}
7
+ * @param binaryVersion {string}
8
+ * @param getReleaseHistory {
9
+ * function(
10
+ * targetBinaryVersion: string,
11
+ * platform: string,
12
+ * identifier?: string
13
+ * ): Promise<ReleaseHistoryInterface>}
14
+ * @param setReleaseHistory {
15
+ * function(
16
+ * targetBinaryVersion: string,
17
+ * jsonFilePath: string,
18
+ * releaseInfo: ReleaseHistoryInterface,
19
+ * platform: string,
20
+ * identifier?: string
21
+ * ): Promise<void>}
22
+ * @param platform {"ios" | "android"}
23
+ * @param identifier {string?}
24
+ * @param mandatory {boolean?}
25
+ * @param enable {boolean?}
26
+ * @returns {Promise<void>}
27
+ */
28
+ async function updateReleaseHistory(
29
+ appVersion,
30
+ binaryVersion,
31
+ getReleaseHistory,
32
+ setReleaseHistory,
33
+ platform,
34
+ identifier,
35
+ mandatory,
36
+ enable,
37
+ ) {
38
+ const releaseHistory = await getReleaseHistory(binaryVersion, platform, identifier);
39
+
40
+ const updateInfo = releaseHistory[appVersion]
41
+ if (!updateInfo) throw new Error(`v${appVersion} is not released`)
42
+
43
+ if (typeof mandatory === "boolean") updateInfo.mandatory = mandatory;
44
+ if (typeof enable === "boolean") updateInfo.enabled = enable;
45
+
46
+ try {
47
+ const JSON_FILE_NAME = `${binaryVersion}.json`;
48
+ const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME);
49
+
50
+ console.log(`log: creating JSON file... ("${JSON_FILE_NAME}")\n`, JSON.stringify(releaseHistory, null, 2));
51
+ fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(releaseHistory));
52
+
53
+ await setReleaseHistory(binaryVersion, JSON_FILE_PATH, releaseHistory, platform, identifier)
54
+
55
+ fs.unlinkSync(JSON_FILE_PATH);
56
+ } catch (error) {
57
+ console.error('Error occurred while updating history:', error);
58
+ process.exit(1)
59
+ }
60
+ }
61
+
62
+ module.exports = { updateReleaseHistory: updateReleaseHistory }
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ CONFIG_FILE_NAME: "code-push.config.ts",
3
+ OUTPUT_BUNDLE_DIR: "bundleOutput",
4
+ ROOT_OUTPUT_DIR: "build",
5
+ ENTRY_FILE: "index.ts",
6
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * code based on appcenter-cli
3
+ */
4
+
5
+ const os = require('os');
6
+
7
+ /**
8
+ * Return the path of the temporary directory for react-native bundling
9
+ *
10
+ * @return {string}
11
+ */
12
+ function getReactTempDir() {
13
+ return `${os.tmpdir()}/react-*`;
14
+ }
15
+
16
+ module.exports = { getReactTempDir };
@@ -0,0 +1,28 @@
1
+ const path = require('path');
2
+ const shell = require('shelljs');
3
+ const zip = require('../utils/zip');
4
+ const {generatePackageHashFromDirectory} = require('../utils/hash-utils');
5
+
6
+ /**
7
+ * Create a CodePush bundle file and return the information.
8
+ *
9
+ * @param contentsPath {string} The directory path containing the contents to be made into a CodePush bundle (usually the 'build/CodePush' directory))
10
+ * @param bundleDirectory {string} The directory path to save the CodePush bundle file
11
+ * @return {Promise<{ bundleFileName: string }>}
12
+ */
13
+ async function makeCodePushBundle(contentsPath, bundleDirectory) {
14
+ const updateContentsZipPath = await zip(contentsPath);
15
+
16
+ const packageHash = await generatePackageHashFromDirectory(contentsPath, path.join(contentsPath, '..'));
17
+
18
+ shell.mkdir('-p', `./${bundleDirectory}`);
19
+ shell.mv(updateContentsZipPath, `./${bundleDirectory}/${packageHash}`);
20
+
21
+ return {
22
+ // To allow the "release" command to get the file and hash value from the result of the "bundle" command,
23
+ // use the hash value as the name of the file.
24
+ bundleFileName: packageHash,
25
+ };
26
+ }
27
+
28
+ module.exports = { makeCodePushBundle };
@@ -0,0 +1,12 @@
1
+ const shell = require('shelljs');
2
+
3
+ /**
4
+ * @param deleteDirs {string[]} Directories to delete
5
+ * @param makeDir {string} Directory path to create
6
+ */
7
+ function prepareToBundleJS({ deleteDirs, makeDir }) {
8
+ shell.rm('-rf', deleteDirs);
9
+ shell.mkdir('-p', makeDir);
10
+ }
11
+
12
+ module.exports = { prepareToBundleJS };
@@ -0,0 +1,213 @@
1
+ /**
2
+ * code based on appcenter-cli
3
+ */
4
+
5
+ const childProcess = require('child_process');
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const shell = require('shelljs');
9
+
10
+ /**
11
+ * Run Hermes compile CLI command
12
+ *
13
+ * @param bundleName {string} JS bundle file name
14
+ * @param outputPath {string} Path to output .hbc file
15
+ * @param sourcemapOutput {string} Path to output sourcemap file (Warning: if sourcemapOutput points to the outputPath, the sourcemap will be included in the CodePush bundle and increase the deployment size)
16
+ * @param extraHermesFlags {string[]} Additional options to pass to `hermesc` command
17
+ * @return {Promise<void>}
18
+ */
19
+ async function runHermesEmitBinaryCommand(
20
+ bundleName,
21
+ outputPath,
22
+ sourcemapOutput,
23
+ extraHermesFlags = [],
24
+ ) {
25
+ /**
26
+ * @type {string[]}
27
+ */
28
+ const hermesArgs = [
29
+ '-emit-binary',
30
+ '-out',
31
+ path.join(outputPath, bundleName + '.hbc'),
32
+ path.join(outputPath, bundleName),
33
+ ...extraHermesFlags,
34
+ ];
35
+ if (sourcemapOutput) {
36
+ hermesArgs.push('-output-source-map');
37
+ }
38
+
39
+ console.log('Converting JS bundle to byte code via Hermes, running command:\n');
40
+
41
+ return new Promise((resolve, reject) => {
42
+ try {
43
+ const hermesCommand = getHermesCommand();
44
+
45
+ const disableAllWarningsArg = '-w';
46
+ shell.exec(`${hermesCommand} ${hermesArgs.join(' ')} ${disableAllWarningsArg}`);
47
+
48
+ // Copy HBC bundle to overwrite JS bundle
49
+ const source = path.join(outputPath, bundleName + '.hbc');
50
+ const destination = path.join(outputPath, bundleName);
51
+ shell.cp(source, destination);
52
+ shell.rm(source);
53
+ resolve();
54
+ } catch (e) {
55
+ reject(e);
56
+ }
57
+ }).then(() => {
58
+ if (!sourcemapOutput) {
59
+ // skip source map compose if source map is not enabled
60
+ return;
61
+ }
62
+
63
+ // compose-source-maps.js file path
64
+ const composeSourceMapsPath = getComposeSourceMapsPath();
65
+ if (composeSourceMapsPath === null) {
66
+ throw new Error('react-native compose-source-maps.js scripts is not found');
67
+ }
68
+
69
+ const jsCompilerSourceMapFile = path.join(outputPath, bundleName + '.hbc' + '.map');
70
+ if (!fs.existsSync(jsCompilerSourceMapFile)) {
71
+ throw new Error(`sourcemap file ${jsCompilerSourceMapFile} is not found`);
72
+ }
73
+
74
+ return new Promise((resolve, reject) => {
75
+ const composeSourceMapsArgs = [
76
+ composeSourceMapsPath,
77
+ sourcemapOutput,
78
+ jsCompilerSourceMapFile,
79
+ '-o',
80
+ sourcemapOutput,
81
+ ];
82
+ const composeSourceMapsProcess = childProcess.spawn('node', composeSourceMapsArgs);
83
+ console.log(`${composeSourceMapsPath} ${composeSourceMapsArgs.join(' ')}`);
84
+
85
+ composeSourceMapsProcess.stdout.on('data', (data) => {
86
+ console.log(data.toString().trim());
87
+ });
88
+
89
+ composeSourceMapsProcess.stderr.on('data', (data) => {
90
+ console.error(data.toString().trim());
91
+ });
92
+
93
+ composeSourceMapsProcess.on('close', (exitCode, signal) => {
94
+ if (exitCode !== 0) {
95
+ reject(new Error(`"compose-source-maps" command failed (exitCode=${exitCode}, signal=${signal}).`));
96
+ }
97
+
98
+ // Delete the HBC sourceMap, otherwise it will be included in 'code-push' bundle as well
99
+ fs.unlink(jsCompilerSourceMapFile, (err) => {
100
+ if (err != null) {
101
+ console.error(err);
102
+ reject(err);
103
+ }
104
+
105
+ resolve();
106
+ });
107
+ });
108
+ });
109
+ });
110
+ }
111
+
112
+ /**
113
+ * @return {string}
114
+ */
115
+ function getHermesCommand() {
116
+ /**
117
+ * @type {(file: string) => boolean}
118
+ */
119
+ const fileExists = (file) => {
120
+ try {
121
+ return fs.statSync(file).isFile();
122
+ } catch (e) {
123
+ return false;
124
+ }
125
+ };
126
+ // Hermes is bundled with react-native since 0.69
127
+ const bundledHermesEngine = path.join(
128
+ getReactNativePackagePath(),
129
+ 'sdks',
130
+ 'hermesc',
131
+ getHermesOSBin(),
132
+ getHermesOSExe(),
133
+ );
134
+ if (fileExists(bundledHermesEngine)) {
135
+ return bundledHermesEngine;
136
+ }
137
+ throw new Error('Hermes engine binary not found. Please upgrade to react-native 0.69 or later');
138
+ }
139
+
140
+ /**
141
+ * @return {string}
142
+ */
143
+ function getHermesOSBin() {
144
+ switch (process.platform) {
145
+ case 'win32':
146
+ return 'win64-bin';
147
+ case 'darwin':
148
+ return 'osx-bin';
149
+ case 'freebsd':
150
+ case 'linux':
151
+ case 'sunos':
152
+ default:
153
+ return 'linux64-bin';
154
+ }
155
+ }
156
+
157
+ /**
158
+ * @return {string}
159
+ */
160
+ function getHermesOSExe() {
161
+ const hermesExecutableName = 'hermesc';
162
+ switch (process.platform) {
163
+ case 'win32':
164
+ return hermesExecutableName + '.exe';
165
+ default:
166
+ return hermesExecutableName;
167
+ }
168
+ }
169
+
170
+ /**
171
+ * @return {string | null}
172
+ */
173
+ function getComposeSourceMapsPath() {
174
+ // detect if compose-source-maps.js script exists
175
+ const composeSourceMaps = path.join(getReactNativePackagePath(), 'scripts', 'compose-source-maps.js');
176
+ if (fs.existsSync(composeSourceMaps)) {
177
+ return composeSourceMaps;
178
+ }
179
+ return null;
180
+ }
181
+
182
+ /**
183
+ * @return {string}
184
+ */
185
+ function getReactNativePackagePath() {
186
+ const result = childProcess.spawnSync('node', [
187
+ '--print',
188
+ "require.resolve('react-native/package.json')",
189
+ ]);
190
+ const packagePath = path.dirname(result.stdout.toString());
191
+ if (result.status === 0 && directoryExistsSync(packagePath)) {
192
+ return packagePath;
193
+ }
194
+
195
+ return path.join('node_modules', 'react-native');
196
+ }
197
+
198
+ /**
199
+ * @param dirname {string}
200
+ * @return {boolean}
201
+ */
202
+ function directoryExistsSync(dirname) {
203
+ try {
204
+ return fs.statSync(dirname).isDirectory();
205
+ } catch (err) {
206
+ if (err.code !== 'ENOENT') {
207
+ throw err;
208
+ }
209
+ }
210
+ return false;
211
+ }
212
+
213
+ module.exports = { runHermesEmitBinaryCommand };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * code based on appcenter-cli
3
+ */
4
+
5
+ const path = require('path');
6
+ const shell = require('shelljs');
7
+
8
+ /**
9
+ * Run `react-native bundle` CLI command
10
+ *
11
+ * @param bundleName {string} JS bundle file name
12
+ * @param entryFile {string} App code entry file name (default: index.ts)
13
+ * @param outputPath {string} Path to output JS bundle file and assets
14
+ * @param platform {string} Platform (ios | android)
15
+ * @param sourcemapOutput {string} Path to output sourcemap file (Warning: if sourcemapOutput points to the outputPath, the sourcemap will be included in the CodePush bundle and increase the deployment size)
16
+ * @param extraBundlerOptions {string[]} Additional options to pass to `react-native bundle` command
17
+ * @return {void}
18
+ */
19
+ function runReactNativeBundleCommand(
20
+ bundleName,
21
+ outputPath,
22
+ platform,
23
+ sourcemapOutput,
24
+ entryFile,
25
+ extraBundlerOptions = [],
26
+ ) {
27
+ /**
28
+ * @return {string}
29
+ */
30
+ function getCliPath() {
31
+ return path.join('node_modules', '.bin', 'react-native');
32
+ }
33
+
34
+ /**
35
+ * @type {string[]}
36
+ */
37
+ const reactNativeBundleArgs = [
38
+ 'bundle',
39
+ '--assets-dest',
40
+ outputPath,
41
+ '--bundle-output',
42
+ path.join(outputPath, bundleName),
43
+ '--dev',
44
+ 'false',
45
+ '--entry-file',
46
+ entryFile,
47
+ '--platform',
48
+ platform,
49
+ '--sourcemap-output',
50
+ sourcemapOutput,
51
+ ...extraBundlerOptions,
52
+ ];
53
+
54
+ console.log('Running "react-native bundle" command:\n');
55
+
56
+ shell.exec(`${getCliPath()} ${reactNativeBundleArgs.join(' ')}`);
57
+ }
58
+
59
+ module.exports = { runReactNativeBundleCommand };
package/cli/index.js ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { program } = require('commander')
4
+ const shell = require('shelljs')
5
+ const { showLogo } = require('./utils/showLogo')
6
+
7
+ shell.set('-e')
8
+ shell.set('+v')
9
+
10
+ program
11
+ .name('npx code-push')
12
+ .description('Command line interface for @algocare/react-native-code-push')
13
+ .version('1.0.0')
14
+ .action(() => {
15
+ showLogo()
16
+ })
17
+
18
+ /**
19
+ * npx code-push bundle
20
+ */
21
+ require('./commands/bundleCommand')
22
+
23
+ /**
24
+ * npx code-push create-history
25
+ */
26
+ require('./commands/createHistoryCommand')
27
+
28
+ /**
29
+ * npx code-push update-history
30
+ */
31
+ require('./commands/updateHistoryCommand')
32
+
33
+ /**
34
+ * npx code-push release
35
+ */
36
+ require('./commands/releaseCommand')
37
+
38
+ /**
39
+ * npx code-push show-history
40
+ */
41
+ require('./commands/showHistoryCommand')
42
+
43
+ program.parse()
@@ -0,0 +1,42 @@
1
+ /**
2
+ * code based on appcenter-cli
3
+ */
4
+
5
+ const fs = require('fs');
6
+
7
+ /**
8
+ *
9
+ * @param path {string}
10
+ * @return {boolean}
11
+ */
12
+ function isDirectory(path) {
13
+ return fs.statSync(path).isDirectory();
14
+ }
15
+
16
+ /**
17
+ *
18
+ * @param length {number}
19
+ * @return {string}
20
+ */
21
+ function generateRandomFilename(length) {
22
+ let filename = '';
23
+ const validChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
24
+
25
+ for (let i = 0; i < length; i++) {
26
+ filename += validChar.charAt(Math.floor(Math.random() * validChar.length));
27
+ }
28
+
29
+ return filename;
30
+ }
31
+
32
+ /**
33
+ *
34
+ * @param filePath {string}
35
+ * @return {string}
36
+ */
37
+ function normalizePath(filePath) {
38
+ //replace all backslashes coming from cli running on windows machines by slashes
39
+ return filePath.replace(/\\/g, '/');
40
+ }
41
+
42
+ module.exports = { isDirectory, generateRandomFilename, normalizePath };
@@ -0,0 +1,49 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ /**
5
+ * allows to require a config file with .ts extension
6
+ * @param filePath {string}
7
+ * @returns {*} FIXME type
8
+ */
9
+ function requireConfig(filePath) {
10
+ const ext = path.extname(filePath);
11
+
12
+ if (ext === '.ts') {
13
+ try {
14
+ require('ts-node/register');
15
+ } catch {
16
+ console.error('ts-node not found. Please install ts-node as a devDependency.');
17
+ process.exit(1);
18
+ }
19
+ } else if (ext === '.js') {
20
+ // do nothing
21
+ } else {
22
+ throw new Error(`Unsupported file extension: ${ext}`);
23
+ }
24
+
25
+ return require(filePath);
26
+ }
27
+
28
+ /**
29
+ * @param startDir {string}
30
+ * @param configFileName {string}
31
+ * @returns {*|null} FIXME type
32
+ */
33
+ function findAndReadConfigFile(startDir, configFileName) {
34
+ let dir = startDir;
35
+
36
+ while (dir !== path.parse(dir).root) {
37
+ const configPath = path.join(dir, configFileName);
38
+ if (fs.existsSync(configPath)) {
39
+ const config = requireConfig(configPath);
40
+ return config;
41
+ }
42
+ dir = path.dirname(dir);
43
+ }
44
+
45
+ console.error(`${configFileName} not found.`);
46
+ return null;
47
+ }
48
+
49
+ module.exports = { findAndReadConfigFile };