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: 56827fcc75c42ec13b828146404d62db67feae8d (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
61
62
#!/usr/bin/env node
var fs = require("fs")
  , path = require("path")
  , root = path.resolve(__dirname, "..")
  , glob = require("glob")
  , conversion = { "cli": 1, "api": 3, "files": 5, "misc": 7 }

glob(root + "/{README.md,doc/*/*.md}", function (er, files) {
  if (er)
    throw er
  output(files.map(function (f) {
    var b = path.basename(f)
    if (b === "README.md")
      return [1, b]
    if (b === "index.md")
      return null
    var s = conversion[path.basename(path.dirname(f))]
    return [s, f]
  }).filter(function (f) {
    return f
  }).sort(function (a, b) {
    return (a[0] === b[0])
           ? ( path.basename(a[1]) === "npm.md" ? -1
             : path.basename(b[1]) === "npm.md" ? 1
             : path.basename(a[1]) === "README.md" ? -1
             : path.basename(b[1]) === "README.md" ? 1
             : a[1] > b[1] ? 1 : -1 )
           : a[0] - b[0]
  }))
})

return

function output (files) {
  console.log(
    "npm-index(7) -- Index of all npm documentation\n" +
    "==============================================\n")

  writeLines(files, 1, "Command Line Documentation")
  writeLines(files, 3, "API Documentation")
  writeLines(files, 5, "Files")
  writeLines(files, 7, "Misc")
}

function writeLines (files, sxn, heading) {
  console.log("# %s\n", heading)
  files.filter(function (f) {
    return f[0] === sxn
  }).forEach(writeLine)
}


function writeLine (sd) {
  var sxn = sd[0]
    , doc = sd[1]
    , d = path.basename(doc, ".md")

  var content = fs.readFileSync(doc, "utf8").split("\n")[0].split("-- ")[1]

  console.log("## %s(%d)\n", d, sxn)
  console.log(content + "\n")
}