Skip to content

Commit

Permalink
feat: add git version update hook
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Apr 13, 2023
1 parent 5cf41b1 commit 39c435e
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .husky/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exit 0
48 changes: 48 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# types
commit_types='^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)'
minor_types='^(build|feat|revert)'
patch_types='^(chore|fix|perf|refactor)'

parens='(\(\w+\))?'
msg=':\s.+'

version_match='"version": *"[0-9.]\+"'
version_str='"version": '

# skip with env
if [ "$SKIP_PRE_COMMIT" = true ]; then
echo 'Skipping conventional-pre-commit hook...'
exit 0
fi

# read message to var
commit_msg=$(cat $1)

if [[ $commit_msg =~ $commit_types$parens'!?'$msg ]]; then
echo 'Use Conventional Commits: https://conventionalcommits.org'
exit 1
fi

# bump version function
bumpVersion() {
npm version --no-git-tag-version $1 > /dev/null

sed -i -e "s/$version_match/$version_str$(npm pkg get version)/gi" public/manifest.json
}

# version change type
if [[ $commit_msg =~ $commit_types$parens'!'$msg ]]; then
bumpVersion major
else
if [[ $commit_msg =~ $minor_types$parens$msg ]]; then
bumpVersion minor
else
if [[ $commit_msg =~ $patch_types$parens$msg ]]; then
bumpVersion patch
fi
fi
fi

exit 0
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"url": "git+https://github.com/nobkd/replace-maps.git"
},
"scripts": {
"postinstall": "husky install",
"icons": "svgexport icons/icon.svg public/icons/48.png 48:48 && svgexport icons/icon-grey.svg public/icons/48-grey.png 48:48 && svgexport icons/icon.svg public/icons/96.png 96:96 && svgexport icons/icon-grey.svg public/icons/96-grey.png 96:96",
"format": "prettier . --check",
"format:fix": "npm run format -- --write",
Expand All @@ -31,6 +32,7 @@
"@types/leaflet": "^1.9.3",
"@types/webextension-polyfill": "^0.10.0",
"@vitest/coverage-c8": "^0.29.8",
"husky": "^8.0.3",
"prettier": "^2.8.7",
"svgexport": "^0.4.2",
"typescript": "^5.0.2",
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"description": "Replace Maps iframes with OSM",
"manifest_version": 2,
"name": "Replace Maps",
"version": "1.0",
"version": "1.0.0",
"homepage_url": "https://github.com/nobkd/replace-maps",
"icons": {
"48": "icons/48.png",
Expand Down

0 comments on commit 39c435e

Please sign in to comment.