From acccfda632d936dad4c66b86bc8a2edbfd337935 Mon Sep 17 00:00:00 2001 From: Laurie Harper Date: Wed, 6 Apr 2011 02:58:10 -0400 Subject: 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. --- doc/config.md | 28 ++++++++++++++++++++++++++++ lib/init.js | 10 +++++++++- lib/utils/config-defs.js | 8 ++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/doc/config.md b/doc/config.md index 8b0d43872..244d38e91 100644 --- a/doc/config.md +++ b/doc/config.md @@ -249,6 +249,34 @@ user. The gzip binary +### init.version + +* Default: "0.0.0" +* Type: String + +The value `npm init` should use by default for the package version. + +### init.author.name + +* Default: "0.0.0" +* Type: String + +The value `npm init` should use by default for the package author's name. + +### init.author.email + +* Default: "0.0.0" +* Type: String + +The value `npm init` should use by default for the package author's email. + +### init.author.url + +* Default: "0.0.0" +* Type: String + +The value `npm init` should use by default for the package author's homepage. + ### logfd * Default: stderr file descriptor 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 -- cgit v1.2.3