Skip to content

Instantly share code, notes, and snippets.

@TSFoster
Last active November 15, 2019 11:28
Show Gist options
  • Save TSFoster/ea729827a080bcfb4f50da0bc79bdc12 to your computer and use it in GitHub Desktop.
Save TSFoster/ea729827a080bcfb4f50da0bc79bdc12 to your computer and use it in GitHub Desktop.
pre-commit hook for elm packages with a package.json
#!/bin/sh
ELM_JSON_VERSION="$(jq -r .version elm.json)"
PACKAGE_JSON_VERSION="$(jq -r .version package.json)"
if [ $ELM_JSON_VERSION != $PACKAGE_JSON_VERSION ]; then
echo "Version in elm.json ($ELM_JSON_VERSION) does not match version in package.json ($PACKAGE_JSON_VERSION)"
if [ -n "$(git status --porcelain package.json)" ]; then
echo "Cannot fix package.json as it contains unstaged changes" >&2
exit 1
fi
echo "Assuming elm.json is correct, fixing package.json"
mv package.json package.json.tmp
jq ".version |= \"$ELM_JSON_VERSION\"" package.json.tmp > package.json
rm package.json.tmp
git add package.json
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment