Skip to content

Commit

Permalink
Add script for bumping the version (#7)
Browse files Browse the repository at this point in the history
* Ignore backup copies of package.json in Git

* Add script for bumping the version
  • Loading branch information
korya committed Oct 24, 2023
1 parent c0e8f1b commit 66d1bff
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
coverage/
planitar-rnfs-untar-*.tgz
package.json.*
.*.sw[a-z]*
64 changes: 64 additions & 0 deletions script/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash

set -e

if [ -z "$1" ]; then
echo "Usage: $0 <major|minor|patch>"
exit 1
fi

if [ ! -f package.json ]; then
echo 'Error: package.json not found'
echo ''
echo 'Run this script from the root of the repository'
exit 1
fi

if [[ -n "$(git status --porcelain --untracked-files=no)" ]]; then
echo 'Error: Working directory is not clean'
echo ''
echo 'Commit or stash your changes before running this script'
exit 1
fi

case "$1" in
major)
jqExpr='.version |= ((split(".") | .[0] | tonumber + 1 | tostring) + ".0.0")'
;;

minor)
jqExpr='.version |= ((split(".") | .[0] + "." + (.[1] | tonumber + 1 | tostring) + ".0"))'
;;

patch)
jqExpr='.version |= ((split(".") | .[0] + "." + .[1] + "." + (.[2] | tonumber + 1 | tostring)))'
;;

*)
echo "Usage: $0 <major|minor|patch>"
exit 1
;;
esac

jq --indent 2 "${jqExpr}" package.json >package.json.tmp
mv package.json package.json.bak
mv package.json.tmp package.json

npm i


gitTag="v$(jq -r .version package.json)"

echo ''
echo 'Done'
echo ''
echo '1. Review and commit the changes:'
git status -s
git diff package.json
echo ''
echo '2. Tag the release:'
echo " git tag -a ${gitTag} -m '${gitTag}'"
echo ''
echo '3. Publish the release:'
echo " git push origin ${gitTag}"
echo ' npm publish'

0 comments on commit 66d1bff

Please sign in to comment.