Last active
March 19, 2019 16:58
-
-
Save alexcode/13c5d48843929f1a9deee75628b2212f to your computer and use it in GitHub Desktop.
Nativescript. Retrieve version from package.json and set AndroidManifest.xml and Info.plist.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# First param can be th project root directory | |
if [ $1 != "" ]; then | |
PROJ_DIR=$1 | |
else | |
PROJ_DIR=. | |
fi | |
PACKAGE_FILE=${PROJ_DIR}/package.json | |
MANIFEST_FILE=${PROJ_DIR}/app/App_Resources/Android/src/main/AndroidManifest.xml | |
PLIST_FILE=${PROJ_DIR}/app/App_Resources/iOS/Info.plist | |
get_versions() { | |
if [ $# -ne 1 ]; then | |
echo "internal error" | |
exit 1 | |
fi | |
PACKAGE_VERSION=$(cat $1 \ | |
| grep version \ | |
| head -1 \ | |
| awk -F: '{ print $2 }' \ | |
| sed 's/[",\t ]//g') | |
VERSION_NAME=${PACKAGE_VERSION} | |
MAJOR=${PACKAGE_VERSION:0:1} | |
MINOR=${PACKAGE_VERSION:2:1} | |
PATCH=${PACKAGE_VERSION:4:1} | |
VERSION_CODE=$((${PATCH} + ${MINOR} * 100 + ${MAJOR} * 10000)) | |
} | |
update_manifest() | |
{ | |
if [ $# -ne 3 ]; then | |
echo "internal error" | |
exit 1 | |
fi | |
sed -i .bak -e "s/versionCode=\"[0-9]\{1,\}\"/versionCode=\"$2\"/g" $1 | |
sed -i .bak -e "s/versionName=\"[^\"]*\"/versionName=\"$3\"/g" $1 | |
if [ $? -eq 0 ]; then | |
$(rm $1.bak) | |
else | |
echo "Internal error, reverting changes" | |
$(mv $1.bak $1) | |
fi | |
echo "versionName $3 and versionCode $2 has been set in $1" | |
} | |
update_plist() | |
{ | |
if [ $# -ne 2 ]; then | |
echo "internal error" | |
exit 1 | |
fi | |
plutil -replace CFBundleShortVersionString -string $2 $1 | |
plutil -replace CFBundleVersion -string $2 $1 | |
echo "CFBundleShortVersionString and CFBundleVersion $2 has been set in $1" | |
} | |
get_versions ${PACKAGE_FILE} | |
update_plist ${PLIST_FILE} ${VERSION_NAME} | |
update_manifest ${MANIFEST_FILE} ${VERSION_CODE} ${VERSION_NAME} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment