Skip to content

Instantly share code, notes, and snippets.

@peteringram0
Created June 20, 2019 19:35
Show Gist options
  • Save peteringram0/cabc17c57f3c732094f04e6dee5d7e3a to your computer and use it in GitHub Desktop.
Save peteringram0/cabc17c57f3c732094f04e6dee5d7e3a to your computer and use it in GitHub Desktop.
bump package.json version number (patch only)
#!/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