React Native Deploy helper
Install
npm install -g @np-dev/rn-deploy
OR
npm install --save-dev @np-dev/rn-deploy
Commands
- rn-deploy codepush ${platform} ${environment}
- platform: ios or android or all
- environment: dev - .env, staging - .env.staging, production - .env.production
- For example:
rn-deploy codepush ios dev
rn-deploy codepush android dev
rn-deploy codepush all dev
.env example
DEPLOY_CODEPUSH_TOKEN = 'User token from codepush'
IOS_DEPLOY_TOKEN = 'IOS token from codepush'
ANDROID_DEPLOY_TOKEN = 'Android token from codepush'
ANDROID_CODEPUSH_URL = 'Android project'
IOS_CODEPUSH_URL = 'IOS project'
Sync CodePush with S3
- Add to .env or .env.codepush_s3
AWS_REGION = ''
AWS_BUCKET_NAME = ''
AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''
AWS_ENDPOINT = 'For custom s3 server'
AWS_FORCE_PATH_STYLE = true
- Add @np-dev/react-native-code-push to package.json
yarn add @np-dev/react-native-code-push
npm i @np-dev/react-native-code-push
- In the app, when your app check for updates, add the following code:
import codePush, {RemotePackage} from '@np-dev/react-native-code-push';
const remoteVersion: RemotePackage | null = await codePush.checkForUpdate();
let downloadUrl: string | undefined;
if (remoteVersion.packageHash) {
const S3Url = 'https://packages.s3.ap-southeast-1.amazonaws.com/' + remoteVersion.packageHash;
const checkS3 = await fetch(S3Url, {
method: 'HEAD',
});
if (checkS3.status === 200) {
downloadUrl = S3Url;
}
}
codePush.sync(
{
installMode: codePush.InstallMode.IMMEDIATE,
downloadUrl,
},
syncStatusChangedCallback,
codePushDownloadDidProgress,
codePushDownloadCompleted,
);