This CLI syncs the npm package version to the capacitor android and ios projects.
Github: https://github.com/bjesuiter/capacitor-sync-version-cli
Capacitor creates a folder for each platform in the root of your project, like android
, ios
, and electron
.
Since electron is in beta right now, it's not supported by this tool.
Capacitor does not deal with syncing the version number from your package.json to the mobile projects, mainly because this sync is not 1 to 1 possible without assumtions. This cli uses an automatic alogrithm to calculate the android versionCode based on the version string from package.json. The android versionCode is an ever increasing integer-32 defining the unique version for each app.
npm i cap-sync-version
In Android the plugin will automatically make the following modifications:
-
Add the following after
apply plugin: 'com.android.application'
at the top of./android/app/build.gradle
:def appProperties = new Properties(); file("app.properties").withInputStream { appProperties.load(it) }
-
Use these new properties to set
versionCode
andversionName
in./android/app/build.gradle
defaultConfig { versionCode appProperties.getProperty('versionCode').toInteger() versionName appProperties.getProperty('versionName') }
-
Create a file called
app.properties
under./android/app/
with the following two properties to the file:versionName: 0.0.1 versionCode: 1
Note: These values will be overwritten with the next call to this
cap-sync-version
cli.
Nothing to say
$> cap-sync-version --help
Usage: cap-sync-version [options]
Options:
-v, --version output the version number
-a, --android Sync package version to android. It will not update iOS, unless --ios is specified. (default: false)
-p, --android-allow-prerelease Note: This flag is disabled since 2.0.0 and will be ignored, because it produced unrelieable version codes in android. (default: false)
-i, --ios Sync package version to ios. It will not update Android, unless --android is specified. (default: false)
-plist, --plist [files...] Add additional plists to modify (ios only) (default: false)
-h, --help display help for command
General Information:
Version: 2.0.2
Purpose: This CLI syncs the npm package version to the capacitor android and ios projects.
Default Behavior: syncs the package version to android and ios, if available
Big Thanks for Contributions to
Package created after:
https://medium.com/netscape/a-guide-to-create-a-nodejs-command-line-package-c2166ad0452e
Pure ESM Package modeled after:
Sindre Sorhus - Pure ESM Package
All notable changes to this project will be documented here. The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
- Add Github link to Readme
- Now the android updater will make the necessary changes in the gradle file automatically instead of leaving it as a manual process for the user of this package. Note: If something breaks because of this, open an Issue or even a PR with a fix at: https://github.com/bjesuiter/capacitor-sync-version-cli
-
Update Dependencies:
- Commander to ^11.0.0
- fs-extra to ^11.1.1
- read-pkg to ^8.0.0
- Update npm shield in readme to be able to click on it to come to npm
- Add install instructions to Readme
- Fix an import bug with readPackageAsync
- Update Dependencies (see exact commits at the end of this github release)
- Note: 3.0.4 has this changelog published to npm (missing in 3.0.3)
-
Update Dependencies:
- commander to 8.0.0
- some
npm audit fix
updates - xo linting package
-
includes PR 13 by Lucas Zeer
- fixes commander 7.X options handling change (new: cli.opts property)
- fixes handling of default plattforms to update npm version for
- Fixed Version Numbers in Changelog for 3.0.0 & 3.0.1
- Contribution by Lucas Zeer: Possibility to add additional Plist files on iOS as targets for version sync
- BREAKING CHANGE: This CLI is now a pure ESM Package, which means, it needs NodeJS > 12.20 to run (see 'engines' field in package.json for more details)
- Updated all dev & normal dependencies to fix security problems
- fix version reporting for cap-sync-version cli
- Update readme
- Add tests for buildAndroidVersionCode function to make sure all android version code generation works correctly and especially continuously
- Updates for Readme & Changelog
- prohibit generating versions with prerelease part
- removes all code for prerelease versionCode generation for android to avoid instabilities in the version code
- Improve Badges in Readme
- Feature: ability to sync versions of android and ios capacitor projects with the npm package version
Initial Package Creation
Note: Periods in example android version codes are for better readability
- A version of 2.3.5-0 would have a version code of
2.030.500
and the version 2.3.5 would also have the version code2.030.500
, since the prerelease digits are zero per default. - A version of 2.3.5-1 would have a higher version code as 2.3.5, even though 2.3.5 is the final version of 2.3.5-1.
Version 2.3.5-1 would have the code
2.030.501
, but version 2.3.5 would have the code2.030.500
, which would result in rejection of the built apk or aab by the google play console. - iOS is not able to encode prerelease versions like this altogether.
One could fix above errors, but not without making the version generation algorithm more complicated and less intuitive. And when looking at the fact, that iOS doesn't even support prerelease versions, I'll simply increase the headroom of patch versions (where the developer can decide to mark them as beta or something).