CodePush Plugin for Capacitor. Working with Capacitor 8.
npm install cap-codepushThis version is a fork of Mapiacompany's Capacitor Codepush, updated to work with the latest Capacitor. I use this daily in my company.
#### Setup a Codepush Server
- https://github.com/lisong/code-push-server
#### Setup Codepush CLI
- https://github.com/shm-open/code-push-cli
#### Take a look at the original README for this project
I simplified this documentation to provide a quick Getting Started. For any doubt or extended functionality, consult the original README:
- ORIGINAL_README.md
#### Capacitor 8
```
npm i cap-codepush@8
npm i cap-codepush@7
`Old naming convention
#### Capacitor 6
`
npm i cap-codepush@3
`
#### Capacitor 5
`
npm i cap-codepush@2
`
#### Capacitor 4
`
npm i cap-codepush@1
`Add App to the CodePush Server via CLI
$3
- https://github.com/shm-open/code-push-cli$3
#### Authenticate the CLI to your server
Don't have a Codepush Server?
- https://github.com/lisong/code-push-server
`bash
code-push register https://your-codepush-server-ip:10443
`Use your own credentials provided by the server admin.
#### Register a New App
Each app must have two versions:
- One for Android (suffix
-android)
- One for iOS (suffix -ios)
The platform can be
ios or android.The technology to select is
cordova, even if you are using Capacitor.`bash
code-push app add Example (execute both for each app):
code-push app add myapp-ios ios cordova
code-push app add myapp-android android cordova
`$3
Add the following snippet in
app.component.ts:Example with Ionic+Angular
`ts
import { CodePush, InstallMode } from 'cap-codepush';async ngOnInit() {
await this.initializeCodepush();
}
private async initializeCodepush() {
CodePush.sync({
onSyncStatusChanged: (syncStatus) => {
console.log('Sync status changed: ', syncStatus);
},
installMode: InstallMode.IMMEDIATE,
}).then(
(status) => {
if (status) {
console.log(status);
}
},
(error) => {
if (error) {
console.log(error);
}
}
);
}
`Update
capacitor.config.ts with:`js
plugins: {
CodePush: {
SERVER_URL: "https://your-codepush-server.com:10443/",
IOS_DEPLOY_KEY: IS_DEV ? "[your development key]" : "[your production key]",
ANDROID_DEPLOY_KEY: IS_DEV ? "[your development key]" : "[your production key]",
}
}
`Releasing a New Version of Your App
The path to the
public folder is always:- Android:
android/app/src/main/assets/public/
- iOS: ios/App/App/public/#### Manual Release
`bash
ionic cap sync # synchronize Ionic with native project
code-push release -d Example:
ionic cap synccode-push release myapp-android android/app/src/main/assets/public/ 1.0.0 -d "Production"
code-push release myapp-ios ios/App/App/public/ 1.0.0 -d "Production"
`Useful Commands
List all apps available on the CodePush server
`bash
code-push app ls
`List all deployments for a given app
`bash
code-push deployment ls To show deployment tokens as well:
code-push deployment ls -kExample:
code-push deployment ls myapp-ios
`$3
⚠️ This command will not rollback updates already installed by users.
`bash
code-push deployment clear Example:
code-push deployment clear myapp-android Production
code-push deployment clear myapp-android Staging
``