read-package-json
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "read-package-json", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)", | ||
@@ -5,0 +5,0 @@ "description": "The thing npm uses to read package.json files with semantics and defaults and validation", |
@@ -195,2 +195,31 @@ // vim: set softtabstop=16 shiftwidth=16: | ||
var defDesc = "Unnamed repository; edit this file " + | ||
"'description' to name the repository." | ||
function gitDescription (file, data, cb) { | ||
if (data.description) return cb(null, data); | ||
var dir = path.dirname(file) | ||
// just cuz it'd be nice if this file mattered... | ||
var gitDesc = path.resolve(dir, '.git/description') | ||
fs.readFile(gitDesc, 'utf8', function (er, desc) { | ||
desc = desc.trim() | ||
if (!er && desc.trim() !== defDesc) | ||
data.description = desc | ||
return cb(null, data) | ||
}) | ||
} | ||
function readmeDescription (file, data) { | ||
var d = data.readme | ||
if (!d) return | ||
d = d.split('\n') | ||
d = d.filter(function (line) { | ||
return /\s+/.test(line) | ||
&& line.trim() !== data.name | ||
&& !line.trim().match(/^#/) | ||
})[0] | ||
d = d.trim() | ||
d = d.replace(/\.$/, '') | ||
if (d) data.description = d | ||
} | ||
function readme (file, data, cb) { | ||
@@ -264,2 +293,5 @@ if (data.readme) return cb(null, data); | ||
if (data.readme) | ||
readmeDescription(file, data) | ||
readJson.cache.set(file, data) | ||
@@ -266,0 +298,0 @@ cb(null, data) |
27022
519