diff options
author | isaacs <i@izs.me> | 2011-09-25 21:16:35 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-09-25 21:16:35 +0400 |
commit | a2f6cc7de6721a85d6c3b39df61a4f88d1c9a37e (patch) | |
tree | fc81c4a55b0ce7a691ae3487bdaee5c6e391e9e5 | |
parent | fe576995c40f87544116ca210e7b21e0484b1c57 (diff) |
Include api docs in index
-rw-r--r-- | scripts/index-build.js | 73 |
1 files changed, 54 insertions, 19 deletions
diff --git a/scripts/index-build.js b/scripts/index-build.js index 412711a46..331fa3a48 100644 --- a/scripts/index-build.js +++ b/scripts/index-build.js @@ -1,25 +1,60 @@ #!/usr/bin/env node var fs = require("fs") , path = require("path") - , docdir = path.resolve(__dirname, "..", "doc") + , cli = path.resolve(__dirname, "..", "doc", "cli") + , clidocs = null + , api = path.resolve(__dirname, "..", "doc", "api") + , apidocs = null + , readme = path.resolve(__dirname, "..", "README.md") -console.log( - "npm-index(1) -- Index of all npm documentation\n" + - "==============================================\n") -fs.readdir(docdir, function (er, docs) { +fs.readdir(cli, done("cli")) +fs.readdir(api, done("api")) + +function done (which) { return function (er, docs) { if (er) throw er - ;["../README.md"].concat(docs.filter(function (d) { - return d !== "index.md" - && d.charAt(0) !== "." - && d.match(/\.md$/) - })).forEach(function (d) { - var doc = path.resolve(docdir, d) - , s = fs.lstatSync(doc) - , content = fs.readFileSync(doc, "utf8").split("\n")[0].split("--")[1] - - if (s.isSymbolicLink()) return - - console.log(d.replace(/^.*?([^\/]*)\.md$/, "## npm-$1(1)") + "\n") - console.log(content + "\n") + if (which === "api") apidocs = docs + else clidocs = docs + + if (apidocs && clidocs) next() +}} + +function filter (d) { + return d !== "index.md" + && d.charAt(0) !== "." + && d.match(/\.md$/) +} + +function next () { + console.log( + "npm-index(1) -- Index of all npm documentation\n" + + "==============================================\n") + + apidocs = apidocs.filter(filter).map(function (d) { + return [3, path.resolve(api, d)] }) -}) + + clidocs = [[1, readme]].concat(clidocs.filter(filter).map(function (d) { + return [1, path.resolve(cli, d)] + })) + + console.log("# Command Line Documentation") + + clidocs.forEach(writeLine) + + console.log("# API Documentation") + apidocs.forEach(writeLine) +} + +function writeLine (sd) { + var sxn = sd[0] + , doc = sd[1] + , d = path.basename(doc, ".md") + , s = fs.lstatSync(doc) + + if (s.isSymbolicLink()) return + + var content = fs.readFileSync(doc, "utf8").split("\n")[0].split("--")[1] + + console.log("## npm-%s(%d)\n", d, sxn) + console.log(content + "\n") +} |