diff options
author | Laurie Harper <laurie@holoweb.net> | 2011-04-06 10:58:10 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-04-06 21:19:31 +0400 |
commit | acccfda632d936dad4c66b86bc8a2edbfd337935 (patch) | |
tree | ecf3d85825bbd36f0b172add84dbf9a55ee30817 /lib | |
parent | 364dfc628c1625f5c3be4c515beec2cb15952146 (diff) |
Default version and auther info from config for `npm init`.
Read the initial value of a package's `version`, `author.name`,
`author.email` and `author.url` properties from .npmrc when
running `npm init`, allowing the user to set defaults for
these fields.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/init.js | 10 | ||||
-rw-r--r-- | lib/utils/config-defs.js | 8 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/init.js b/lib/init.js index e00f7a43e..38b69e415 100644 --- a/lib/init.js +++ b/lib/init.js @@ -24,6 +24,12 @@ function init (args, cb) { readJson(path.join(folder, "package.json"), function (er, data) { if (er) data = {} + + data.author = data.author || + { name: npm.config.get("init.author.name") + , email: npm.config.get("init.author.email") + , url: npm.config.get("init.author.url") } + init_(data, folder, function (er) { npm.config.set("loglevel", ll) if (!er) log(path.join(folder, "package.json"), "written") @@ -207,7 +213,7 @@ function defaultLibWalker (folder, name, cb) { // sync - no io function defaultName (folder, data) { if (data.name) return data.name - return path.basename(folder).replace(/^node[_-]?|[-\.]?js$/g, '') + return path.basename(folder).replace(/^node[_-]?|[-\.]?js$/g, "") } function defaultVersion (folder, data, cb) { @@ -216,6 +222,8 @@ function defaultVersion (folder, data, cb) { function (er, code, out) { out = (out || "").trim() if (semver.valid(out)) return cb(null, out) + out = npm.config.get("init.version") + if (semver.valid(out)) return cb(null, out) return cb(null, "0.0.0") }) } diff --git a/lib/utils/config-defs.js b/lib/utils/config-defs.js index 4e43fac21..df8dec060 100644 --- a/lib/utils/config-defs.js +++ b/lib/utils/config-defs.js @@ -34,6 +34,10 @@ Object.defineProperty(exports, "defaults", {get: function () { , globalconfig : path.resolve(process.execPath, "..", "..", "etc", "npmrc") , group : process.env.SUDO_GID || process.getgid() , gzipbin : process.env.GZIPBIN || "gzip" + , "init.version" : "0.0.0" + , "init.author.name" : "" + , "init.author.email" : "" + , "init.author.url" : "" , logfd : stdio.stderrFD , loglevel : "warn" , long : false @@ -86,6 +90,10 @@ exports.types = , globalconfig : path , group : [String, Number] , gzipbin : String + , "init.version" : String + , "init.author.name" : String + , "init.author.email" : String + , "init.author.url" : String , logfd : [Number, Stream] , loglevel : ["silent","win","error","warn","info","verbose","silly"] , long : Boolean |