Permalink
Browse files

Handle docs better so that the installed docs are always in sync with…

… the active program
  • Loading branch information...
1 parent 0d86a97 commit a179be62b8c2c273b7eb78d16dc1df92b2443b44 @isaacs isaacs committed May 3, 2010
Showing with 57 additions and 16 deletions.
  1. +4 −16 Makefile
  2. +48 −0 install-docs.js
  3. +5 −0 package.json
View
@@ -4,28 +4,16 @@ docs = $(shell ls doc/*.md \
|sed 's|doc/|man/|g' \
)
-install: doc_install
- node install-npm.js
-
-doc_install: doc
- cd man && \
- for d in $(shell ls *.1); do \
- cp man/$$d /usr/local/share/man/man1/npm-$$d; \
- done;
-
-clean:
- rm -r man
-
-uninstall: clean
- rm /usr/local/share/man/man1/npm{-*,}.1
- @echo TODO - npm uninstall itself
+install:
+ @node install-npm.js
man:
mkdir man
doc: man $(docs)
+ true
man/%.1: doc/%.md
ronn --roff $< > $@
-.PHONY: install doc clean uninstall doc_install
+.PHONY: install doc clean uninstall
View
@@ -0,0 +1,48 @@
+
+// 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
+
+// var 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")
+return
+
+fs.readdir(path.join(process.cwd(), "man"), function (er, docs) {
+ log(path.join(process.cwd(), "man"), "readdir")
+ if (er) throw er
+ ;(function R (doc) {
+ if (!doc) return
+ switch (event) {
+ case "activate":
+ var target = path.join(process.prefix, "share/man/man1/", doc)
+ rm( target
+ , function () {
+ fs.symlink
+ ( path.join(process.cwd(), "man", doc)
+ , path.join(target)
+ , function (er, ok) {
+ if (er) throw er
+ R(docs.pop())
+ }
+ )
+ }
+ )
+ break
+ case "deactivate":
+ rm( path.join(process.prefix, "share/man/man1/", doc)
+ , function (er) { R(docs.pop()) }
+ )
+ break
+ default: throw new Error("invalid state"); break
+ }
+ })(docs.pop())
+})
View
@@ -16,4 +16,9 @@
, "main" : "./npm"
, "bin" : { "npm" : "./cli.js" }
, "engines" : { "node" : ">=0.1.32" }
+, "scripts" :
+ { "preactivate" : "make doc"
+ , "activate" : "node install-docs.js"
+ , "deactivate" : "node install-docs.js"
+ }
}

0 comments on commit a179be6

Please sign in to comment.