react-native-code-push
Advanced tools
Comparing version 1.5.3-beta to 1.6.0-beta
@@ -63,4 +63,5 @@ import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk"; | ||
} else { | ||
const remotePackage = { ...update, ...PackageMixins.remote }; | ||
const remotePackage = { ...update, ...PackageMixins.remote(sdk.reportStatusDownload) }; | ||
remotePackage.failedInstall = await NativeCodePush.isFailedUpdate(remotePackage.packageHash); | ||
remotePackage.deploymentKey = deploymentKey || nativeConfig.deploymentKey; | ||
return remotePackage; | ||
@@ -105,3 +106,27 @@ } | ||
}; | ||
sdk.reportStatusDeploy = (deployedPackage, status) => { | ||
return new Promise((resolve, reject) => { | ||
module.exports.AcquisitionSdk.prototype.reportStatusDeploy.call(sdk, deployedPackage, status, (err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
}; | ||
sdk.reportStatusDownload = (downloadedPackage) => { | ||
return new Promise((resolve, reject) => { | ||
module.exports.AcquisitionSdk.prototype.reportStatusDownload.call(sdk, downloadedPackage, (err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
}; | ||
return sdk; | ||
@@ -115,2 +140,18 @@ } | ||
async function notifyApplicationReady() { | ||
await NativeCodePush.notifyApplicationReady(); | ||
const statusReport = await NativeCodePush.getNewStatusReport(); | ||
if (statusReport) { | ||
const config = await getConfiguration(); | ||
if (statusReport.appVersion) { | ||
const sdk = getPromisifiedSdk(requestFetchAdapter, config); | ||
sdk.reportStatusDeploy(); | ||
} else { | ||
config.deploymentKey = statusReport.package.deploymentKey; | ||
const sdk = getPromisifiedSdk(requestFetchAdapter, config); | ||
sdk.reportStatusDeploy(statusReport.package, statusReport.status); | ||
} | ||
} | ||
} | ||
function restartApp(onlyIfUpdateIsPending = false) { | ||
@@ -275,3 +316,3 @@ NativeCodePush.restartApp(onlyIfUpdateIsPending); | ||
log, | ||
notifyApplicationReady: NativeCodePush.notifyApplicationReady, | ||
notifyApplicationReady, | ||
restartApp, | ||
@@ -278,0 +319,0 @@ setUpTestDependencies, |
@@ -0,1 +1,2 @@ | ||
import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk"; | ||
import { DeviceEventEmitter } from "react-native"; | ||
@@ -7,28 +8,31 @@ | ||
module.exports = (NativeCodePush) => { | ||
const remote = { | ||
async download(downloadProgressCallback) { | ||
if (!this.downloadUrl) { | ||
throw new Error("Cannot download an update without a download url"); | ||
} | ||
const remote = (reportStatusDownload) => { | ||
return { | ||
async download(downloadProgressCallback) { | ||
if (!this.downloadUrl) { | ||
throw new Error("Cannot download an update without a download url"); | ||
} | ||
let downloadProgressSubscription; | ||
if (downloadProgressCallback) { | ||
// Use event subscription to obtain download progress. | ||
downloadProgressSubscription = DeviceEventEmitter.addListener( | ||
"CodePushDownloadProgress", | ||
downloadProgressCallback | ||
); | ||
} | ||
let downloadProgressSubscription; | ||
if (downloadProgressCallback) { | ||
// Use event subscription to obtain download progress. | ||
downloadProgressSubscription = DeviceEventEmitter.addListener( | ||
"CodePushDownloadProgress", | ||
downloadProgressCallback | ||
); | ||
} | ||
// Use the downloaded package info. Native code will save the package info | ||
// so that the client knows what the current package version is. | ||
try { | ||
const downloadedPackage = await NativeCodePush.downloadUpdate(this); | ||
return { ...downloadedPackage, ...local }; | ||
} finally { | ||
downloadProgressSubscription && downloadProgressSubscription.remove(); | ||
} | ||
}, | ||
// Use the downloaded package info. Native code will save the package info | ||
// so that the client knows what the current package version is. | ||
try { | ||
const downloadedPackage = await NativeCodePush.downloadUpdate(this); | ||
reportStatusDownload && reportStatusDownload(this); | ||
return { ...downloadedPackage, ...local }; | ||
} finally { | ||
downloadProgressSubscription && downloadProgressSubscription.remove(); | ||
} | ||
}, | ||
isPending: false // A remote package could never be in a pending state | ||
isPending: false // A remote package could never be in a pending state | ||
}; | ||
}; | ||
@@ -35,0 +39,0 @@ |
{ | ||
"name": "react-native-code-push", | ||
"version": "1.5.3-beta", | ||
"version": "1.6.0-beta", | ||
"description": "React Native plugin for the CodePush service", | ||
@@ -19,3 +19,3 @@ "main": "CodePush.js", | ||
"dependencies": { | ||
"code-push": "^1.1.1-beta", | ||
"code-push": "1.5.1-beta", | ||
"semver": "^5.1.0" | ||
@@ -22,0 +22,0 @@ }, |
116
README.md
# React Native Plugin for CodePush | ||
This plugin provides client-side integration for the [CodePush service](https://microsoft.github.io/code-push), allowing you to easily add a dynamic update experience to your React Native app(s). | ||
This plugin provides client-side integration for the [CodePush service](http://codepush.tools), allowing you to easily add a dynamic update experience to your React Native app(s). | ||
@@ -13,3 +13,4 @@ * [How does it work?](#how-does-it-work) | ||
* [Plugin Installation](#plugin-installation-android) | ||
* [Plugin Configuration](#plugin-configuration-android) | ||
* [Plugin Configuration (React Native < v0.18.0)](#plugin-configuration-android---react-native--v0180) | ||
* [Plugin Configuration (React Native 0.18.0+)](#plugin-configuration-android---react-native-v0180) | ||
* [Plugin Usage](#plugin-usage) | ||
@@ -42,5 +43,5 @@ * [Releasing Updates (JavaScript-only)](#releasing-updates-javascript-only) | ||
Once you've followed the general-purpose ["getting started"](http://microsoft.github.io/code-push/docs/getting-started.html) instructions for setting up your CodePush account, you can start CodePush-ifying your React Native app by running the following command from within your app's root directory: | ||
Once you've followed the general-purpose ["getting started"](http://codepush.tools/docs/getting-started.html) instructions for setting up your CodePush account, you can start CodePush-ifying your React Native app by running the following command from within your app's root directory: | ||
``` | ||
```shell | ||
npm install --save react-native-code-push | ||
@@ -63,3 +64,3 @@ ``` | ||
3. Select the project node in Xcode and select the "Build Phases" tab of your project configuration. | ||
4. Drag `libCodePush.a` from `Libraries/CodePush.xcodeproj/Products` into the "Link Binary With Libraries" secton of your project's "Build Phases" configuration. | ||
4. Drag `libCodePush.a` from `Libraries/CodePush.xcodeproj/Products` into the "Link Binary With Libraries" section of your project's "Build Phases" configuration. | ||
@@ -85,3 +86,3 @@ ![Link CodePush during build](https://cloud.githubusercontent.com/assets/516559/10322221/a75ea066-6c31-11e5-9d88-ff6f6a4d6968.png) | ||
``` | ||
```objective-c | ||
#import "CodePush.h" | ||
@@ -92,3 +93,3 @@ ``` | ||
``` | ||
```objective-c | ||
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; | ||
@@ -99,3 +100,3 @@ ``` | ||
``` | ||
```objective-c | ||
jsCodeLocation = [CodePush bundleURL]; | ||
@@ -108,2 +109,14 @@ ``` | ||
Typically, you're only going to want to use CodePush to resolve your JS bundle location within release builds, and therefore, we recommend using the `DEBUG` pre-processor macro to dynamically switch between using the packager server and CodePush, depending on whether you are debugging or not. This will make it much simpler to ensure you get the right behavior you want in production, while still being able to use the Chrome Dev Tools, live reload, etc. at debug-time. | ||
```objective-c | ||
NSURL *jsCodeLocation; | ||
#ifdef DEBUG | ||
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; | ||
#else | ||
jsCodeLocation = [CodePush bundleURL]; | ||
#endif | ||
``` | ||
To let the CodePush runtime know which deployment it should query for updates against, perform the following steps: | ||
@@ -115,4 +128,6 @@ | ||
2. In your app's `Info.plist` make sure your `CFBundleShortVersionString` value is a valid [semver](http://semver.org/) version (e.g. 1.0.0 not 1.0) | ||
2. In your app's `Info.plist` make sure your `Bundle versions string, short` (aka `CFBundleShortVersionString`) value is a valid [semver](http://semver.org/) version (e.g. 1.0.0 not 1.0) | ||
![Bundle version](https://cloud.githubusercontent.com/assets/116461/12307416/f9b82688-b9f3-11e5-839a-f1c6b4acd093.png) | ||
## Android Setup | ||
@@ -140,4 +155,6 @@ | ||
### Plugin Configuration (Android) | ||
### Plugin Configuration (Android - React Native < v0.18.0) | ||
*NOTE: These instructions are specific to apps that are using React Native v0.15.0-v0.17.0. If you are using v0.18.0+, then skip ahead to the next section.* | ||
After installing the plugin and syncing your Android Studio project with Gradle, you need to configure your app to consult CodePush for the location of your JS bundle, since it will "take control" of managing the current and all future versions. To do this, perform the following steps: | ||
@@ -161,3 +178,3 @@ | ||
// 3. Initialize CodePush with your deployment key and an instance of your MainActivity. | ||
CodePush codePush = new CodePush("d73bf5d8-4fbd-4e55-a837-accd328a21ba", this); | ||
CodePush codePush = new CodePush("d73bf5d8-4fbd-4e55-a837-accd328a21ba", this, BuildConfig.DEBUG); | ||
... | ||
@@ -195,2 +212,57 @@ mReactInstanceManager = ReactInstanceManager.builder() | ||
### Plugin Configuration (Android - React Native v0.18.0+) | ||
*NOTE: These instructions are specific to apps that are using React Native v0.18.0+. If you are using v0.15.0-v0.17.0, then refer to the previous section.* | ||
After installing the plugin and syncing your Android Studio project with Gradle, you need to configure your app to consult CodePush for the location of your JS bundle, since it will "take control" of managing the current and all future versions. To do this, perform the following steps: | ||
1. Update the `MainActivity.java` file to use CodePush via the following changes: | ||
```java | ||
... | ||
// 1. Import the plugin class | ||
import com.microsoft.codepush.react.CodePush; | ||
public class MainActivity extends ReactActivity { | ||
// 2. Define a private field to hold the CodePush runtime instance | ||
private CodePush _codePush; | ||
... | ||
// 3. Override the getJSBundleFile method in order to let | ||
// the CodePush runtime determine where to get the JS | ||
// bundle location from on each app start | ||
@Override | ||
protected String getJSBundleFile() { | ||
return this._codePush.getBundleUrl("index.android.bundle"); | ||
} | ||
@Override | ||
protected List<ReactPackage> getPackages() { | ||
// 4. Instantiate an instance of the CodePush runtime, using the right deployment key | ||
this._codePush = new CodePush("0dsIDongIcoH0mqAmoR0CYb5FhBZNy1w4Bf-l", this, BuildConfig.DEBUG); | ||
// 5. Add the CodePush package to the list of existing packages | ||
return Arrays.<ReactPackage>asList( | ||
new MainReactPackage(), this._codePush.getReactPackage()); | ||
} | ||
... | ||
} | ||
``` | ||
2. Ensure that the `android.defaultConfig.versionName` property in your `android/app/build.gradle` file is set to a semver compliant value (i.e. "1.0.0" not "1.0") | ||
```gradle | ||
android { | ||
... | ||
defaultConfig { | ||
... | ||
versionName "1.0.0" | ||
... | ||
} | ||
... | ||
} | ||
``` | ||
## Plugin Usage | ||
@@ -207,3 +279,3 @@ | ||
``` | ||
```javascript | ||
import CodePush from "react-native-code-push"; | ||
@@ -214,3 +286,3 @@ ``` | ||
``` | ||
```javascript | ||
CodePush.sync(); | ||
@@ -227,7 +299,9 @@ ``` | ||
2. Execute `code-push release <appName> <jsBundleFilePath> <appStoreVersion> --deploymentName <deploymentName>` in order to publish the generated JS bundle to the server. The `<jsBundleFilePath>` parameter should equal the value you provided to the `--bundle-output` flag in step #1. Additionally, the `<appStoreVersion>` parameter should equal the exact app store version (i.e. the semver version end users would see when installing it) you want this CodePush update to target. | ||
2. Execute `code-push release <appName> <jsBundleFilePath> <appStoreVersion> --deploymentName <deploymentName>` in order to publish the generated JS bundle to the server. The `<jsBundleFilePath>` parameter should equal the value you provided to the `--bundle-output` flag in step #1. Additionally, the `<appStoreVersion>` parameter should equal the [**exact app store version**](http://codepush.tools/docs/cli.html#app-store-version-parameter) (i.e. the semver version end users would see when installing it) you want this CodePush update to target. | ||
For more info regarding the `release` command and its parameters, refer to the [CLI documentation](http://codepush.tools/docs/cli.html#releasing-app-updates). | ||
Example Usage: | ||
``` | ||
```shell | ||
react-native bundle --platform ios --entry-file index.ios.js --bundle-output codepush.js --dev false | ||
@@ -243,3 +317,3 @@ code-push release MyApp codepush.js 1.0.2 | ||
*Note: Android doesn't currently support deploying assets, so you must use the previous release strategy instead.* | ||
*Note: Android doesn't currently support deploying assets, so you must use the previous release strategy instead for that platform. We will release Android support as soon as React Native 0.19.0 is released.* | ||
@@ -252,3 +326,3 @@ If you are using the new React Native [assets system](https://facebook.github.io/react-native/docs/images.html#content), as opposed to loading your images from the network and/or platform-specific mechanisms (e.g. iOS asset catalogs), then you can't simply pass your jsbundle to CodePush as demonstrated above. You **MUST** provide your images as well. To do this, simply use the following workflow: | ||
``` | ||
```shell | ||
react-native bundle \ | ||
@@ -258,8 +332,12 @@ --platform ios \ | ||
--bundle-output ./release/main.jsbundle \ | ||
--assets-dest ./release | ||
--assets-dest ./release \ | ||
--dev false | ||
``` | ||
3. Execute `code-push release`, passing the path to the directory you created in #1 as the "package" parameter (e.g. `code-push release Foo ./release 1.0.0`). The code-push CLI will automatically handle zipping up the contents for you, so don't worry about handling that yourself. | ||
*NOTE: The file name that you specify as the value for the `--bundle-output` parameter must have one of the following extensions in order to be detected by the plugin: `.js`, `.jsbundle`, `.bundle` (e.g. `main.jsbundle`, `ios.js`). The name of the file isn't relevant, but the extension is used for detectining the bundle within the update contents, and therefore, using any other extension will result in the update failing.* | ||
3. Execute `code-push release`, passing the path to the directory you created in #1 as the ["package"](http://codepush.tools/docs/cli.html#package-parameter) parameter, and the [**exact app version**](http://codepush.tools/docs/cli.html#app-store-version-parameter) that this update is targetting as the ["appStoreVersion"](http://codepush.tools/docs/cli.html#app-store-version-parameter) parameter (e.g. `code-push release Foo ./release 1.0.0`). The code-push CLI will automatically handle zipping up the contents for you, so don't worry about handling that yourself. | ||
For more info regarding the `release` command and its parameters, refer to the [CLI documentation](http://codepush.tools/docs/cli.html#releasing-app-updates). | ||
Additionally, the CodePush client supports differential updates, so even though you are releasing your JS bundle and assets on every update, your end users will only actually download the files they need. The service handles this automatically so that you can focus on creating awesome apps and we can worry about optimizing end user downloads. | ||
@@ -266,0 +344,0 @@ |
module.exports = { | ||
async request(verb, url, body, callback) { | ||
if (typeof body === "function") { | ||
callback = body; | ||
body = null; | ||
async request(verb, url, requestBody, callback) { | ||
if (typeof requestBody === "function") { | ||
callback = requestBody; | ||
requestBody = null; | ||
} | ||
@@ -13,4 +13,4 @@ | ||
if (body && typeof body === "object") { | ||
body = JSON.stringify(body); | ||
if (requestBody && typeof requestBody === "object") { | ||
requestBody = JSON.stringify(requestBody); | ||
} | ||
@@ -20,5 +20,5 @@ | ||
const response = await fetch(url, { | ||
method: verb, | ||
method: getHttpMethodName(verb), | ||
headers: headers, | ||
body: body | ||
body: requestBody | ||
}); | ||
@@ -33,2 +33,18 @@ | ||
} | ||
}; | ||
}; | ||
function getHttpMethodName(verb) { | ||
// Note: This should stay in sync with the enum definition in | ||
// https://github.com/Microsoft/code-push/blob/master/sdk/script/acquisition-sdk.ts#L6 | ||
return [ | ||
"GET", | ||
"HEAD", | ||
"POST", | ||
"PUT", | ||
"DELETE", | ||
"TRACE", | ||
"OPTIONS", | ||
"CONNECT", | ||
"PATCH" | ||
][verb]; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
656140
1543
671
+ Addedcode-push@1.5.1-beta(transitive)
- Removedasync@0.9.2(transitive)
- Removedcode-push@1.1.1-beta(transitive)
- Removedcombined-stream@0.0.7(transitive)
- Removedcomponent-emitter@1.1.2(transitive)
- Removedcookiejar@2.0.1(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddelayed-stream@0.0.5(transitive)
- Removedextend@1.2.1(transitive)
- Removedform-data@0.2.0(transitive)
- Removedformidable@1.0.14(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@0.0.1(transitive)
- Removedmethods@1.0.1(transitive)
- Removedmime@1.3.4(transitive)
- Removedmime-db@1.12.0(transitive)
- Removedmime-types@2.0.14(transitive)
- Removedms@2.0.0(transitive)
- Removedqs@2.3.3(transitive)
- Removedreadable-stream@1.0.27-1(transitive)
- Removedreduce-component@1.0.1(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedsuperagent@1.2.0(transitive)
Updatedcode-push@1.5.1-beta