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
  • #1 written by Spudnik
    about 1 year ago

    Please could you put a link to the script that you use to change the JS file?

    Thanks

  • #2 written by Blog, earn and reach a wider audience
    about 2 weeks ago

    Thank you for this post, I’ve started using this method to document the javascript portions of our site rewrite.

    Really helpful – this + Doxygen = great documentation for a modern site!

No trackbacks yet.