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

Commit

Permalink
Add sign-git-tag config for 'npm version' command
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jul 12, 2012
1 parent 1fd1bdc commit 3072804
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
11 changes: 11 additions & 0 deletions doc/cli/config.md
Expand Up @@ -694,6 +694,17 @@ character to indicate reverse sort.

The shell to run for the `npm explore` command.

### sign-git-tag

* Default: false
* Type: Boolean

If set to true, then the `npm version` command will tag the version
using `-s` to add a signature.

Note that git requires you to have set up GPG keys in your git configs
for this to work properly.

### strict-ssl

* Default: true
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/config-defs.js
Expand Up @@ -189,6 +189,7 @@ Object.defineProperty(exports, "defaults", {get: function () {
, searchexclude: null
, searchsort: "name"
, shell : osenv.shell()
, "sign-git-tag": false
, "strict-ssl": true
, tag : "latest"
, tmp : temp
Expand Down Expand Up @@ -280,6 +281,7 @@ exports.types =
, "date", "-date"
, "keywords", "-keywords" ]
, shell : String
, "sign-git-tag": Boolean
, "strict-ssl": Boolean
, tag : String
, tmp : path
Expand Down
8 changes: 6 additions & 2 deletions lib/version.js
Expand Up @@ -10,7 +10,7 @@ var exec = require("./utils/exec.js")
, log = require("npmlog")
, npm = require("./npm.js")

version.usage = "npm version <newversion> [--message commit-message]"
version.usage = "npm version [<newversion> | major | minor | patch | build]\n"
+ "\n(run in package dir)\n"
+ "'npm -v' or 'npm --version' to print npm version "
+ "("+npm.version+")\n"
Expand Down Expand Up @@ -52,19 +52,23 @@ function checkGit (data, cb) {
, function (er, code, stdout, stderr) {
var lines = stdout.trim().split("\n").filter(function (line) {
return line.trim() && !line.match(/^\?\? /)
}).map(function (line) {
return line.trim()
})
if (lines.length) return cb(new Error(
"Git working directory not clean.\n"+lines.join("\n")))
write(data, function (er) {
if (er) return cb(er)
var message = npm.config.get("message").replace(/%s/g, data.version)
, sign = npm.config.get("sign-git-tag")
, flag = sign ? "-sm" : "-am"
chain
( [ [ exec, npm.config.get("git")
, ["add","package.json"], process.env, false ]
, [ exec, npm.config.get("git")
, ["commit", "-m", message ], process.env, false ]
, [ exec, npm.config.get("git")
, ["tag", "v"+data.version], process.env, false ] ]
, ["tag", "v"+data.version, flag, message], process.env, false ] ]
, cb )
})
})
Expand Down

0 comments on commit 3072804

Please sign in to comment.