@hot-updater/react-native 0.0.1

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.
@@ -0,0 +1,42 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "HotUpdater"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+
14
+ s.platforms = { :ios => "11.0" }
15
+ s.source = { :git => "https://github.com/gronxb/hot-updater.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm}"
18
+ s.public_header_files = ['ios/HotUpdater/HotUpdater.h']
19
+
20
+ # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
21
+ # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
22
+ if respond_to?(:install_modules_dependencies, true)
23
+ install_modules_dependencies(s)
24
+ else
25
+ s.dependency "React-Core"
26
+
27
+ # Don't install the dependencies when we run `pod install` in the old architecture.
28
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
29
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
30
+ s.pod_target_xcconfig = {
31
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
32
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
33
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
34
+ }
35
+ s.dependency "React-Codegen"
36
+ s.dependency "RCT-Folly"
37
+ s.dependency "RCTRequired"
38
+ s.dependency "RCTTypeSafety"
39
+ s.dependency "ReactCommon/turbomodule/core"
40
+ end
41
+ end
42
+ end
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Sungyu Kang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # hot-updater (WIP)
2
+ React Native OTA solution for internal infrastructure
3
+
4
+ ## Usage
5
+ * as-is
6
+ ```objective-c
7
+ // filename: ios/MyApp/AppDelegate.mm
8
+ // ...
9
+
10
+ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
11
+ {
12
+ #if DEBUG
13
+ return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
14
+ #else
15
+ return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
16
+ #endif
17
+ }
18
+
19
+ // ...
20
+ ```
21
+
22
+ * to-be
23
+ ```objective-c
24
+ // filename: ios/MyApp/AppDelegate.mm
25
+ // ...
26
+
27
+ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
28
+ {
29
+ return [HotUpdater bundleURL];
30
+ }
31
+
32
+ / ...
33
+ ```
@@ -0,0 +1,8 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTBundleURLProvider.h>
3
+
4
+ @interface HotUpdater : NSObject <RCTBridgeModule>
5
+
6
+ + (NSURL *)bundleURL;
7
+
8
+ @end
@@ -0,0 +1,119 @@
1
+ #import "HotUpdater.h"
2
+
3
+ @implementation HotUpdater
4
+
5
+ RCT_EXPORT_MODULE();
6
+
7
+ static NSURL *_bundleURL = nil;
8
+ static dispatch_once_t setBundleURLOnceToken;
9
+
10
+ #pragma mark - Bundle URL Management
11
+
12
+ + (void)setBundleURL:(NSURL *)url {
13
+ dispatch_once(&setBundleURLOnceToken, ^{
14
+ NSString *path = [self pathFromURL:url];
15
+
16
+ if (![self downloadDataFromURL:url andSaveToPath:path]) {
17
+ return;
18
+ }
19
+
20
+ _bundleURL = [NSURL fileURLWithPath:path];
21
+ [[NSUserDefaults standardUserDefaults] setObject:[_bundleURL absoluteString] forKey:@"HotUpdaterBundleURL"];
22
+ [[NSUserDefaults standardUserDefaults] synchronize];
23
+ });
24
+ }
25
+
26
+ + (NSURL *)cachedURLFromBundle {
27
+ static dispatch_once_t onceToken;
28
+ dispatch_once(&onceToken, ^{
29
+ NSString *savedURLString = [[NSUserDefaults standardUserDefaults] objectForKey:@"HotUpdaterBundleURL"];
30
+ if (savedURLString) {
31
+ _bundleURL = [NSURL URLWithString:savedURLString];
32
+ }
33
+ });
34
+
35
+ if (_bundleURL && [[NSFileManager defaultManager] fileExistsAtPath:[_bundleURL path]]) {
36
+ return _bundleURL;
37
+ }
38
+
39
+ return nil;
40
+ }
41
+
42
+ + (NSURL *)fallbackURL {
43
+ // This Support React Native 0.72.6
44
+ #if DEBUG
45
+ return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
46
+ #else
47
+ return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
48
+ #endif
49
+ }
50
+
51
+ + (NSURL *)bundleURL {
52
+ return [self cachedURLFromBundle] ?: [self fallbackURL];
53
+ }
54
+
55
+ #pragma mark - Utility Methods
56
+
57
+ + (NSString *)pathForFilename:(NSString *)filename {
58
+ return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:filename];
59
+ }
60
+
61
+ + (NSString *)pathFromURL:(NSURL *)url {
62
+ NSString *pathComponent = url.path;
63
+
64
+ if ([pathComponent hasPrefix:@"/"]) {
65
+ pathComponent = [pathComponent substringFromIndex:1];
66
+ }
67
+
68
+ return [self pathForFilename:pathComponent];
69
+ }
70
+
71
+ + (BOOL)downloadDataFromURL:(NSURL *)url andSaveToPath:(NSString *)path {
72
+ NSData *data = [NSData dataWithContentsOfURL:url];
73
+
74
+ if (!data) {
75
+ NSLog(@"Failed to download data from URL: %@", url);
76
+ return NO;
77
+ }
78
+
79
+ NSFileManager *fileManager = [NSFileManager defaultManager];
80
+ NSError *folderError;
81
+ if (![fileManager createDirectoryAtPath:[path stringByDeletingLastPathComponent]
82
+ withIntermediateDirectories:YES
83
+ attributes:nil
84
+ error:&folderError]) {
85
+ NSLog(@"Failed to create folder: %@", folderError);
86
+ return NO;
87
+ }
88
+
89
+ NSError *error;
90
+ [data writeToFile:path options:NSDataWritingAtomic error:&error];
91
+
92
+ if (error) {
93
+ NSLog(@"Failed to save data: %@", error);
94
+ return NO;
95
+ }
96
+
97
+ return YES;
98
+ }
99
+
100
+ #pragma mark - React Native Exports
101
+
102
+ RCT_EXPORT_METHOD(getBundleURL:(RCTResponseSenderBlock)callback) {
103
+ NSString *urlString = [HotUpdater.bundleURL absoluteString];
104
+ callback(@[urlString]);
105
+ }
106
+
107
+ RCT_EXPORT_METHOD(setBundleURL:(NSString *)urlString) {
108
+ [HotUpdater setBundleURL:[NSURL URLWithString:urlString]];
109
+ }
110
+
111
+ RCT_EXPORT_METHOD(downloadAndSave:(NSString *)urlString callback:(RCTResponseSenderBlock)callback) {
112
+ NSURL *url = [NSURL URLWithString:urlString];
113
+ NSString *path = [HotUpdater pathFromURL:url];
114
+ NSLog(@"Downloading %@ to %@", url, path);
115
+ BOOL success = [HotUpdater downloadDataFromURL:url andSaveToPath:path];
116
+ callback(@[@(success)]);
117
+ }
118
+
119
+ @end
package/lib/index.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Retrieves the bundle URL.
3
+ *
4
+ * @returns {Promise<string>} A promise that resolves to the bundle URL.
5
+ */
6
+ export declare const getBundleURL: () => Promise<string>;
7
+ /**
8
+ * Sets the bundle URL.
9
+ *
10
+ * @param {string} url - The URL to be set as the bundle URL.
11
+ * @returns {void} No return value.
12
+ */
13
+ export declare const setBundleURL: (url: string) => any;
14
+ /**
15
+ * Downloads and saves data from the given URL.
16
+ *
17
+ * @param {string} url - The URL to download data from.
18
+ * @returns {Promise<boolean>} Resolves with `true` if the operation is successful, otherwise rejects with `false`.
19
+ *
20
+ */
21
+ export declare const downloadAndSave: (url: string) => Promise<boolean>;
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,YAAY,uBAIxB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,QAAS,MAAM,QAEvC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,QAAS,MAAM,qBAM1C,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,35 @@
1
+ import { NativeModules } from "react-native";
2
+ var HotUpdater = NativeModules.HotUpdater;
3
+ /**
4
+ * Retrieves the bundle URL.
5
+ *
6
+ * @returns {Promise<string>} A promise that resolves to the bundle URL.
7
+ */
8
+ export var getBundleURL = function () {
9
+ return new Promise(function (resolve) {
10
+ return HotUpdater.getBundleURL(function (url) { return resolve(url); });
11
+ });
12
+ };
13
+ /**
14
+ * Sets the bundle URL.
15
+ *
16
+ * @param {string} url - The URL to be set as the bundle URL.
17
+ * @returns {void} No return value.
18
+ */
19
+ export var setBundleURL = function (url) {
20
+ return HotUpdater.setBundleURL(url);
21
+ };
22
+ /**
23
+ * Downloads and saves data from the given URL.
24
+ *
25
+ * @param {string} url - The URL to download data from.
26
+ * @returns {Promise<boolean>} Resolves with `true` if the operation is successful, otherwise rejects with `false`.
27
+ *
28
+ */
29
+ export var downloadAndSave = function (url) {
30
+ return new Promise(function (resolve, reject) {
31
+ return HotUpdater.downloadAndSave(url, function (isSuccess) {
32
+ return isSuccess ? resolve(true) : reject(false);
33
+ });
34
+ });
35
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@hot-updater/react-native",
3
+ "version": "0.0.1",
4
+ "description": "React Native OTA solution for internal infrastructure",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "src",
9
+ "lib",
10
+ "android",
11
+ "ios",
12
+ "cpp",
13
+ "*.podspec",
14
+ "!ios/build",
15
+ "!android/build",
16
+ "!android/gradle",
17
+ "!android/gradlew",
18
+ "!android/gradlew.bat",
19
+ "!android/local.properties",
20
+ "!**/__tests__",
21
+ "!**/__fixtures__",
22
+ "!**/__mocks__",
23
+ "!**/.*"
24
+ ],
25
+ "keywords": [],
26
+ "license": "MIT",
27
+ "repository": "https://github.com/gronxb/hot-updater",
28
+ "author": "gronxb <gron1gh1@gmail.com> (https://github.com/gronxb)",
29
+ "bugs": {
30
+ "url": "https://github.com/gronxb/hot-updater/issues"
31
+ },
32
+ "homepage": "https://github.com/gronxb/hot-updater#readme",
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "codegenConfig": {
37
+ "name": "RNReactNativeSpec",
38
+ "type": "modules",
39
+ "jsSrcsDir": "src"
40
+ },
41
+ "packageManager": "pnpm@8.9.2",
42
+ "devDependencies": {
43
+ "react": "^18.2.0",
44
+ "react-native": "^0.72.6"
45
+ },
46
+ "scripts": {
47
+ "preinstall": "npx only-allow pnpm",
48
+ "build": "tsc"
49
+ }
50
+ }
package/src/index.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { NativeModules } from "react-native";
2
+
3
+ const { HotUpdater } = NativeModules;
4
+
5
+ /**
6
+ * Retrieves the bundle URL.
7
+ *
8
+ * @returns {Promise<string>} A promise that resolves to the bundle URL.
9
+ */
10
+ export const getBundleURL = () => {
11
+ return new Promise<string>((resolve) =>
12
+ HotUpdater.getBundleURL((url: string) => resolve(url))
13
+ );
14
+ };
15
+
16
+ /**
17
+ * Sets the bundle URL.
18
+ *
19
+ * @param {string} url - The URL to be set as the bundle URL.
20
+ * @returns {void} No return value.
21
+ */
22
+ export const setBundleURL = (url: string) => {
23
+ return HotUpdater.setBundleURL(url);
24
+ };
25
+
26
+ /**
27
+ * Downloads and saves data from the given URL.
28
+ *
29
+ * @param {string} url - The URL to download data from.
30
+ * @returns {Promise<boolean>} Resolves with `true` if the operation is successful, otherwise rejects with `false`.
31
+ *
32
+ */
33
+ export const downloadAndSave = (url: string) => {
34
+ return new Promise<boolean>((resolve, reject) =>
35
+ HotUpdater.downloadAndSave(url, (isSuccess: boolean) =>
36
+ isSuccess ? resolve(true) : reject(false)
37
+ )
38
+ );
39
+ };