Hey everyone !
I don't like having to manually update the
package.json file's patch version (the 'x' in '1.0.x').
Because of that, I decided to take advantage of git hooks and wrote some scripts to make my life easier.
You can find the scripts here but I'll make a dedicated repo if this seem useful to people.
Here is how it works:
- I assume everyone is setting up a tag for major/minor version changes ('x.x.0')
- I assume the
scripts folder is at the root of the repository (to generate the hooks)
Then, after cloning a repo, I do this:
This will generate a post and a pre commit hook.
The pre-commit hook is used to automatically create a new tag if major or minor version has changed. Inside
The post-commit hook is used to automatically update the package.json after each commit. It increases the patch version by one (each commit is considered a patch) by counting the number of commits since the last tag (or the beginning if no tags made)
The post-commit hook (file
setup_readme_version.sh) also updates the
readme.md of my project to write
_Current repository version : v<major>.<minor>.<patch>_
If you don't want this behavior, you don't have anything to do. If you want it, you have to put
_Current repository version : v_ somewhere in your readme. The regexp will match and update it.
And, if you want to bump minor or major version, simply do it in your
package.json and the hooks will properly read and process it. Even updating the readme. And a new tag will be created.
Let me know what you think about this stuff !