JsDoc生成你的JavaScript文档

这是一个Java写的文档生成工具,注释风格要求跟Java的一样即可生成出注释文档,非常好用。直接到官网下载,网上一大堆教程都是JsDoc2版的,现在官网已经说了不再支持JsDoc2版,推荐使用JsDoc3版本。

Github: https://github.com/jsdoc3/jsdoc

下载后不用安装直接就能用,当然还是要先安装配置好JDK环境,不会的自行找资料。以Win平台做例子,下载过来后解压然后启动命令模式进入程序目录下执行jsdoc即可启动程序,可以直接jsdoc --help查看帮助文档,jsdoc3更直接方便的生成注释文档

D:\jsdoc>jsdoc --help
OPTIONS:
        -t, --template <value>          The name of the template to use. Default
: the "default" template
        -c, --configure <value>         The path to the configuration file. Defa
ult: jsdoc __dirname + /conf.json
        -e, --encoding <value>          Assume this encoding when reading all so
urce files. Default: utf8
        -T, --test              Run all tests and quit.
        -d, --destination <value>               The path to the output folder. U
se "console" to dump data to the console. Default: ./out/
        -p, --private           Display symbols marked with the @private tag. De
fault: false
        -r, --recurse           Recurse into subdirectories when scanning for so
urce code files.
        -l, --lenient           Continue to generate output if a doclet is incom
plete or contains errors. Default: false
        -h, --help              Print this message and quit.
        -X, --explain           Dump all found doclet internals to console and q
uit.
        -q, --query <value>             A query string to parse and store in env
.opts.query. Example: foo=bar&baz=true
        -u, --tutorials <value>         Directory in which JSDoc should search f
or tutorials.
        -v, --version           Display the version number and quit.
        --verbose               Display verbose output for tests
        --match <value>         Only run tests containing <value>
        --nocolor               Do not use color in console output from tests

选项的功能通过help已经说的很清楚,我们来试试生成一篇注释文档

js

/**
 * @description 求两个数的和<br />
 * 1) 参数将强制转换为Number类型<br />
 * 2) 这是一个全局的公用方法
 * @method add
 * @param {Number} num1 数1
 * @param {Number} num2 数2
 * @return {Number} 数1和数2的和
 * @since 2013-08-04
 * @author lee
 * @example
 * var sum = add(3,5); <br />
 * alert(sum); // 8
 * @static
 */
function add(num1,num2){
  return Number(num1)+Number(num2);
}

生成文档

D:\jsdoc>jsdoc doc1/test.js

doc1/test.js就是你要生成注释文档的js文件,相对于jsdoc命令的目录,当然你也可以写成绝对路径。

执行后会在jsdoc程序目录下生成一个out输出目录,里面就是生成的注释文档,也可以使用-d参数指定注释文档输出目录,生成的文档效果:

full

效果不错,当然你也可以使用更好看的模板!

分享

TITLE: JsDoc生成你的JavaScript文档

LINK: https://www.qttc.net/361-jsdoc.html

NOTE: 原创内容,转载请注明出自琼台博客