Ask Your Question
2

What is the method for invoking npm version in package.json scripts with a varying value?

asked 2023-06-10 03:28:54 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-10 03:36:02 +0000

huitzilopochtli gravatar image

To invoke npm version in package.json scripts with a varying value, you can use the following approach:

  1. Declare the varying value as an environment variable in your script.

  2. 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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-10 03:28:54 +0000

Seen: 18 times

Last updated: Jun 10 '23