Currently trying to configure npm
so that when I run npm version
, it sets the version in package.json, then adds everything currently staged to its commit, and npm docs make it seem like this is possible, but I keep getting the error stating that the command can't be run because my working directory isn't clean.
Ideally, I'd like to not have to add -f
to my npm version
command.
My package.json
"scripts": {
...
"nv": "node newversion.js", /*Creates a changelog and runs npm version*/
"preversion": "git add -A",
"version": "git add -A"
}
npm version 1.4.1 -m "%s -> custom scrollbars"
-> npm ERR! Git working directory not clean.
Manually staging before running npm version
doesn't work either.
Is there something I'm missing? I'm not super npm- or package.json-knowledgeable so any help would be much appreciated.
In the end, the goal is to be able to run npm-version
and it stages anything in working directory and adds it to the commit that npm-version
makes.
CodePudding user response:
Another approach would be to use package standard-version
, which does generate a changelog and update the version.
See "Automatically generate and release a changelog using Node.js
" (Jul. 2021) from Indermohan Singh (Software Developer at Ubiq.ai | Creator of ragakosh.com)
npm run release
Running the command above will show the following message on the screen:
> [email protected] release /home/imsingh/Develop/inder/changelog
> standard-version
✔ bumping version in package.json from 1.0.0 to 1.1.0
✔ bumping version in package-lock.json from 1.0.0 to 1.1.0
✔ created CHANGELOG.md
✔ outputting changes to CHANGELOG.md
✔ committing package-lock.json and package.json and CHANGELOG.md
✔ tagging release v1.1.0
ℹ Run `git push --follow-tags origin master && npm publish` to publish