To invoke npm version
in package.json scripts with a varying value, you can use the following approach:
Declare the varying value as an environment variable in your script.
Use the environment variable in the npm version command.
For example, consider the following script:
{
"scripts": {
"version-patch": "VERSION_TYPE=patch npm version $VERSION_TYPE",
"version-minor": "VERSION_TYPE=minor npm version $VERSION_TYPE",
"version-major": "VERSION_TYPE=major npm version $VERSION_TYPE"
}
}
In this script, we declare an environment variable VERSION_TYPE
with the value patch
, minor
, or major
, respectively, in the version-patch
, version-minor
, and version-major
scripts. We then use the environment variable in the npm version
command.
To run this script, you can use the following commands:
npm run version-patch
npm run version-minor
npm run version-major
These commands will invoke the npm version
command with the corresponding VERSION_TYPE
value, incrementing the version number accordingly.
Asked: 2023-06-10 03:28:54 +0000
Seen: 18 times
Last updated: Jun 10 '23