Permalink
Browse files

Abstract doc building to a separate script

  • Loading branch information...
isaacs committed Sep 4, 2011
1 parent f2a2b3e commit bf4646091ab881b15a45d0f08358c6afd8317f59
Showing with 59 additions and 41 deletions.
  1. +13 −41 Makefile
  2. +46 −0 scripts/doc-build.sh
View
@@ -41,50 +41,18 @@ uninstall: submodules
doc: $(docs) $(htmldocs)
# use `npm install ronn` for this to work.
-man1/%.1: doc/%.md
- @[ -x ./node_modules/.bin/ronn ] || node cli.js install ronn
- @[ -d man1 ] || mkdir -p man1
- ./node_modules/.bin/ronn --roff $< \
- | perl -pi -e 's/npm\\-([^\(]*)\([0-9]\)/npm help \1/g' \
- | perl -pi -e 's/npm\([0-9]\)/npm help npm/g' \
- > $@
-
-man1/%/: doc/%/
- @[ -d $@ ] || mkdir -p $@
+man1/README.1: README.md
+ scripts/doc-build.sh $< $@
+man1/%.1: doc/%.md
+ scripts/doc-build.sh $< $@
html/doc/README.html: README.md html/dochead.html html/docfoot.html
- @[ -x ./node_modules/.bin/ronn ] || node cli.js install ronn
- @[ -d html/doc ] || mkdir -p html/doc
- (cat html/dochead.html && \
- ./node_modules/.bin/ronn -f $< && \
- cat html/docfoot.html )\
- | sed 's|@NAME@|$*|g' \
- | sed 's|@DATE@|$(shell date -u +'%Y-%M-%d %H:%m:%S')|g' \
- | perl -pi -e 's/<h1>npm(-?[^\(]*\([0-9]\)) -- (.*?)<\/h1>/<h1>npm\1<\/h1> <p>\2<\/p>/g' \
- | perl -pi -e 's/npm-?([^\)]+)\(1\)/<a href="\1.html">npm \1<\/a>/g' \
- | perl -pi -e 's/npm\(1\)/<a href="npm.html">npm<\/a>/g' \
- | perl -pi -e 's/README/<a href="README.html">README<\/a>/g' \
- > $@
+ scripts/doc-build.sh $< $@
-# use `npm install ronn` for this to work.
html/doc/%.html: doc/%.md html/dochead.html html/docfoot.html
- @[ -x ./node_modules/.bin/ronn ] || node cli.js install ronn
- @[ -d html/doc ] || mkdir -p html/doc
- (cat html/dochead.html && \
- ./node_modules/.bin/ronn -f $< && \
- cat html/docfoot.html )\
- | sed 's|@NAME@|$*|g' \
- | sed 's|@DATE@|$(shell date -u +'%Y-%M-%d %H:%m:%S')|g' \
- | perl -pi -e 's/<h1>npm(-?[^\(]*\([0-9]\)) -- (.*?)<\/h1>/<h1>npm\1<\/h1> <p>\2<\/p>/g' \
- | perl -pi -e 's/npm-?([^\)]*)\(1\)/<a href="\1.html">npm \1<\/a>/g' \
- | perl -pi -e 's/npm\(1\)/<a href="npm.html">npm<\/a>/g' \
- | perl -pi -e 's/README/<a href="README.html">README<\/a>/g' \
- > $@
-
-
-html/doc/%/: doc/%/ html/doc
- @[ -d $@ ] || mkdir -p $@
+ scripts/doc-build.sh $< $@
+
test: submodules
node cli.js test
@@ -96,6 +64,10 @@ version: link
publish: link
git tag -s -m v$(shell npm -v) v$(shell npm -v) &&\
git push origin master &&\
- npm publish
+ npm publish &&\
+ make doc-publish
+
+doc-publish: doc
+ rsync -vazu --stats --no-implied-dirs --delete html/doc/ npmjs.org:/var/www/npmjs.org/public/doc
-.PHONY: latest install dev link doc clean uninstall test man
+.PHONY: latest install dev link doc clean uninstall test man doc-publish
View
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+if [[ $DEBUG != "" ]]; then
+ set -x
+fi
+set -o errexit
+set -o pipefail
+
+[ -x ./node_modules/.bin/ronn ] || node cli.js install ronn
+
+src=$1
+dest=$2
+name=$(basename ${src%.*})
+date=$(date -u +'%Y-%M-%d %H:%m:%S')
+version=$(npm -v)
+
+mkdir -p $(dirname $dest)
+
+case $dest in
+ *.html)
+ (cat html/dochead.html && \
+ ./node_modules/.bin/ronn -f $src && \
+ cat html/docfoot.html )\
+ | sed "s|@NAME@|$name|g" \
+ | sed "s|@DATE@|$date|g" \
+ | sed "s|@VERSION@|$version|g" \
+ | perl -pi -e 's/<h1>npm(-?[^\(]*\([0-9]\)) -- (.*?)<\/h1>/<h1>npm\1<\/h1> <p>\2<\/p>/g' \
+ | perl -pi -e 's/npm-([^\)]+)\(1\)/<a href="\1.html">npm \1<\/a>/g' \
+ | perl -pi -e 's/npm\(1\)/<a href="npm.html">npm<\/a>/g' \
+ | perl -pi -e 's/README/<a href="README.html">README<\/a>/g' \
+ > $dest
+ exit $?
+ ;;
+ *.1)
+ ./node_modules/.bin/ronn --roff $src \
+ | sed "s|@VERSION@|$version|g" \
+ | perl -pi -e 's/npm\\-([^\(]*)\([0-9]\)/npm help \1/g' \
+ | perl -pi -e 's/npm\([0-9]\)/npm help npm/g' \
+ > $dest
+ exit $?
+ ;;
+ *)
+ echo "Invalid destination type: $dest" >&2
+ exit 1
+ ;;
+esac

0 comments on commit bf46460

Please sign in to comment.