Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Add auto-increment support to version command
Browse files Browse the repository at this point in the history
Pass "major", "minor", or "patch" to increment the existing version
by that amount.
  • Loading branch information
grncdr authored and isaacs committed Oct 17, 2011
1 parent d049d1f commit ae6a2d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions doc/cli/version.md
Expand Up @@ -10,8 +10,13 @@ npm-version(1) -- Bump a package version
Run this in a package directory to bump the version and write the new
data back to the package.json file.

The `newversion` argument should be a valid semver string, *or* a valid
second argument to semver.inc (one of "patch", "minor", or "major"). In
the second case, the existing version will be incremented by that amount.

If run in a git repo, it will also create a version commit and tag, and
fail if the repo is not clean.

If supplied with `--message` (shorthand: `-m`) command line option, npm
will use it as a commit message when creating a version commit.

Expand Down
5 changes: 3 additions & 2 deletions lib/version.js
Expand Up @@ -21,10 +21,11 @@ version.usage = "npm version <newversion> [--message commit-message]"

function version (args, cb) {
if (args.length !== 1) return cb(version.usage)
var newVer = semver.valid(args[0])
if (!newVer) return cb(version.usage)
readJson(path.join(process.cwd(), "package.json"), function (er, data) {
if (er) return log.er(cb, "No package.json found")(er)
var newVer = semver.valid(args[0])
if (!newVer) newVer = semver.inc(data.version, args[0])
if (!newVer) return cb(version.usage)
if (data.version === newVer) return cb(new Error("Version not changed"))
data.version = newVer
Object.keys(data).forEach(function (k) {
Expand Down

0 comments on commit ae6a2d7

Please sign in to comment.