Skip to content

Instantly share code, notes, and snippets.

@thelinuxlich
Created February 8, 2011 18:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thelinuxlich/816977 to your computer and use it in GitHub Desktop.
Save thelinuxlich/816977 to your computer and use it in GitHub Desktop.
This shellscript watches coffee files for changes and compiles them and runs docco after
#!/bin/sh
# use my inotify-tools fork at https://github.com/thelinuxlich/inotify-tools
# use my docco fork if you want to generate php documentation(npm install thelinuxlich-docco)
while output=`inotifywait -r -e create -e close_write -e modify --format '%w %f' --include ".*\.(coffee|php)$" /srv/www/htdocs/php/`; do
DIR=${output%% *}
DOCDIR=${DIR/php\//php\/docs/}
FILE=${output#* }
echo "Detected a change in ${DIR}${FILE} ..." >> /srv/www/htdocs/php/logs/watcher.log
if [[ $FILE == *.coffee* ]]
then
COFFEEDIR="${DIR}${FILE}"
JSDIR="${DIR/coffee/js/}"
mkdir -p $JSDIR
echo "Compiling JS from ${COFFEEDIR} to ${JSDIR}..." >> /srv/www/htdocs/php/logs/watcher.log
coffee -o $JSDIR -c ${COFFEEDIR} 2>> /srv/www/htdocs/php/logs/watcher.log
fi;
DOCCOFILE=${DIR}doc_${FILE}
cp ${DIR}${FILE} ${DOCCOFILE}
echo "Generating documentation of ${DOCCOFILE}..." >> /srv/www/htdocs/php/logs/watcher.log
if [[ `file -i ${DIR}${FILE}` != *utf-8* ]]
then
iconv --from-code=ISO-8859-1 --to-code=UTF-8 ${DIR}${FILE} > $DOCCOFILE
fi
docco ${DOCCOFILE} >> /srv/www/htdocs/php/logs/watcher.log
rm -f $DOCCOFILE
mkdir -p $DOCDIR
mv -f /srv/www/htdocs/php/sh/docs/* $DOCDIR
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment