Skip to content

gianluigitrontini/capacitor-codepush

 
 

Repository files navigation

Capacitor Plugin for CodePush

This version is a fork of Mapiacompany's Capacitor Codepush, updated to work with the latest Capacitor. I use this daily in my company.

References

Setup a Codepush Server

Setup Codepush 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:

Install the plugin to your Capacitor project

Capacitor 7

npm i cap-codepush@7

Previous versions

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

Install the CLI

Authentication

Authenticate the CLI to your server

Don't have a Codepush Server?

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.

code-push app add <app-name-with-suffix> <platform> <technology>

# Example (execute both for each app):
code-push app add myapp-ios ios cordova
code-push app add myapp-android android cordova

Project Integration

Add the following snippet in app.component.ts:

Example with Ionic+Angular

ngOnInit() {
  if (this.platform.is("capacitor")) {
    await this.initializeCodepush();
  }
}

private async initializeCodepush() {
  codePush
    .sync({
      onSyncStatusChanged: (syncStatus) => {},
      installMode: InstallMode.IMMEDIATE,
    })
    .then(
      (status) => {
        if (status) {
          console.log(status);
        }
      },
      (error) => {
        if (error) {
          console.log(error);
        }
      }
    );
}

Update capacitor.config.ts with:

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

ionic cap sync # synchronize Ionic with native project
code-push release <app-name> <public-folder-path> <target-version> -d <deployment>

# Example:
ionic cap sync

code-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

code-push app ls

List all deployments for a given app

code-push deployment ls <app-name>

# To show deployment tokens as well:
code-push deployment ls <app-name> -k

# Example:
code-push deployment ls myapp-ios

Delete All Deployments for an App

⚠️ This command will not rollback updates already installed by users.

code-push deployment clear <app-name> <deployment-name>

# Example:
code-push deployment clear myapp-android Production
code-push deployment clear myapp-android Staging

About

Updated version of Capacitor plugin for integrating CodePush on Capacitor 4+, Angular 14+

Resources

License

Contributing

Stars

Watchers

Forks

Languages

  • Objective-C 44.5%
  • TypeScript 35.3%
  • Java 10.4%
  • JavaScript 9.1%
  • Swift 0.2%
  • Ruby 0.2%
  • Other 0.3%