Skip to content

Commit

Permalink
Merge pull request #8 from Derewith/update
Browse files Browse the repository at this point in the history
feat: adapted the app to the new be
  • Loading branch information
Derewith authored Mar 22, 2024
2 parents b150660 + e52f39d commit 93e5254
Show file tree
Hide file tree
Showing 29 changed files with 1,043 additions and 533 deletions.
4 changes: 0 additions & 4 deletions DoubleConversion-Bridging-Header.h

This file was deleted.

77 changes: 69 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@

Handle your app updates

## Table of contents

- [Installation](#installation)
- [Usage](#usage)
- [Configuration](#configuration)
- [iOS](#ios)
- [Options](#options)
- [Tracking [iOS]](#tracking-ios)
- [Tracking [Android]](#tracking-android)
- [Contributing](#contributing)
- [License](#license)

## Installation

```sh
bun install react-native-bundle-updater
At now the installation is only available locally, you can install the package by adding the following line to your package.json file

```json
"react-native-bundle-updater": "file:path/to/the/package",
```

In the near future, the package will be available on npm.

## Usage

Make some modifications to your App files on the react native side.
Expand All @@ -17,23 +33,68 @@ import something from 'react-native-bundle-updater';
and then run:

```sh
bun upload:dev folderOfJSBundle assetsGeneratedFolder apiKey
npx react-native-bundle-updater [apiKey] [branch] [version] [-m "Bundle notes" (optional)]
```

Example:

```sh
bun upload:dev ./example/ios/main.jsbundle ./example/ios/assets 31ad196f026d0b07b7dffe9019f708955c13
npx react-native-bundle-updater **YourApiKey** master 1.0.0 -m "New awesome bundle"
```

## Configuration for React Native

### iOS

Add the following lines to your AppDelegate.m file

```objc
#import "AppDelegate.h"
#import "BundleUpdater.h" // <-- Add this line

....some code....

self.initialProps = @{}; // <-- After this line

BundleUpdater *bundleUpdater = [BundleUpdater sharedInstance];
[bundleUpdater initialization:@"YOURKEY" withBranch: @"staging"];

.... some other code ....

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { // <-- Replace this method
BundleUpdater *bundleUpdater = [BundleUpdater sharedInstance];
return [bundleUpdater initializeBundle:bridge withKey:@"YOURKEY"];
}

```
## Options
### Tracking [iOS]
By default the tracking is disabled, you can enable it by adding the enableTracking boolean flag inside the AppDelegate.m file.
```objc
[BundleUpdater setEnableTracking:YES];
```

In order to inform the user about the tracking, you can add the following lines to your Info.plist file

```xml
<key>NSUserTrackingUsageDescription</key>
<string>**Your APP** requires your permission for tracking some basic information to enhance your experience </string>
```

### Tracking [Android]

// TODO

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

## License

MIT

---
[MIT LICENSE](LICENSE)

Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
2024 © Impresoft Engage
44 changes: 44 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node

const { exec } = require('child_process');
const yargs = require('yargs');
const {
REACT_NATIVE_BUNDLE_COMMAND,
BUNDLE_UPDATER_CLI_COMMAND,
} = require('./constants');

const options = yargs
.usage('Usage: $0 [options] <apiKey> <branch> <version>')
.option('m', {
alias: 'comment',
describe: 'Add a comment to the bundle',
type: 'string',
default: '',
})
.demandCommand(3, 'You must provide the apiKey, branch and version')
.help('h')
.alias('h', 'help').argv;

const apiKey = options._[0];
const branch = options._[1];
const version = options._[2];
const comment = options.comment;

console.log(`Creating the bundle...`);
exec(REACT_NATIVE_BUNDLE_COMMAND, (error, stdout, stderr) => {
if (error) {
console.error(`Error during the first script execution: ${stderr}`);
process.exit(1);
} else {
const cliCommand = `${BUNDLE_UPDATER_CLI_COMMAND} ${apiKey} ${branch} ${version} -m "${comment}"`;
exec(cliCommand, (_error, _stdout, _stderr) => {
if (_error) {
console.error(`Error during the second script execution: ${_stderr}`);
process.exit(1);
} else {
console.log(`${_stdout}`);
process.exit(0);
}
});
}
});
Binary file modified bun.lockb
Binary file not shown.
63 changes: 0 additions & 63 deletions cli.js

This file was deleted.

6 changes: 6 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
REACT_NATIVE_BUNDLE_COMMAND:
'npx react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios --minify true',
BUNDLE_UPDATER_CLI_COMMAND:
'node ./node_modules/react-native-bundle-updater/local-cli/cli.js',
};
11 changes: 3 additions & 8 deletions example/ios/BundleUpdaterExample/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@ - (BOOL)application:(UIApplication *)application
self.initialProps = @{};

BundleUpdater *bundleUpdater = [BundleUpdater sharedInstance];
[bundleUpdater initialization:@"70df8a199213d53d892a3eddb6f3bf9c4158"
resolve:^(NSString *result) {
NSLog(@"[APP]Initialization success: %@", result);
}
reject:^(NSString *code, NSString *message, NSError *error) {
NSLog(@"[APP]Initialization error: %@", error);
}];
[bundleUpdater initialization:@"6e776f467b0744d19e62172c59c79efb" withBranch: @"staging"];

return [super application:application
didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
BundleUpdater *bundleUpdater = [BundleUpdater sharedInstance];
return [bundleUpdater initializeBundle:bridge withKey:@"70df8a199213d53d892a3eddb6f3bf9c4158"];
return [bundleUpdater initializeBundle:bridge withKey:@"6e776f467b0744d19e62172c59c79efb"];
}


@end
6 changes: 5 additions & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ PODS:
- React-Core
- SDWebImage (~> 5.0)
- SPIndicator
- SSZipArchive
- React-NativeModulesApple (0.72.5):
- React-callinvoker
- React-Core
Expand Down Expand Up @@ -397,6 +398,7 @@ PODS:
- SDWebImage/Core (5.18.3)
- SocketRocket (0.6.1)
- SPIndicator (1.6.4)
- SSZipArchive (2.4.3)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -447,6 +449,7 @@ SPEC REPOS:
- SDWebImage
- SocketRocket
- SPIndicator
- SSZipArchive

EXTERNAL SOURCES:
boost:
Expand Down Expand Up @@ -550,7 +553,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: f32f98d8ddbdfd97dea286af90381a731d68c505
React-jsinspector: aef73cbd43b70675f572214d10fa438c89bf11ba
React-logger: 2e4aee3e11b3ec4fa6cfd8004610bbb3b8d6cca4
react-native-bundle-updater: c6a6abe1c438e4ce16e6c8c43d30892fde92113a
react-native-bundle-updater: 184993a89efbdd006d66e207eb7002f3bb9f5d74
React-NativeModulesApple: 535e26db03f74ecc500748ce79fa349b2ee2ee21
React-perflogger: cd8886513f68e1c135a1e79d20575c6489641597
React-RCTActionSheet: 726d2615ca62a77ce3e2c13d87f65379cdc73498
Expand All @@ -571,6 +574,7 @@ SPEC CHECKSUMS:
SDWebImage: 96e0c18ef14010b7485210e92fac888587ebb958
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
SPIndicator: 93e0a4fb23de51294ac48e874c0f081a5e293e4f
SSZipArchive: fe6a26b2a54d5a0890f2567b5cc6de5caa600aef
Yoga: 86fed2e4d425ee4c6eab3813ba1791101ee153c6

PODFILE CHECKSUM: 7431905f8d399ca127564f129bfa93819111c9b2
Expand Down
11 changes: 11 additions & 0 deletions ios/BundleUpdater+FileManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#import "BundleUpdater.h"

@interface BundleUpdater (FileManager)

- (void)copyFilesFromSource:(NSString *)sourceFolder toDestination:(NSString *)destinationFolder;
- (void)clearDocumentsFolder;
- (NSMutableData *)calculateSHA256Hash:(NSData *)script;
- (NSString *)loadHashFromDisk;
- (NSString *)unzipBundleAndAssetsInto: (NSURL *) location withSuccess:(BOOL *)success;

@end
Loading

0 comments on commit 93e5254

Please sign in to comment.