Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurie Harper <laurie@holoweb.net>2011-04-06 10:58:10 +0400
committerisaacs <i@izs.me>2011-04-06 21:19:31 +0400
commitacccfda632d936dad4c66b86bc8a2edbfd337935 (patch)
treeecf3d85825bbd36f0b172add84dbf9a55ee30817 /lib/init.js
parent364dfc628c1625f5c3be4c515beec2cb15952146 (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/init.js')
-rw-r--r--lib/init.js10
1 files changed, 9 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")
})
}