Permalink
Browse files

Read contributors out of AUTHORS file, if present

  • Loading branch information...
1 parent 29d3d59 commit 1287c7fd4481c921881a39ed27fee7965e3b241a @isaacs isaacs committed Apr 30, 2011
Showing with 107 additions and 56 deletions.
  1. +31 −0 AUTHORS
  2. +12 −8 bin/read-package-json.js
  3. +64 −17 lib/utils/read-json.js
  4. +0 −31 package.json
View
@@ -0,0 +1,31 @@
+# Authors ordered by first contribution.
+Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)
+Steve Steiner <ssteinerX@gmail.com> (http://websaucesoftware.com/blog/)
+Mikeal Rogers <mikeal.rogers@gmail.com> (http://www.mikealrogers.com/)
+Aaron Blohowiak <aaron.blohowiak@gmail.com> (http://aaronblohowiak.com/)
+Martyn Smith <martyn@dollyfish.net.nz> (http://dollyfish.net.nz/)
+Mathias Pettersson <mape@mape.me> (http://mape.me/)
+Brian Hammond <brian@fictorial.com> (http://fictorial.com/)
+Charlie Robbins <charlie.robbins@gmail.com> (http://www.charlierobbins.com/)
+Francisco Treacy <francisco.treacy@gmail.com> (http://franciscotreacy.com/)
+Cliffano Subagio <cliffano@gmail.com> (http://blog.cliffano.com/)
+Christian Eager <christian.eager@nokia.com> (http://perpenduum.com)
+Dav Glass <davglass@gmail.com> (http://blog.davglass.com)
+Alex K. Wolfe <alexkwolfe@gmail.com>
+James Sanders <jimmyjazz14@gmail.com> (http://james-sanders.com/)
+Reid Burke <me@reidburke.com> (http://reidburke.com/)
+Arlo Breault <arlolra@gmail.com> (http://thoughtherder.com/)
+Timo Derstappen <teemow@gmail.com> (http://teemow.com)
+Bradley Meck <bradley.meck@gmail.com>
+Bart Teeuwisse <bart.teeuwisse@thecodemill.biz> (http://thecodemill.biz/)
+Ben Noordhuis <info@bnoordhuis.nl> (http://bnoordhuis.nl/)
+Tor Valamo <tor.valamo@gmail.com> (http://www.magnimedia.no/)
+Whyme.Lyu <5longluna@gmail.com> (http://whyme.kuantu.com/)
+Olivier Melcher <olivier.melcher@gmail.com>
+Tomaž Muraus <kami@k5-storitve.net> (http://www.tomaz-muraus.info)
+Evan Meagher <evan.meagher@gmail.com> (http://evanmeagher.net/)
+Orlando Vazquez <ovazquez@gmail.com> (http://2wycked.net/)
+George Miroshnykov <gmiroshnykov@lohika.com>
+Geoff Flarity (http://ca.linkedin.com/pub/geoff-flarity/a/536/43a)
+Pete Kruckenberg <pete@kruckenberg.com>
+Chris Wong <chris@chriswongstudio.com>
@@ -3,16 +3,20 @@ if (argv.length < 3) {
console.error("Usage: read-package.json <file> [<fields> ...]")
process.exit(1)
}
+
var fs = require("fs")
, file = argv[2]
- , data = JSON.parse(fs.readFileSync(file, "utf8"))
+ , readJson = require("../lib/utils/read-json")
-if (argv.length === 3) console.log(data)
-else argv.slice(3).forEach(function (field) {
- field = field.split(".")
- var val = data
- field.forEach(function (f) {
- val = val[f]
+readJson(file, function (er, data) {
+ if (er) throw er
+ if (argv.length === 3) console.log(data)
+ else argv.slice(3).forEach(function (field) {
+ field = field.split(".")
+ var val = data
+ field.forEach(function (f) {
+ val = val[f]
+ })
+ console.log(val)
})
- console.log(val)
})
@@ -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"
View
@@ -7,37 +7,6 @@
, "config" : { "publishtest" : false }
, "homepage" : "http://npmjs.org/"
, "author" : "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)"
-, "contributors" :
- [ "Steve Steiner <ssteinerX@gmail.com> (http://websaucesoftware.com/blog/)"
- , "Mikeal Rogers <mikeal.rogers@gmail.com> (http://www.mikealrogers.com/)"
- , "Aaron Blohowiak <aaron.blohowiak@gmail.com> (http://aaronblohowiak.com/)"
- , "Martyn Smith <martyn@dollyfish.net.nz> (http://dollyfish.net.nz/)"
- , "Mathias Pettersson <mape@mape.me> (http://mape.me/)"
- , "Brian Hammond <brian@fictorial.com> (http://fictorial.com/)"
- , "Charlie Robbins <charlie.robbins@gmail.com> (http://www.charlierobbins.com/)"
- , "Francisco Treacy <francisco.treacy@gmail.com> (http://franciscotreacy.com/)"
- , "Cliffano Subagio <cliffano@gmail.com> (http://blog.cliffano.com/)"
- , "Christian Eager <christian.eager@nokia.com> (http://perpenduum.com)"
- , "Dav Glass <davglass@gmail.com> (http://blog.davglass.com)"
- , "Alex K. Wolfe <alexkwolfe@gmail.com>"
- , "James Sanders <jimmyjazz14@gmail.com> (http://james-sanders.com/)"
- , "Reid Burke <me@reidburke.com> (http://reidburke.com/)"
- , "Arlo Breault <arlolra@gmail.com> (http://thoughtherder.com/)"
- , "Timo Derstappen <teemow@gmail.com> (http://teemow.com)"
- , "Bradley Meck <bradley.meck@gmail.com>"
- , "Bart Teeuwisse <bart.teeuwisse@thecodemill.biz> (http://thecodemill.biz/)"
- , "Ben Noordhuis <info@bnoordhuis.nl> (http://bnoordhuis.nl/)"
- , "Tor Valamo <tor.valamo@gmail.com> (http://www.magnimedia.no/)"
- , "Whyme.Lyu <5longluna@gmail.com> (http://whyme.kuantu.com/)"
- , "Olivier Melcher <olivier.melcher@gmail.com>"
- , "Tomaž Muraus <kami@k5-storitve.net> (http://www.tomaz-muraus.info)"
- , "Evan Meagher <evan.meagher@gmail.com> (http://evanmeagher.net/)"
- , "Orlando Vazquez <ovazquez@gmail.com> (http://2wycked.net/)"
- , "George Miroshnykov <gmiroshnykov@lohika.com>"
- , "Geoff Flarity (http://ca.linkedin.com/pub/geoff-flarity/a/536/43a)"
- , "Pete Kruckenberg <pete@kruckenberg.com>"
- , "Chris Wong <chris@chriswongstudio.com>"
- ]
, "repository" :
{ "type" : "git"
, "url" : "git://github.com/isaacs/npm.git"

0 comments on commit 1287c7f

Please sign in to comment.