@bravemobile/react-native-code-push 9.0.0-beta.0 → 9.0.0-beta.2

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.
package/CodePush.js CHANGED
@@ -61,83 +61,75 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
61
61
  };
62
62
 
63
63
  /**
64
- * `releaseHistory`
65
- * @type {ReleaseHistoryInterface}
64
+ * @type {updateChecker|undefined}
65
+ * @deprecated
66
66
  */
67
- const releaseHistory = await sharedCodePushOptions.releaseHistoryFetcher(updateRequest);
67
+ const updateChecker = sharedCodePushOptions.updateChecker;
68
+ if (updateChecker) {
69
+ const { update_info } = await updateChecker(updateRequest);
68
70
 
69
- /**
70
- * `runtimeVersion`
71
- * The version of currently running CodePush update. (It can be undefined if the app is running without CodePush update.)
72
- * @type {string|undefined}
73
- */
74
- const runtimeVersion = updateRequest.label;
71
+ return mapToRemotePackageMetadata(update_info, config.deploymentKey);
72
+ } else {
73
+ /**
74
+ * `releaseHistory`
75
+ * @type {ReleaseHistoryInterface}
76
+ */
77
+ const releaseHistory = await sharedCodePushOptions.releaseHistoryFetcher(updateRequest);
75
78
 
76
- const versioning = new SemverVersioning(releaseHistory);
79
+ /**
80
+ * `runtimeVersion`
81
+ * The version of currently running CodePush update. (It can be undefined if the app is running without CodePush update.)
82
+ * @type {string|undefined}
83
+ */
84
+ const runtimeVersion = updateRequest.label;
77
85
 
78
- const shouldRollbackToBinary = versioning.shouldRollbackToBinary(runtimeVersion)
79
- if (shouldRollbackToBinary) {
80
- // Reset to latest major version and restart
81
- CodePush.clearUpdates();
82
- CodePush.allowRestart();
83
- CodePush.restartApp();
84
- }
86
+ const versioning = new SemverVersioning(releaseHistory);
85
87
 
86
- const [latestVersion, latestReleaseInfo] = versioning.findLatestRelease();
87
- const isMandatory = versioning.checkIsMandatory(runtimeVersion);
88
+ const shouldRollbackToBinary = versioning.shouldRollbackToBinary(runtimeVersion)
89
+ if (shouldRollbackToBinary) {
90
+ // Reset to latest major version and restart
91
+ CodePush.clearUpdates();
92
+ CodePush.allowRestart();
93
+ CodePush.restartApp();
94
+ }
95
+
96
+ const [latestVersion, latestReleaseInfo] = versioning.findLatestRelease();
97
+ const isMandatory = versioning.checkIsMandatory(runtimeVersion);
88
98
 
89
- /**
90
- * Convert the update information decided from `ReleaseHistoryInterface` to be passed to the library core (original CodePush library).
91
- *
92
- * @type {UpdateCheckResponse} the interface required by the original CodePush library.
93
- */
94
- const updateInfo = {
95
- download_url: latestReleaseInfo.downloadUrl,
96
- // (`enabled` will always be true in the release information obtained from the previous process.)
97
- is_available: latestReleaseInfo.enabled,
98
- package_hash: latestReleaseInfo.packageHash,
99
- is_mandatory: isMandatory,
100
- // 이건 항상 현재 실행중인 바이너리 버전을 전달한다.
101
- // 조회한 업데이트가 현재 바이너리를 타겟하는가? 를 API 서버에서 판단한 다음, 해당 된다면 런타임 바이너리 버전을 그대로 돌려주던 것임.
102
- // 우리는 updateChecker 조회 결과가 넘어왔다면 해당 정보는 현재 런타임 바이너리에 호환됨을 전제로 하고있음.
103
- target_binary_range: updateRequest.app_version,
104
99
  /**
105
- * Retrieve the update version from the ReleaseHistory and store it in the label.
106
- * This information can be accessed at runtime through the CodePush bundle metadata.
100
+ * Convert the update information decided from `ReleaseHistoryInterface` to be passed to the library core (original CodePush library).
101
+ *
102
+ * @type {UpdateCheckResponse} the interface required by the original CodePush library.
107
103
  */
108
- label: latestVersion,
109
- // false 전달해야 정상 동작함
110
- update_app_version: false,
111
- // 그닥 쓸모 없음
112
- description: '',
113
- // 런타임에 안쓰임
114
- is_disabled: false,
115
- // 런타임에 안쓰임
116
- package_size: 0,
117
- // 런타임에 안쓰임
118
- should_run_binary_version: false,
119
- }
120
-
104
+ const updateInfo = {
105
+ download_url: latestReleaseInfo.downloadUrl,
106
+ // (`enabled` will always be true in the release information obtained from the previous process.)
107
+ is_available: latestReleaseInfo.enabled,
108
+ package_hash: latestReleaseInfo.packageHash,
109
+ is_mandatory: isMandatory,
110
+ // 이건 항상 현재 실행중인 바이너리 버전을 전달한다.
111
+ // 조회한 업데이트가 현재 바이너리를 타겟하는가? 를 API 서버에서 판단한 다음, 해당 된다면 런타임 바이너리 버전을 그대로 돌려주던 것임.
112
+ // 우리는 updateChecker 조회 결과가 넘어왔다면 해당 정보는 현재 런타임 바이너리에 호환됨을 전제로 하고있음.
113
+ target_binary_range: updateRequest.app_version,
114
+ /**
115
+ * Retrieve the update version from the ReleaseHistory and store it in the label.
116
+ * This information can be accessed at runtime through the CodePush bundle metadata.
117
+ */
118
+ label: latestVersion,
119
+ // false 전달해야 정상 동작함
120
+ update_app_version: false,
121
+ // 그닥 쓸모 없음
122
+ description: '',
123
+ // 런타임에 안쓰임
124
+ is_disabled: false,
125
+ // 런타임에 안쓰임
126
+ package_size: 0,
127
+ // 런타임에 안쓰임
128
+ should_run_binary_version: false,
129
+ }
121
130
 
122
- if (!updateInfo) {
123
- return null;
124
- } else if (!updateInfo.download_url) {
125
- return null;
126
- } else if (!updateInfo.is_available) {
127
- return null;
131
+ return mapToRemotePackageMetadata(updateInfo, config.deploymentKey);
128
132
  }
129
-
130
- // refer to `RemotePackage` type inside code-push SDK
131
- return {
132
- deploymentKey: config.deploymentKey,
133
- description: updateInfo.description ?? '',
134
- label: updateInfo.label ?? '',
135
- appVersion: updateInfo.target_binary_range ?? '',
136
- isMandatory: updateInfo.is_mandatory ?? false,
137
- packageHash: updateInfo.package_hash ?? '',
138
- packageSize: updateInfo.package_size ?? 0,
139
- downloadUrl: updateInfo.download_url ?? '',
140
- };
141
133
  } catch (error) {
142
134
  log(`An error has occurred at update checker :`, error);
143
135
  // update will not happen
@@ -182,6 +174,34 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
182
174
  }
183
175
  }
184
176
 
177
+ /**
178
+ * @param updateInfo {UpdateCheckResponse}
179
+ * @param deploymentKey {string}
180
+ * @return {RemotePackage | null}
181
+ */
182
+ function mapToRemotePackageMetadata(updateInfo, deploymentKey) {
183
+ if (!updateInfo) {
184
+ return null;
185
+ } else if (!updateInfo.download_url) {
186
+ log("download_url is missed in the release history.");
187
+ return null;
188
+ } else if (!updateInfo.is_available) {
189
+ return null;
190
+ }
191
+
192
+ // refer to `RemotePackage` type inside code-push SDK
193
+ return {
194
+ deploymentKey: deploymentKey,
195
+ description: updateInfo.description ?? '',
196
+ label: updateInfo.label ?? '',
197
+ appVersion: updateInfo.target_binary_range ?? '',
198
+ isMandatory: updateInfo.is_mandatory ?? false,
199
+ packageHash: updateInfo.package_hash ?? '',
200
+ packageSize: updateInfo.package_size ?? 0,
201
+ downloadUrl: updateInfo.download_url ?? '',
202
+ };
203
+ }
204
+
185
205
  const getConfiguration = (() => {
186
206
  let config;
187
207
  return async function getConfiguration() {
@@ -560,19 +580,35 @@ let CodePush;
560
580
  * @returns {Promise<ReleaseHistoryInterface>} The release history of the updates deployed for a specific binary version.
561
581
  */
562
582
 
583
+ /**
584
+ * @callback updateChecker
585
+ * @param {UpdateCheckRequest} updateRequest Current package information to check for updates.
586
+ * @returns {Promise<{update_info: UpdateCheckResponse}>} The result of the update check. Follows the AppCenter API response interface.
587
+ *
588
+ * @deprecated It will be removed in the next major version.
589
+ */
590
+
563
591
  /**
564
592
  * If you pass options once when calling `codePushify`, they will be shared with related functions.
565
593
  * @type {{
566
594
  * releaseHistoryFetcher: releaseHistoryFetcher | undefined,
567
- * setReleaseHistoryFetcher(releaseHistoryFetcherFunction: releaseHistoryFetcher): void,
595
+ * setReleaseHistoryFetcher(releaseHistoryFetcherFunction: releaseHistoryFetcher | undefined): void,
596
+ * updateChecker: updateChecker | undefined,
597
+ * setUpdateChecker(updateCheckerFunction: updateChecker | undefined): void,
568
598
  * }}
569
599
  */
570
600
  const sharedCodePushOptions = {
571
601
  releaseHistoryFetcher: undefined,
572
602
  setReleaseHistoryFetcher(releaseHistoryFetcherFunction) {
573
- if (!releaseHistoryFetcherFunction || typeof releaseHistoryFetcherFunction !== 'function') throw new Error('pass a function to releaseHistoryFetcher');
603
+ if (!releaseHistoryFetcherFunction || typeof releaseHistoryFetcherFunction !== 'function') throw new Error('Please implement the releaseHistoryFetcher function');
574
604
  this.releaseHistoryFetcher = releaseHistoryFetcherFunction;
575
- }
605
+ },
606
+ updateChecker: undefined,
607
+ setUpdateChecker(updateCheckerFunction) {
608
+ if (!updateCheckerFunction) return;
609
+ if (typeof updateCheckerFunction !== 'function') throw new Error('Please pass a function to updateChecker');
610
+ this.updateChecker = updateCheckerFunction;
611
+ },
576
612
  }
577
613
 
578
614
  function codePushify(options = {}) {
@@ -596,6 +632,7 @@ function codePushify(options = {}) {
596
632
  }
597
633
 
598
634
  sharedCodePushOptions.setReleaseHistoryFetcher(options.releaseHistoryFetcher);
635
+ sharedCodePushOptions.setUpdateChecker(options.updateChecker);
599
636
 
600
637
  const decorator = (RootComponent) => {
601
638
  class CodePushComponent extends React.Component {
@@ -16,6 +16,7 @@ program.command('release')
16
16
  .option('-m, --mandatory <bool>', 'make the release to be mandatory', parseBoolean, false)
17
17
  .option('--enable <bool>', 'make the release to be enabled', parseBoolean, true)
18
18
  .option('--skip-bundle <bool>', 'skip bundle process', parseBoolean, false)
19
+ .option('--skip-cleanup <bool>', 'skip cleanup process', parseBoolean, false)
19
20
  .option('--output-bundle-dir <string>', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR)
20
21
  /**
21
22
  * @param {Object} options
@@ -30,6 +31,7 @@ program.command('release')
30
31
  * @param {string} options.mandatory
31
32
  * @param {string} options.enable
32
33
  * @param {string} options.skipBundle
34
+ * @param {string} options.skipCleanup
33
35
  * @param {string} options.outputBundleDir
34
36
  * @return {void}
35
37
  */
@@ -50,6 +52,7 @@ program.command('release')
50
52
  options.mandatory,
51
53
  options.enable,
52
54
  options.skipBundle,
55
+ options.skipCleanup,
53
56
  `${options.outputPath}/${options.outputBundleDir}`,
54
57
  )
55
58
 
@@ -33,6 +33,7 @@ const { addToReleaseHistory } = require("./addToReleaseHistory");
33
33
  * @param mandatory {boolean}
34
34
  * @param enable {boolean}
35
35
  * @param skipBundle {boolean}
36
+ * @param skipCleanup {boolean}
36
37
  * @param bundleDirectory {string}
37
38
  * @return {Promise<void>}
38
39
  */
@@ -50,6 +51,7 @@ async function release(
50
51
  mandatory,
51
52
  enable,
52
53
  skipBundle,
54
+ skipCleanup,
53
55
  bundleDirectory,
54
56
  ) {
55
57
  const bundleFileName = skipBundle
@@ -80,7 +82,9 @@ async function release(
80
82
  enable,
81
83
  )
82
84
 
83
- cleanUpOutputs(outputPath);
85
+ if (!skipCleanup) {
86
+ cleanUpOutputs(outputPath);
87
+ }
84
88
  }
85
89
 
86
90
  function cleanUpOutputs(dir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bravemobile/react-native-code-push",
3
- "version": "9.0.0-beta.0",
3
+ "version": "9.0.0-beta.2",
4
4
  "description": "React Native plugin for the CodePush service",
5
5
  "main": "CodePush.js",
6
6
  "typings": "typings/react-native-code-push.d.ts",
@@ -56,8 +56,18 @@ export interface CodePushOptions extends SyncOptions {
56
56
  checkFrequency: CodePush.CheckFrequency;
57
57
  /**
58
58
  * Specifies a function to get the release history.
59
+ *
60
+ * (If you want to use `updateChecker`, pass no-op function.)
59
61
  */
60
62
  releaseHistoryFetcher: (updateRequest: UpdateCheckRequest) => Promise<ReleaseHistoryInterface>;
63
+ /**
64
+ * Specify a function to perform the update check.
65
+ * It can be used for self-hosting.
66
+ * Defaults to AppCenter update_check REST API request.
67
+ *
68
+ * @deprecated It will be removed in the next major version. Please migrate to `releaseHistoryFetcher`.
69
+ */
70
+ updateChecker?: (updateRequest: UpdateCheckRequest) => Promise<{ update_info: UpdateCheckResponse }>;
61
71
  }
62
72
 
63
73
  export interface DownloadProgress {