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

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2010-05-10 23:39:40 +0400
committerisaacs <i@izs.me>2010-05-10 23:39:40 +0400
commit528898be33e37b87c5295d802440873eda171fa3 (patch)
tree7574d118878c8c09b59d5c3938f3dda05241faeb /scripts
parent895281c4edd10541fd3a1abb25e8fb742974bb86 (diff)
Move install-docs.js into the scripts folder so that it's not so confusing.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/install-docs.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/scripts/install-docs.js b/scripts/install-docs.js
new file mode 100644
index 000000000..869f6c558
--- /dev/null
+++ b/scripts/install-docs.js
@@ -0,0 +1,63 @@
+
+// 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
+ , exec = require("./lib/utils/exec")
+ , log = require("./lib/utils/log")
+ , fs = require("fs")
+ , path = require("path")
+ , rm = require("./lib/utils/rm-rf")
+ , mkdir = require("./lib/utils/mkdir-p")
+ , manTarget = path.join(process.installPrefix, "share/man/man1")
+ , exec = require("./lib/utils/exec")
+
+log(event, "docs")
+
+exec("man", ["-w"], function (er, code, stdout, stderr) {
+ if (er) throw er
+ var manpath = stdout.trim().split(":")
+ if (manpath.indexOf(path.dirname(manTarget)) === -1) {
+ log("It seems " + manTarget + " is not visible to man", "!")
+ log("For greater justice, please add it to your man path", "!")
+ log("See: man man", "!")
+ }
+ mkdir(manTarget, function (er) {
+ if (er) throw er
+ installDocs()
+ })
+})
+function installDocs () {
+ fs.readdir(path.join(process.cwd(), "man"), function (er, docs) {
+ log(path.join(process.cwd(), "man"), "docs")
+ log(manTarget, "docs")
+ if (er) return
+ ;(function R (doc) {
+ if (!doc) return log("done", "docs")
+ if (doc === "." || doc === "..") return R(docs.pop())
+ var target = path.join(manTarget, "npm-"+doc)
+ target = target.replace(/npm-npm\.1$/, "npm.1")
+ 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())
+ })
+}