diff options
author | isaacs <i@izs.me> | 2011-04-30 21:55:01 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-04-30 22:00:00 +0400 |
commit | 1287c7fd4481c921881a39ed27fee7965e3b241a (patch) | |
tree | 0c41fae6c9fdf33e2aeedcab3da87f89bc7b0084 /lib/utils/read-json.js | |
parent | 29d3d59f124467276e0637ca281222aec39e1bec (diff) |
Read contributors out of AUTHORS file, if present
Diffstat (limited to 'lib/utils/read-json.js')
-rw-r--r-- | lib/utils/read-json.js | 81 |
1 files changed, 64 insertions, 17 deletions
diff --git a/lib/utils/read-json.js b/lib/utils/read-json.js index c2bd2a0cf..d15518a30 100644 --- a/lib/utils/read-json.js +++ b/lib/utils/read-json.js @@ -30,26 +30,67 @@ function readJson (jsonFile, opts, cb) { } } - fs.readFile( path.join(path.dirname(jsonFile), "wscript") - , function (er, data) { + var wscript = null + , contributors = null + , serverjs = null + + if (opts.wscript != null) { + wscript = opts.wscript + next() + } else fs.readFile( path.join(path.dirname(jsonFile), "wscript") + , function (er, data) { if (er) opts.wscript = false - else opts.wscript = data.toString().match(/(^|\n)def build\b/) - && data.toString().match(/(^|\n)def configure\b/) - fs.stat( path.join(path.dirname(jsonFile), "server.js") - , function (er, st) { - if (er) opts.serverjs = false - else opts.serverjs = st.isFile() - - fs.readFile(jsonFile, processJson(opts, function (er, data) { - if (er) return cb(er) - var doLoad = !(jsonFile.indexOf(npm.cache) === 0 && - path.basename(path.dirname(jsonFile)) !== "package") - if (!doLoad) return cb(er, data) - loadPackageDefaults(data, path.dirname(jsonFile), cb) - })) - }) + else opts.wscript = !!(data.toString().match(/(^|\n)def build\b/) + && data.toString().match(/(^|\n)def configure\b/)) + wscript = opts.wscript + next() + }) + + if (opts.contributors != null) { + contributors = opts.contributors + next() + } else fs.readFile( path.join(path.dirname(jsonFile), "AUTHORS") + , function (er, data) { + if (er) opts.contributors = false + else { + data = data.toString().split(/\r?\n/).map(function (l) { + l = l.trim().split("#").shift() + return l + }).filter(function (l) { return l }) + opts.contributors = data + } + contributors = opts.contributors + next() + }) + + if (opts.serverjs != null) { + serverjs = opts.serverjs + next() + } else fs.readFile( path.join(path.dirname(jsonFile), "server.js") + , function (er, data) { + if (er) opts.serverjs = false + else opts.serverjs = st.isFile() + serverjs = opts.serverjs + next() }) + + function next () { + if (wscript === null + || contributors === null + || serverjs === null) { + return + } + + fs.readFile(jsonFile, processJson(opts, function (er, data) { + if (er) return cb(er) + var doLoad = !(jsonFile.indexOf(npm.cache) === 0 && + path.basename(path.dirname(jsonFile)) !== "package") + if (!doLoad) return cb(er, data) + loadPackageDefaults(data, path.dirname(jsonFile), cb) + })) + } } + function processJson (opts, cb) { if (typeof cb !== "function") cb = opts, opts = {} if (typeof cb !== "function") { @@ -205,6 +246,12 @@ function processObject (opts, cb) { return function (er, json) { } } + // if it has an AUTHORS, then credit them + if (opts.contributors && Array.isArray(opts.contributors) + && opts.contributors.length) { + json.contributors = opts.contributors + } + // if it has a server.js, then start it. if (opts.serverjs && !scripts.start) { scripts.start = "node server.js" |