Created
March 18, 2016 18:20
-
-
Save alinz/f5a0d804dc81efa5e92c to your computer and use it in GitHub Desktop.
Simple bash script to update your react-native version.
This file contains 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/bash | |
usage () | |
{ | |
echo "Version Update" | |
echo "" | |
echo "Usage:" | |
echo "" | |
echo " Options:" | |
echo " -h show usage/help" | |
echo " -c <string> optional current version" | |
echo " -n <string> requried next version" | |
echo "" | |
echo "e.g." | |
echo " version-update -c 1.0.0 -n 1.0.1" | |
echo " version-update -n 1.0.1" | |
echo "" | |
} | |
replace() | |
{ | |
local FIND=$1 | |
local REPLACE=$2 | |
local FILE=$3 | |
sed -i '' "s/$FIND/$REPLACE/g" $FILE | |
} | |
jsonValue() | |
{ | |
KEY=$1 | |
num=1 | |
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' \ | |
| tr -d '"' | sed -n ${num}p | |
} | |
CURRENT= | |
NEXT= | |
while getopts "hc:n:" OPTION | |
do | |
case $OPTION in | |
h) | |
usage | |
exit 1 | |
;; | |
c) | |
CURRENT=$OPTARG | |
;; | |
n) | |
NEXT=$OPTARG | |
;; | |
?) | |
usage | |
exit | |
;; | |
esac | |
done | |
if [ -z "$NEXT" ]; then | |
echo "next version must be defined" | |
exit 1 | |
fi | |
# set CURRENT version by extracting version from package.json. | |
if [ -z "$CURRENT" ]; then | |
CURRENT=$(cat package.json | jsonValue version) | |
CURRENT=`echo $CURRENT` # this command actually trim the string WTF!!! | |
fi | |
replace "$CURRENT" "$NEXT" "package.json" | |
replace "$CURRENT" "$NEXT" "app/meta.js" | |
replace "$CURRENT" "$NEXT" "android/app/src/main/AndroidManifest.xml" | |
replace "$CURRENT" "$NEXT" "ios/MyAwesomeApp/Info.plist" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment