forked from npm/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-docs.js
46 lines (42 loc) · 1.38 KB
/
install-docs.js
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
// a helper install script to install the documentation along with the program
// this runs whenever npm is activated or deactivated, so that the docs always
// reflect the current command.
var event = process.env.npm_lifecycle_event
, chain = require("./lib/utils/chain")
, exec = require("./lib/utils/exec")
, log = require("./lib/utils/log")
, fs = require("fs")
, path = require("path")
, rm = require("./lib/utils/rm-rf")
log(event, "install docs")
fs.readdir(path.join(process.cwd(), "man"), function (er, docs) {
log(path.join(process.cwd(), "man"), "readdir")
if (er) return
;(function R (doc) {
if (!doc) return
if (doc === "." || doc === "..") return R(docs.pop())
var target = path.join(process.installPrefix, "share/man/man1", "npm-"+doc)
target = target.replace(/npm-npm\.1$/, "npm.1")
log(target, event)
switch (event) {
case "activate":
rm( target
, function () {
fs.symlink
( path.join(process.cwd(), "man", doc)
, target
, function (er, ok) {
if (er) throw er
R(docs.pop())
}
)
}
)
break
case "deactivate":
rm( target, function (er) { R(docs.pop()) })
break
default: throw new Error("invalid state"); break
}
})(docs.pop())
})