设置一个基本的Gulpfile来运行JSDoc

Dan*_*ott 2 javascript jsdoc jsdoc3 gulp

我正在努力理解我当前的gulpfile中缺少什么才能让JSDoc满意.

下面的代码不会导致任何错误,但是查看生成的文档的索引页面,很明显我的文档没有被格式化.

我在这里错过了什么?

首先,这是我想要记录的功能.

/**
 *   Returns the sum of a and b
 *   @param {Number} a
 *   @param {Number} b
 *   @return {Number} Sum of a and b 
 */
var sum = function(a, b){
  return a + b; 
};
Run Code Online (Sandbox Code Playgroud)

接下来,这是我的gulpfile.js

var gulp = require('gulp');
var jsdoc = require('gulp-jsdoc');

gulp.task('js-doc', function(){
  return gulp.src([ 'app.js' ])
  .pipe(jsdoc.parser({}, 'test'))
  .pipe(jsdoc.generator('./docs'));
});
Run Code Online (Sandbox Code Playgroud)

运行后gulp js-doc,它会创建docs /目录并构建文档.但是,访问浏览器中的index.html页面会发现实际上没有生成任何文档.当我看到app.js.htmlJSDoc生成的另一个文件时,我看到了我的代码块,但它上面没有任何内容被解析并变成实际的文档.见下面的截图.

在此输入图像描述

我想我缺少对JSDoc或Gulp的一些基本理解.

Dan*_*ott 5

弄清楚了:

npm install --save jsdoc gulp-shell

然后,在你的gulpfile.js里面粘贴以下要求和任务:

var gulp = require('gulp');
var shell = require('gulp-shell');

gulp.task('js-doc', shell.task(['./node_modules/jsdoc/jsdoc .']));
Run Code Online (Sandbox Code Playgroud)

现在,当您从命令行运行时gulp js-doc,您将生成文档.

  • 快速说明:对我来说,我必须在我的gulp任务中使用`./ node_modules/.bin/jsdoc`而不是`./ node_modules/jsdoc/jsdoc`.我的shell任务最终是这样的:`'./ node_modules/.bin/jsdoc src -r -d docs'` (2认同)