Skip to content

Commit

Permalink
Abstract doc building to a separate script
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Sep 4, 2011
1 parent f2a2b3e commit bf46460
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 41 deletions.
54 changes: 13 additions & 41 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
46 changes: 46 additions & 0 deletions scripts/doc-build.sh
Original file line number Diff line number Diff line change
@@ -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.