From a52c1c30ee4adc7511c2d7fae97ef71018bd40c9 Mon Sep 17 00:00:00 2001 From: Alexander Pataridze Date: Wed, 27 Nov 2024 15:56:52 +0400 Subject: [PATCH 1/2] fix: release builds --- ios/ThreadManager.m | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/ios/ThreadManager.m b/ios/ThreadManager.m index 3c24aec..006386e 100644 --- a/ios/ThreadManager.m +++ b/ios/ThreadManager.m @@ -47,34 +47,30 @@ -(void) checkAndSendEvent:(NSString*)name body:(id)body } int threadId = nextThreadId++; - - NSString *jsFileSlug = [name containsString:@"./"] - ? [name stringByReplacingOccurrencesOfString:@"./" withString:@""] - : name; - - // Bundled JavaScript is placed within the resources directory. - NSURL *bundledThreadURL = [[NSBundle mainBundle] URLForResource:[NSString stringWithFormat:@"%@", [jsFileSlug lastPathComponent]] withExtension:@"jsbundle"]; - + + NSURL *threadURL; + +#ifdef DEBUG + threadURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:name]; +#else + NSString *jsBundlePath = [[NSBundle mainBundle] pathForResource:@"index.thread" ofType:@"jsbundle"]; + // Check whether we can read bundle JS the resources directory. If // the file is not found, error will be non-nil. NSError *error = nil; - NSURL *threadURL = [bundledThreadURL checkResourceIsReachableAndReturnError:&error] - ? bundledThreadURL - : [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:name]; - - #ifndef DEBUG - // For non-debug builds, we enforce that the bundle JS must - // be available in the resources dir by terminating before - // falling back to loading via Metro. - if (error) { - reject( + + if(error != nil){ + reject( [NSString stringWithFormat:@"%ld", (long)error.code], [NSString stringWithFormat:@"Unable to resolve thread bundle: %@", error.localizedDescription], error - ); - return; - } - #endif + ); + return; + } + + threadURL = [NSURL fileURLWithPath:jsBundlePath]; +#endif + NSLog(@"starting Thread %@", [threadURL absoluteString]); RCTBridgeModuleListProvider threadModuleProvider = ^NSArray> *{ From c5769acf3840f584f0ee021aca82c21ed23c68de Mon Sep 17 00:00:00 2001 From: Alexander Pataridze Date: Wed, 27 Nov 2024 16:12:19 +0400 Subject: [PATCH 2/2] refactor: update readme --- README.md | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 24f7b9f..dc0d886 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,36 @@ remotely behave unpredictably. I recommend using a third party debugging tool li including your main application as well as your thread code can connect to Reactotron and log debugging messages. -### Building for Release + +### Set up automated bundling [iOS] + +Bundling can be automated on iOS. + +- Create a build phase "Bundle thread" and paste script below. + +```bash +if [[ $CONFIGURATION == 'Release' ]] +then + source ../scripts/detect-nvm.sh + cd .. + sh ./scripts/bundleThread.sh +else + rm index.thread.jsbundle + touch index.thread.jsbundle +fi +``` + +- Once the script is there add item to Output Files and set `$(SRCROOT)/index.thread.jsbundle` +- Now create a `bundleThread.sh` script and paste code below. (Make sure the entry file is correct) + +```bash +REACT_NATIVE_DIR="node_modules/react-native" +node "$REACT_NATIVE_DIR/local-cli/cli.js" bundle --dev false --assets-dest ./ios --entry-file threads/sdk/index.js --platform ios --bundle-output ./ios/index.thread.jsbundle +``` + + + +### Building for Release [Android] You will need to manually bundle your thread files for use in a production release of your app. This documentation assumes you have a single thread file called @@ -143,26 +172,15 @@ of your app. This documentation assumes you have a single thread file called a different location, you can update the documented commands accordingly. **Note**: If your single thread file is in a different location, the folder structure needs to -be replicated under `./ios` and `./android/app/src/main/assets/threads`. +be replicated under `./android/app/src/main/assets/threads`. ``` ./App/Workers/worker.thread.js => ./ios/App/Workers/worker.thread.jsbundle ./App/Workers/worker.thread.js => ./android/app/src/main/assets/threads/App/Workers/worker.thread.jsbundle ``` -For iOS you can use the following command: - -`node node_modules/react-native/local-cli/cli.js bundle --dev false --assets-dest ./ios --entry-file index.thread.js --platform ios --bundle-output ./ios/index.thread.jsbundle` - -Once you have generated the bundle file in your ios folder, you will also need to add -the bundle file to you project in Xcode. In Xcode's file explorer you should see -a folder with the same name as your app, containing a `main.jsbundle` file as well -as an `appDelegate.m` file. Right click on that folder and select the 'Add Files to ' -option, which will open up finder and allow you to select your `ios/index.thread.jsbundle` -file. You will only need to do this once, and the file will be included in all future -builds. -For Android create this direactory +Create this direactory `mkdir ./android/app/src/main/assets/threads` And then you can use the following command: