Before I do a small release and tag it, I'd like to update the package.json to reflect the new version of the program.
Is there a way to edit the file package.json
automatically?
Would using a git pre-release hook
help?
Before I do a small release and tag it, I'd like to update the package.json to reflect the new version of the program.
Is there a way to edit the file package.json
automatically?
Would using a git pre-release hook
help?
If you are using yarn you can use
This will increment
package.json
version by patch(0.0.x)
, commit, and tag it with formatv0.0.0
Likewise you can bump minor or major version by using
--minor
or--major
When pushing to git ensure you also push the tags with
--follow-tags
You can also create a script for it
Simply run it by typing
yarn release-it
As an addition to
npm version
you can use the--no-git-tag-version
flag if you want a version bump but no tag or a new commit:https://docs.npmjs.com/cli/version
I am using husky and git-branch-is:
Read more about npm version
Webpack or Vue.js
If you are using webpack or Vue.js, you can display this in the UI using Auto inject version - Webpack plugin
NUXT
In
nuxt.config.js
:Inside your
template
for example in the footer:This is what I normally do with my projects:
The first line,
npm version patch
, will increase the patch version by 1 (x.x.1 to x.x.2) inpackage.json
. Then you add all files -- includingpackage.json
which at that point has been modified. Then, the usualgit commit
andgit push
, and finallynpm publish
to publish the module.I hope this makes sense...
Merc.
Right answer
To do so, just
npm version patch
=)My old answer
There is no
pre-release
hook originally ingit
. At least,man githooks
does not show it.If you're using
git-extra
(https://github.com/visionmedia/git-extras), for instance, you can use apre-release
hook which is implemented by it, as you can see at https://github.com/visionmedia/git-extras/blob/master/bin/git-release. It is needed only a.git/hook/pre-release.sh
executable file which edits yourpackage.json
file. Committing, pushing and tagging will be done by thegit release
command.If you're not using any extension for
git
, you can write a shell script (I'll name itgit-release.sh
) and than you can alias it togit release
with something like:git config --global alias.release '!sh path/to/pre-release.sh $1'
You can, than, use
git release 0.4
which will executepath/to/pre-release.sh 0.4
. Your script can editpackage.json
, create the tag and push it to the server.To give a more up-to-date approach.
package.json
Then you run it:
Which will:
... run tests ...
change your
package.json
to a next minor version (e.g: 1.8.1 to 1.9.0)push your changes
create a new git tag release and
publish your npm package.
--force
is to show who is the boss! Jokes aside see https://github.com/npm/npm/issues/8620