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

index-build.js « scripts - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 331fa3a480911d59cca44ee7b753050e3cea7bc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
var fs = require("fs")
  , path = require("path")
  , cli = path.resolve(__dirname, "..", "doc", "cli")
  , clidocs = null
  , api = path.resolve(__dirname, "..", "doc", "api")
  , apidocs = null
  , readme = path.resolve(__dirname, "..", "README.md")

fs.readdir(cli, done("cli"))
fs.readdir(api, done("api"))

function done (which) { return function (er, docs) {
  if (er) throw er
  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")
}