将静态文件添加到 JSDoc

mar*_*s82 5 javascript jsdoc

我需要在 JSDoc 中添加教程的静态资源。我的项目结构是:

PROJECT ROOT 
| 
|
---> Project directory A
---> Project directory B
---> ...
|
---> Tutorials
     |
     |
     |
     -------->IMG
Run Code Online (Sandbox Code Playgroud)

目录tutorials/img 包含我想要包含的静态资源。我的conf文件是:

{
  "tags": {
    "allowUnknownTags": true,
    "dictionaries": [
      "jsdoc",
      "closure"
    ]
  },
  "source": {
    "include": [
      "modules/abstractModel.js",
      "modules/abstractMediator.js",
      "modules/abstractTemplate.js",
      "modules/abstractView.js",
      "modules/modelEvent/modelEvent.js"
    ],
    //"exclude": ["http/httpSession.js", "http/wyPlayWrapper.js", "util/service.js"],
    "includePattern": ".+\\.js(doc)?$",
    "excludePattern": "(^|\\/|\\\\)_"
  },
  "plugins": [],

  "templates": {
    "default": {
      "staticFiles": {
        "include": ["./trunk/tutorials/img/"]
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我用来生成文档的命令行(从 shell 执行到 PROJECT ROOT 目录):

jsdoc -c conf/jsdoc.conf -u 教程/ -d ./docs 。教程/README.md --verbose

但是任何静态文件都会导入到 docs 文件夹中,并且我无法在教程中使用任何图像。任何建议表示赞赏。

mar*_*s82 2

该功能似乎有很多 bug,至少在 JSDoc 3.3.0-dev 版本中(2014 年 6 月 30 日星期一 00:12:06 GMT)是这样。

首先,正确的语法似乎是:

{
  ....

  "templates": {
    "default": {
      "staticFiles": {
        "paths": ["./tutorials/img/"]
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

然后,在文件jsdoc/templates/default/publish.js中,我将 ~525 行从

var sourcePath = fs.toDir(filePath);
Run Code Online (Sandbox Code Playgroud)

var sourcePath = fs.toDir(fileName);
Run Code Online (Sandbox Code Playgroud)

通过这种方式,tutorials/img 中的文件将被复制到 docs outdir 本身中。这不是最好的解决方案(不复制子目录),但对于我的目的来说已经足够了。