UNPKG

1.08 kBJavaScriptView Raw
1// turns out tagging isn't very complicated
2// all the smarts are in the couch.
3module.exports = tag
4tag.usage = "npm tag <project>@<version> [<tag>]"
5
6tag.completion = require("./unpublish.js").completion
7
8var npm = require("./npm.js")
9 , mapToRegistry = require("./utils/map-to-registry.js")
10 , npa = require("npm-package-arg")
11 , semver = require("semver")
12 , log = require("npmlog")
13
14function tag (args, cb) {
15 var thing = npa(args.shift() || "")
16 , project = thing.name
17 , version = thing.rawSpec
18 , t = args.shift() || npm.config.get("tag")
19
20 t = t.trim()
21
22 if (!project || !version || !t) return cb("Usage:\n"+tag.usage)
23
24 if (semver.validRange(t)) {
25 var er = new Error("Tag name must not be a valid SemVer range: " + t)
26 return cb(er)
27 }
28
29 log.warn("tag", "This command is deprecated. Use `npm dist-tag` instead.")
30
31 mapToRegistry(project, npm.config, function (er, uri, auth) {
32 if (er) return cb(er)
33
34 var params = {
35 version : version,
36 tag : t,
37 auth : auth
38 }
39 npm.registry.tag(uri, params, cb)
40 })
41}