Created
June 20, 2019 19:35
-
-
Save peteringram0/cabc17c57f3c732094f04e6dee5d7e3a to your computer and use it in GitHub Desktop.
bump package.json version number (patch only)
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/sh | |
function bump { | |
# full package version | |
PACKAGE_VERSION=$(cat package.json \ | |
| grep version \ | |
| head -1 \ | |
| awk -F: '{ print $2 }' \ | |
| sed 's/[",]//g' \ | |
| tr -d '[[:space:]]') | |
# current patch version | |
PATCH=${PACKAGE_VERSION##*.} | |
# Length of the new patch number | |
LENGTH=${#PATCH} | |
# Append 1 to patch version | |
NEWPATCHVERSION=`expr $PATCH + 1` | |
# major and minor string only (without patch) | |
MAJORMINOR="${PACKAGE_VERSION::-$LENGTH}" | |
# Merge all togeather | |
FULL="$MAJORMINOR$NEWPATCHVERSION" | |
# replace in file and pipe to temp | |
sed 's|\(.*"version"\): "\(.*\)",.*|\1: '"\"$FULL\",|" package.json > package.tmp | |
# remove old package.json | |
rm package.json | |
# replace package.json | |
mv package.tmp package.json | |
} | |
bump |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment