1.1.0 • Published 2 years ago

capacitor-plugin-sync-version v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

capacitor-plugin-sync-version

The idea is from the another project capacitor-sync-version

npm package version PRs Welcome

Syncing version from package.json to target platform in the capacitor projects.

The version are configured separately in package.json for Android and iOS, because this sync is not 1 to 1 possible without assumtions.

{
  "name": "Your App",
  ...
  "androidVersionName": "1.0.0",
  "androidVersionCode": "2",
  "iOSVersion": "1.1.0",
  "iOSBuild": "2",
}
Android nativepackage.json
versionNameandroidVersionName
versionCodeandroidVersionCode
iOS nativepackage.json
versioniOSVersion
buildiOSBuild

The androidVersionCode and iOSBuild should be integer and increase each time

Currently supported platforms are: [android, ios].

Installation

npm add --save-dev capacitor-plugin-sync-version

Additional preparation for Android only

Step 1. Create a file named app.properties in ./android/app/, then add the following properties:

versionName=1.0.0
versionCode=1

These properties will be updated when capacitor-plugin-sync-version running.

Step 2. Adjust codes to referrence these properties in ./android/app/build.gradle.

  • Add the following codes after apply plugin: 'com.android.application':

    def appProperties = new Properties();
    file("app.properties").withInputStream { appProperties.load(it) }
  • Update properties in defaultConfig {} block:

    defaultConfig {
      versionCode appProperties.getProperty("versionCode").toInteger()
      versionName appProperties.getProperty("versionName")
    }

Usage

The simplest way to use capacitor-plugin-sync-version is running it in the capacitor hooks.

Just adding the following script to package.json:

{
  "scripts": {
    "capacitor:copy:before": "capacitor-plugin-sync-version"
  }
}

In this way, capacitor-plugin-sync-version will be run before capacitor copy command, e.g., npx cap copy npx cap sync.

Other ways to run capacitor-sync-version are:

# sync for android only
capacitor-plugin-sync-version android

# sync for both android and ios
capacitor-plugin-sync-version android ios

Licence

MIT