use doxygen to document javascript

There are two mostly used ways to document javascript. One is mentioned in official doxygen help, which uses a perl script to parse javascript code and generate code that doxygen can process. The other is JsDoc, which use rhino to parse javascript code and generate document.
The perl script is not so flexible, and JsDoc can not provide as much commands as doxygen. So I prefer another method that uses pseudo code in java syntax to document javascript.

1. Use a script to get all pseudo code from .js files and generate .java files with the same name, the script is attached bellow named builddoc. This script actually get all lines begin with ‘///’, ‘/**’, ‘/* ‘, ‘ * ‘, ‘ */’ and ‘//*’ into the .java file.

So a javascript file like

//* package ns;
/**
 * Foo.
 * @param foo foo.
 */
var foo=function(foo){}
//* public void foo(String foo);

will be converted into

package ns;
/**
 * Foo.
 * @param foo foo.
 */
public void foo(String foo);

And now doxygen can process it in java way.

You should use FILE_PATTERNS = *.java in your doxygen configuration to tell doxygen to parse all .java files.


builddoc:

#!/bin/bash

DIRs="./"

if [ $# -ne 0 ]
then
    DIRs=$@
fi

for DIR in $DIRs; do

    JSs=`find $DIR -name "*.js"`

    for JS in $JSs; do
        DOC=`echo $JS|sed 's/\(.*\)\.js/\1.java/g'`;
        if [ $JS -nt $DOC ]; then
            echo "rebuild $DOC"
            grep -e '^\s*\(///\|//\*\|/\*\*\| \* \| \*/\)' $JS | sed 's/^\s*\/\/\*\(.*\)$/\1/g'> $DOC
        fi
    done

done