react-native-ota-hot-update 1.0.9 → 1.1.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.
package/README.md CHANGED
@@ -122,6 +122,7 @@ The important thing: this library will control `version` by it self, need always
122
122
  | updateFail(message: string) | No | Callback | Will trigger when install update failed |
123
123
  | restartAfterInstall | No | boolean | default is `false`, if `true` will restart the app after install success to apply the new change |
124
124
  | progress | No | void | A callback to show progress when downloading bundle |
125
+ | extensionBundle | No | string | extension of bundle js file, default is .bundle, for expo project you might set .hbc |
125
126
 
126
127
  ## DownloadManager
127
128
 
@@ -50,7 +50,7 @@ public class HotUpdateModule extends ReactContextBaseJavaModule {
50
50
  return false;
51
51
  }
52
52
  }
53
- private String unzip(File zipFile) {
53
+ private String unzip(File zipFile, String extension) {
54
54
  File destDir = zipFile.getParentFile(); // Directory of the zip file
55
55
 
56
56
  String bundleFilePath = null;
@@ -78,7 +78,7 @@ public class HotUpdateModule extends ReactContextBaseJavaModule {
78
78
  }
79
79
  }
80
80
  }
81
- if (newFile.getAbsolutePath().contains(".bundle")) {
81
+ if (newFile.getAbsolutePath().contains(extension)) {
82
82
  bundleFilePath = newFile.getAbsolutePath();
83
83
  }
84
84
  }
@@ -90,12 +90,12 @@ public class HotUpdateModule extends ReactContextBaseJavaModule {
90
90
  }
91
91
 
92
92
  @ReactMethod
93
- public void setupBundlePath(String path, Promise promise) {
93
+ public void setupBundlePath(String path, String extension, Promise promise) {
94
94
  if (path != null) {
95
95
  deleteOldBundleIfneeded();
96
96
  File file = new File(path);
97
97
  if (file.exists() && file.isFile()) {
98
- String fileUnzip = unzip(file);
98
+ String fileUnzip = unzip(file, extension != null ? extension : ".bundle");
99
99
  Log.d("setupBundlePath: ", fileUnzip);
100
100
  if (fileUnzip != null) {
101
101
  file.delete();
package/ios/RNhotupdate.m CHANGED
@@ -97,7 +97,7 @@ RCT_EXPORT_MODULE()
97
97
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
98
98
  }
99
99
  }
100
- - (NSString *)searchForJsBundleInDirectory:(NSString *)directoryPath {
100
+ - (NSString *)searchForJsBundleInDirectory:(NSString *)directoryPath extension:(NSString *)extension {
101
101
  NSFileManager *fileManager = [NSFileManager defaultManager];
102
102
  NSError *error;
103
103
 
@@ -114,11 +114,11 @@ RCT_EXPORT_MODULE()
114
114
  if ([fileManager fileExistsAtPath:filePath isDirectory:&isDirectory]) {
115
115
  if (isDirectory) {
116
116
  // Recursively search in subdirectories
117
- NSString *foundPath = [self searchForJsBundleInDirectory:filePath];
117
+ NSString *foundPath = [self searchForJsBundleInDirectory:filePath extension:extension];
118
118
  if (foundPath) {
119
119
  return foundPath;
120
120
  }
121
- } else if ([filePath hasSuffix:@".jsbundle"]) {
121
+ } else if ([filePath hasSuffix:extension]) {
122
122
  // Return the path if it's a .jsbundle file
123
123
  return filePath;
124
124
  }
@@ -127,7 +127,7 @@ RCT_EXPORT_MODULE()
127
127
 
128
128
  return nil;
129
129
  }
130
- - (NSString *)unzipFileAtPath:(NSString *)zipFilePath {
130
+ - (NSString *)unzipFileAtPath:(NSString *)zipFilePath extension:(NSString *)extension {
131
131
  // Define the directory where the files will be extracted
132
132
  NSString *extractedFolderPath = [[zipFilePath stringByDeletingPathExtension] stringByAppendingPathExtension:@"unzip"];
133
133
 
@@ -151,7 +151,7 @@ RCT_EXPORT_MODULE()
151
151
  return nil;
152
152
  }
153
153
  // Find .jsbundle files in the extracted directory
154
- NSString *jsbundleFilePath = [self searchForJsBundleInDirectory:extractedFolderPath];
154
+ NSString *jsbundleFilePath = [self searchForJsBundleInDirectory:extractedFolderPath extension:extension];
155
155
 
156
156
  // Delete the zip file after extraction
157
157
  NSError *removeError = nil;
@@ -165,11 +165,11 @@ RCT_EXPORT_MODULE()
165
165
  }
166
166
 
167
167
  // Expose setupBundlePath method to JavaScript
168
- RCT_EXPORT_METHOD(setupBundlePath:(NSString *)path withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject) {
168
+ RCT_EXPORT_METHOD(setupBundlePath:(NSString *)path extension:(NSString *)extension withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject) {
169
169
  if ([self isFilePathValid:path]) {
170
170
  [self removeBundleIfNeeded];
171
171
  //Unzip file
172
- NSString *extractedFilePath = [self unzipFileAtPath:path];
172
+ NSString *extractedFilePath = [self unzipFileAtPath:path extension:(extension != nil) ? extension : @".jsbundle"];
173
173
  NSLog(@"file extraction----- %@", extractedFilePath);
174
174
  if (extractedFilePath) {
175
175
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ota-hot-update",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "Hot update for react native",
5
5
  "main": "src/index",
6
6
  "repository": "https://github.com/vantuan88291/react-native-ota-hot-update",
package/src/index.tsx CHANGED
@@ -1,10 +1,10 @@
1
1
  import { NativeModules, Platform } from 'react-native';
2
2
  import {DownloadManager} from './download';
3
3
  const LINKING_ERROR =
4
- 'The package \'rn-hotupdate\' doesn\'t seem to be linked. Make sure: \n\n' +
5
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6
- '- You rebuilt the app after installing the package\n' +
7
- '- You are not using Expo Go\n';
4
+ 'The package \'rn-hotupdate\' doesn\'t seem to be linked. Make sure: \n\n' +
5
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6
+ '- You rebuilt the app after installing the package\n' +
7
+ '- You are not using Expo Go\n';
8
8
 
9
9
  export interface UpdateOption {
10
10
  headers?: object
@@ -12,16 +12,17 @@ export interface UpdateOption {
12
12
  updateSuccess?(): void
13
13
  updateFail?(message?: string): void
14
14
  restartAfterInstall?: boolean
15
+ extensionBundle?: string,
15
16
  }
16
17
  const RNhotupdate = NativeModules.RNhotupdate
17
- ? NativeModules.RNhotupdate
18
- : new Proxy(
19
- {},
20
- {
21
- get() {
22
- throw new Error(LINKING_ERROR);
23
- },
24
- }
18
+ ? NativeModules.RNhotupdate
19
+ : new Proxy(
20
+ {},
21
+ {
22
+ get() {
23
+ throw new Error(LINKING_ERROR);
24
+ },
25
+ }
25
26
  );
26
27
  const downloadBundleFile = async (downloadManager: DownloadManager, uri: string, headers?: object, callback?: (received: string, total: string) => void) => {
27
28
  const res = await downloadManager
@@ -38,8 +39,8 @@ const downloadBundleFile = async (downloadManager: DownloadManager, uri: string,
38
39
  });
39
40
  return res.path();
40
41
  };
41
- function setupBundlePath(path: string): Promise<boolean> {
42
- return RNhotupdate.setupBundlePath(path);
42
+ function setupBundlePath(path: string, extension?: string): Promise<boolean> {
43
+ return RNhotupdate.setupBundlePath(path, extension);
43
44
  }
44
45
  function deleteBundlePath(): Promise<boolean> {
45
46
  return RNhotupdate.deleteBundle();
@@ -90,7 +91,7 @@ async function downloadBundleUri(downloadManager: DownloadManager, uri: string,
90
91
  try {
91
92
  const path = await downloadBundleFile(downloadManager, uri, option?.headers, option?.progress);
92
93
  if (path) {
93
- setupBundlePath(path).then(success => {
94
+ setupBundlePath(path, option?.extensionBundle).then(success => {
94
95
  if (success) {
95
96
  setCurrentVersion(version);
96
97
  option?.updateSuccess?.();