Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/allow invalid short version string flag #316

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 58 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,64 @@ $ react-native-version

<!-- START cli -->

-V, --version output the version number
-a, --amend Amend the previous commit. This is done automatically when react-native-version is run from the "version" or "postversion" npm script. Use "--never-amend" if you never want to amend. Also, if the previous commit is a valid npm-version commit, react-native-version will update the Git tag pointing to this commit.
--skip-tag For use with "--amend", if you don't want to update Git tags. Use this option if you have git-tag-version set to false in your npm config or you use "--no-git-tag-version" during npm-version.
-A, --never-amend Never amend the previous commit.
-b, --increment-build Only increment build number.
-B, --never-increment-build Never increment build number.
-d, --android [path] Path to your "android/app/build.gradle" file. (default: "android/app/build.gradle")
-i, --ios [path] Path to your "ios/" folder. (default: "ios")
-L, --legacy Version iOS using agvtool (macOS only). Requires Xcode Command Line Tools.
-q, --quiet Be quiet, only report errors.
-r, --reset-build Reset build number back to "1" (iOS only). Unlike Android's "versionCode", iOS doesn't require you to bump the "CFBundleVersion", as long as "CFBundleShortVersionString" changes. To make it consistent across platforms, react-native-version bumps both by default. You can use this option if you prefer to keep the build number value at "1" after every version change. If you then need to push another build under the same version, you can use "-bt ios" to increment.
-s, --set-build <number> Set a build number. WARNING: Watch out when setting high values. This option follows Android's app versioning specifics - the value has to be an integer and cannot be greater than 2100000000. You cannot decrement this value after publishing to Google Play! More info at: https://developer.android.com/studio/publish/versioning.html#appversioning
--generate-build Generate build number from the package version number. (e.g. build number for version 1.22.3 will be 1022003)
-t, --target <platforms> Only version specified platforms, e.g. "--target android,ios".
-h, --help output usage information
-V, --version output the version number
-a, --amend Amend the previous commit. This is done
automatically when react-native-version
is run from the "version" or
"postversion" npm script. Use
"--never-amend" if you never want to
amend. Also, if the previous commit is
a valid npm-version commit,
react-native-version will update the
Git tag pointing to this commit.
--skip-tag For use with "--amend", if you don't
want to update Git tags. Use this
option if you have git-tag-version set
to false in your npm config or you use
"--no-git-tag-version" during
npm-version.
-A, --never-amend Never amend the previous commit.
-b, --increment-build Only increment build number.
-B, --never-increment-build Never increment build number.
-d, --android [path] Path to your "android/app/build.gradle"
file. (default:
"android/app/build.gradle")
-i, --ios [path] Path to your "ios/" folder. (default:
"ios")
-L, --legacy Version iOS using agvtool (macOS only).
Requires Xcode Command Line Tools.
-q, --quiet Be quiet, only report errors.
-r, --reset-build Reset build number back to "1" (iOS
only). Unlike Android's "versionCode",
iOS doesn't require you to bump the
"CFBundleVersion", as long as
"CFBundleShortVersionString" changes.
To make it consistent across platforms,
react-native-version bumps both by
default. You can use this option if you
prefer to keep the build number value
at "1" after every version change. If
you then need to push another build
under the same version, you can use
"-bt ios" to increment.
-s, --set-build <number> Set a build number. WARNING: Watch out
when setting high values. This option
follows Android's app versioning
specifics - the value has to be an
integer and cannot be greater than
2100000000. You cannot decrement this
value after publishing to Google Play!
More info at:
https://developer.android.com/studio/publish/versioning.html#appversioning
--generate-build Generate build number from the package
version number. (e.g. build number for
version 1.22.3 will be 1022003)
-t, --target <platforms> Only version specified platforms, e.g.
"--target android,ios".
--allow-invalid-short-version-string Allow invalid value for
CFBundleShortVersionString. (e.g.
1.5.0-staging.1.
-h, --help display help for command

<!-- END cli -->

Expand Down
1 change: 1 addition & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ program
'Only version specified platforms, e.g. "--target android,ios".',
list
)
.option("--allow-invalid-short-version-string", "Allow invalid value for CFBundleShortVersionString. (e.g. 1.5.0-staging.1.")
.parse(process.argv);

rnv.version(program);
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ function getNewVersionCode(programOpts, versionCode, versionName, resetBuild) {
* CFBundleShortVersionString must be a string composed of three period-separated integers.
* @private
* @param {String} versionName The full version string
* @param {Boolean} allowInvalidShortVersionString Whether or not to allow short version strings like '1.2.3-beta.1'
* @return {String} e.g. returns '1.2.3' for given '1.2.3-beta.1'. Returns `versionName` if no match is found.
*/
function getCFBundleShortVersionString(versionName) {
function getCFBundleShortVersionString(versionName, allowInvalidShortVersionString = false) {
if (allowInvalidShortVersionString) {
return versionName
}

const match =
versionName && typeof versionName === "string"
? versionName.match(/\d*\.\d*.\d*/g)
Expand Down Expand Up @@ -443,7 +448,8 @@ function version(program, projectPath) {
!programOpts.incrementBuild
? {
CFBundleShortVersionString: getCFBundleShortVersionString(
appPkg.version
appPkg.version,
programOpts.allowInvalidShortVersionString,
)
}
: {},
Expand Down
16 changes: 16 additions & 0 deletions test/shortBundleVerions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,19 @@ test(
t.is(v, 'garbage');
}
);

test(
"CFBundleShortVersionString allow invalid, with invalid",
t => {
const v = getCFBundleShortVersionString('1.2.3-staging.1', true);
t.is(v, '1.2.3-staging.1');
}
);

test(
"CFBundleShortVersionString allow invalid, with valid",
t => {
const v = getCFBundleShortVersionString('1.2.3', true);
t.is(v, '1.2.3');
}
);