2013-07-09 22:09:02 +02:00
|
|
|
#!/usr/bin/env bash
|
2011-11-21 18:48:45 +01:00
|
|
|
|
|
|
|
if [[ $DEBUG != "" ]]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
set -o errexit
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
if ! [ -x node_modules/.bin/ronn ]; then
|
2012-01-17 00:06:16 +01:00
|
|
|
ps=0
|
2011-11-21 18:48:45 +01:00
|
|
|
if [ -f .building_ronn ]; then
|
2012-01-17 00:06:16 +01:00
|
|
|
pid=$(cat .building_ronn)
|
|
|
|
ps=$(ps -p $pid | grep $pid | wc -l) || true
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f .building_ronn ] && [ $ps != 0 ]; then
|
2011-11-21 18:48:45 +01:00
|
|
|
while [ -f .building_ronn ]; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
else
|
|
|
|
# a race to see which make process will be the one to install ronn
|
|
|
|
echo $$ > .building_ronn
|
|
|
|
sleep 1
|
|
|
|
if [ $(cat .building_ronn) == $$ ]; then
|
2012-01-17 00:06:16 +01:00
|
|
|
make node_modules/.bin/ronn
|
2011-11-21 18:48:45 +01:00
|
|
|
rm .building_ronn
|
|
|
|
else
|
|
|
|
while [ -f .building_ronn ]; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
src=$1
|
|
|
|
dest=$2
|
|
|
|
name=$(basename ${src%.*})
|
|
|
|
date=$(date -u +'%Y-%M-%d %H:%m:%S')
|
|
|
|
version=$(node cli.js -v)
|
|
|
|
|
|
|
|
mkdir -p $(dirname $dest)
|
|
|
|
|
|
|
|
case $dest in
|
2013-07-12 17:55:57 +02:00
|
|
|
*.[1357])
|
2011-11-21 18:48:45 +01:00
|
|
|
./node_modules/.bin/ronn --roff $src \
|
|
|
|
| sed "s|@VERSION@|$version|g" \
|
2013-07-12 17:55:57 +02:00
|
|
|
| perl -pi -e 's/(npm\\-)?([^\(]*)\(1\)/npm help \2/g' \
|
|
|
|
| perl -pi -e 's/(npm\\-)?([^\(]*)\([57]\)/npm help \3 \2/g' \
|
|
|
|
| perl -pi -e 's/(npm\\-)?([^\(]*)\(3\)/npm apihelp \2/g' \
|
2011-11-21 18:48:45 +01:00
|
|
|
| perl -pi -e 's/npm\(1\)/npm help npm/g' \
|
|
|
|
| perl -pi -e 's/npm\(3\)/npm apihelp npm/g' \
|
|
|
|
> $dest
|
|
|
|
exit $?
|
|
|
|
;;
|
|
|
|
*.html)
|
2014-04-16 00:31:36 +02:00
|
|
|
url=${dest/html\//}
|
2011-11-21 18:48:45 +01:00
|
|
|
(cat html/dochead.html && \
|
2014-05-06 03:20:40 +02:00
|
|
|
cat $src | ./node_modules/.bin/marked &&
|
2013-07-12 17:55:57 +02:00
|
|
|
cat html/docfoot.html)\
|
2011-11-21 18:48:45 +01:00
|
|
|
| sed "s|@NAME@|$name|g" \
|
|
|
|
| sed "s|@DATE@|$date|g" \
|
2014-04-16 00:31:36 +02:00
|
|
|
| sed "s|@URL@|$url|g" \
|
2011-11-21 18:48:45 +01:00
|
|
|
| sed "s|@VERSION@|$version|g" \
|
2014-05-06 03:20:40 +02:00
|
|
|
| perl -pi -e 's/<h1([^>]*)>([^\(]*\([0-9]\)) -- (.*?)<\/h1>/<h1>\2<\/h1> <p>\3<\/p>/g' \
|
2011-11-21 18:48:45 +01:00
|
|
|
| perl -pi -e 's/npm-npm/npm/g' \
|
2014-05-01 20:09:00 +02:00
|
|
|
| perl -pi -e 's/([^"-])(npm-)?README(?!\.html)(\(1\))?/\1<a href="..\/..\/doc\/README.html">README<\/a>/g' \
|
2013-07-12 17:55:57 +02:00
|
|
|
| perl -pi -e 's/<title><a href="[^"]+README.html">README<\/a><\/title>/<title>README<\/title>/g' \
|
|
|
|
| perl -pi -e 's/([^"-])([^\(> ]+)(\(1\))/\1<a href="..\/cli\/\2.html">\2\3<\/a>/g' \
|
|
|
|
| perl -pi -e 's/([^"-])([^\(> ]+)(\(3\))/\1<a href="..\/api\/\2.html">\2\3<\/a>/g' \
|
|
|
|
| perl -pi -e 's/([^"-])([^\(> ]+)(\(5\))/\1<a href="..\/files\/\2.html">\2\3<\/a>/g' \
|
|
|
|
| perl -pi -e 's/([^"-])([^\(> ]+)(\(7\))/\1<a href="..\/misc\/\2.html">\2\3<\/a>/g' \
|
|
|
|
| perl -pi -e 's/\([1357]\)<\/a><\/h1>/<\/a><\/h1>/g' \
|
|
|
|
| (if [ $(basename $(dirname $dest)) == "doc" ]; then
|
|
|
|
perl -pi -e 's/ href="\.\.\// href="/g'
|
|
|
|
else
|
|
|
|
cat
|
|
|
|
fi) \
|
2014-03-19 17:25:40 +01:00
|
|
|
> $dest
|
2011-11-21 18:48:45 +01:00
|
|
|
exit $?
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid destination type: $dest" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|