Created
June 16, 2016 11:45
-
-
Save maxlawton/582f0f0a9ce6c2c3e3913caab24d08e3 to your computer and use it in GitHub Desktop.
Update Bower and NPM package versions
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
#!/usr/bin/env bash | |
# ==================================================================== | |
if echo "$1" | grep -q -e '^-\+h\(elp\)\?$'; then | |
(cat <<EOF | |
bump-package | |
Update Bower and NPM package versions. | |
USAGE: bump-package [<new-version>] | |
This script attempts to update the "version" value in bower.json | |
and package.json. The target version may be specified as an | |
argument, or the script will attempt to determine the current | |
version from the Git repository. The first attempt at version | |
identification is via \`git flow release list\`, which will return | |
the version number if the current branch is a git flow | |
release. The second attempt will choose the most recent tag on the | |
repository. | |
EOF | |
) 1>&2; | |
exit 1 | |
fi | |
# -------------------------------------------------------------------- | |
command -v json >/dev/null 2>&1 || { | |
echo "This script requires the \`json\` command but it's not installed. Aborting." >&2 | |
exit 1 | |
} | |
# ==================================================================== | |
_branch_version() | |
{ | |
git flow release list \ | |
| grep -e '^* ' \ | |
| cut -d' ' -f2 | |
} | |
_file_version() | |
{ | |
json -f "$1" version | |
} | |
# -------------------------------------------------------------------- | |
echo -n "Current Versions:" | |
for f in {bower,package}.json | |
do | |
echo -n " ${f}="$(_file_version "$f") | |
done | |
echo | |
if [[ $# -gt 0 ]]; then | |
NEWVER="$1" | |
else | |
NEWVER=$(_branch_version) | |
fi | |
if [[ -z "$NEWVER" ]]; then | |
NEWVER=$(git tag | tail -n1 | sed -e 's/v//') | |
fi | |
echo "Bumping versions to ${NEWVER}" | |
for f in {bower,package}.json | |
do | |
CURVER=$(_file_version "$f") | |
if [[ "$CURVER" == "$NEWVER" ]]; then | |
echo " $f is already at version ${NEWVER}" | |
else | |
( | |
json -q -I -f "$f" -e "this.version = '${NEWVER}'" \ | |
&& echo " Bumped $f @ ${CURVER} --> ${NEWVER}" | |
) || echo " FAILED to bump ${f}??" | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment