当我在项目中使用JSDoc的“命名空间”和“模块”时,列出的类和命名空间文档从模块HTML页面中消失了。

3

我正在使用JSDoc和Docstrap记录一个与IT技术相关的项目。

当文档组织为JS文件(或模块)时,生成的文档是可以接受的。每个模块列出了两个类。

接下来,我除了“模块”之外,还包括了“命名空间”。但是,现在在html页面中,每个模块列出的类都消失了。

问题: 如何让JSDoc继续在模块html页面内包含类列表。

在包括“命名空间”之前输入的代码

JS文件: "ModuleFile01.js", "ModuleFile02.js"

ModuleFile01.js

最初的回答:

您好,如果要在JSDoc生成的文档中包含类列表,请确保在注释中使用@memberof标记来指定类所属的模块或命名空间。例如:

/**
 * @class
 * @memberof module:MyModule
 */
function MyClass() {
  // ...
}

这将使JSDoc将MyClass列为MyModule模块的一部分,并在生成的文档中显示相应的类列表。

/** 
 * @module Part1/Section01
 * @description Section 01 of Part1
 */

/**
 * Class 1.01
 */
class Part1Class1 {

    /**
     * Constructor
     */
    constructor() {}
}

/**
 * Class 1.02
 */
class Part1Class2 {

    /**
     * Constructor
     */
    constructor() {}
}

ModuleFile02.js

/** 
 * @module Part1/Section02
 * @description Section 02 of Part1
 */

/**
 * Class 1.02
 */
class Part1Class3 {

    /**
     * Constructor
     */
    constructor() {}
}

/**
 * Class 1.02
 */
class Part1Class4 {

    /**
     * Constructor
     */
    constructor() {}

JSDoc配置

最初的回答
{
    "recurseDepth": 10,
    "source": {
        "includePattern": ".+\\.js(doc|x)?$",
        "excludePattern": "(^|\\/|\\\\)_|.+\\.min.js"
    },
    "sourceType": "module",
    "tags": {
        "allowUnknownTags": true,
        "dictionaries": ["jsdoc","closure"]
    },
    "plugins": 
        [   "plugins/markdown"
        ],
    "templates": {
        "outputSourceFiles": true,
        "outputSourcePath": false,
        "cleverLinks": false,
        "monospaceLinks": false,
        "dateFormat": "YYYY-MM-DD HH:MM",
        "systemName": "Test project",
        "footer": "",
        "copyright": "DocStrap Copyright © 2012-2015 The contributors to the JSDoc3 and DocStrap projects.",
        "navType": "vertical",
        "theme": "readable",
        "linenums": true,
        "collapseSymbols": false,
        "inverseNav": true,
        "protocol": "html://",
        "methodHeadingReturns": false
    },
    "markdown": {
        "parser": "gfm",
        "hardwrap": true
    }
}

在包含“命名空间”之前的JSDoc调试输出

最初的回答:无法提供,未提供原始答案。
DEBUG: JSDoc 3.5.5 (Thu, 14 Sep 2017 02:51:54 GMT)
DEBUG: Environment info: {"env":{"conf":{"plugins":["plugins/markdown"],"recurseDepth":10,"source":{"includePattern":".+\\.js(doc|x)?$","excludePattern":"(^|\\/|\\\\)_|.+\\.min.js"},"sourceType":"module","tags":{"allowUnknownTags":true,"dictionaries":["jsdoc","closure"]},"templates":{"monospaceLinks":false,"cleverLinks":false,"outputSourceFiles":true,"outputSourcePath":false,"dateFormat":"YYYY-MM-DD HH:MM","systemName":"Test project","footer":"","copyright":"DocStrap Copyright © 2012-2015 The contributors to the JSDoc3 and DocStrap projects.","navType":"vertical","theme":"readable","linenums":true,"collapseSymbols":false,"inverseNav":true,"protocol":"html://","methodHeadingReturns":false},"markdown":{"parser":"gfm","hardwrap":true}},"opts":{"_":["src"],"configure":"JSDoc.cfg.json","template":"C:/Users/cpass/node_modules/ink-docstrap/template","destination":"doc","recurse":true,"verbose":true,"debug":true,"encoding":"utf8"}}}
DEBUG: Parsing source files: ["D:\\JavaProjects\\JavaScript\\LWPS\\docs\\test01\\src\\ModuleFile01.js","D:\\JavaProjects\\JavaScript\\LWPS\\docs\\test01\\src\\ModuleFile02.js"]
Parsing D:\JavaProjects\JavaScript\LWPS\docs\test01\src\ModuleFile01.js ...
Parsing D:\JavaProjects\JavaScript\LWPS\docs\test01\src\ModuleFile02.js ...
DEBUG: Finished parsing source files.
DEBUG: Indexing doclets...
DEBUG: Adding inherited symbols, mixins, and interface implementations...
DEBUG: Adding borrowed doclets...
DEBUG: Post-processing complete.
Generating output files...
Finished running in 0.48 seconds.

在包含"namespace"之后输入代码

JS文件:"Cat-Classes","ModuleFile01.js","ModuleFile02.js"

Cat-Classes.js(仅有文档,无代码)

(注:Original Answer翻译成“最初的回答”)
/** 
 * @namespace sections
 * @description Section 01 and 02 of Part1
 * The html page for this namespace lists all classes from "Module01.js" and "Module01.js".
 */

ModuleFile01.js

/** 
 * @module Part1/Section01
 * @description Section 01 of Part1
 */

/**
 * Class 1.01
 * @memberof sections
 */
class Part1Class1 {

    /**
     * Constructor
     */
    constructor() {}
}

/**
 * Class 1.02
 * @memberof sections
 */
class Part1Class2 {

    /**
     * Constructor
     */
    constructor() {}
}

ModuleFile02.js

/** 
 * @module Part1/Section02
 * @description Section 02 of Part1
 */

/**
 * Class 1.02
 * @memberof sections
 */
class Part1Class3 {

    /**
     * Constructor
     */
    constructor() {}
}

/**
 * Class 1.02
 * @memberof sections
 */
class Part1Class4 {

    /**
     * Constructor
     */
    constructor() {}
}

包含"namespace":"sections"之后的JSDoc调试输出

最初的回答。
DEBUG: JSDoc 3.5.5 (Thu, 14 Sep 2017 02:51:54 GMT)
DEBUG: Environment info: {"env":{"conf":{"plugins":["plugins/markdown"],"recurseDepth":10,"source":{"includePattern":".+\\.js(doc|x)?$","excludePattern":"(^|\\/|\\\\)_|.+\\.min.js"},"sourceType":"module","tags":{"allowUnknownTags":true,"dictionaries":["jsdoc","closure"]},"templates":{"monospaceLinks":false,"cleverLinks":false,"outputSourceFiles":true,"outputSourcePath":false,"dateFormat":"YYYY-MM-DD HH:MM","systemName":"Test project","footer":"","copyright":"DocStrap Copyright © 2012-2015 The contributors to the JSDoc3 and DocStrap projects.","navType":"vertical","theme":"readable","linenums":true,"collapseSymbols":false,"inverseNav":true,"protocol":"html://","methodHeadingReturns":false},"markdown":{"parser":"gfm","hardwrap":true}},"opts":{"_":["src"],"configure":"JSDoc.cfg.json","template":"C:/Users/cpass/node_modules/ink-docstrap/template","destination":"doc","recurse":true,"verbose":true,"debug":true,"encoding":"utf8"}}}
DEBUG: Parsing source files: ["D:\\JavaProjects\\JavaScript\\LWPS\\docs\\test02\\src\\Cat-Classes.js","D:\\JavaProjects\\JavaScript\\LWPS\\docs\\test02\\src\\ModuleFile01.js","D:\\JavaProjects\\JavaScript\\LWPS\\docs\\test02\\src\\ModuleFile02.js"]
Parsing D:\JavaProjects\JavaScript\LWPS\docs\test02\src\Cat-Classes.js ...
Parsing D:\JavaProjects\JavaScript\LWPS\docs\test02\src\ModuleFile01.js ...
Parsing D:\JavaProjects\JavaScript\LWPS\docs\test02\src\ModuleFile02.js ...
DEBUG: Finished parsing source files.
DEBUG: Indexing doclets...
DEBUG: Adding inherited symbols, mixins, and interface implementations...
DEBUG: Adding borrowed doclets...
DEBUG: Post-processing complete.
Generating output files...
Finished running in 0.51 seconds.


我正在使用JSDoc和Docstrap记录一个与IT技术相关的项目。
该项目包括两个JS文件(或模块),每个JS文件包含两个类。 每个模块页面列出了模块内的类。
我已经成功地创建了一个文档,其中包含了所有类的“命名空间”,这些类来自ModuleFile01.js和ModuleFile02.js文件。
现在,我创建了一个没有代码,只有文档的JS文件。
现在,文档包括一个列出所有项目类的“命名空间”。 但是,在html页面中,每个模块列出的类已经消失了。
问题: 如何让JSDoc继续在模块html页面中包含类列表。
我的环境 | 软件 | 版本 | | :--------------- | :------ | | JSDoc | JSDoc 3.5.5 (Thu, 14 Sep 2017 02:51:54 GMT) | | Node.js | v10.15.0 | | npm | 6.4.1 | | 操作系统 | Windows 10 Pro, 64 bits, Version 1809 (OS Build 17763.503) |
1个回答

0
你可能想要的是将 * @memberof sections 替换为
* @memberof module:Part1/Section01

不要声明* @namespace sections。模块是命名空间的替代方案,需要使用module:...前缀。
在阅读namepath文档中的特殊情况:模块、外部和事件部分之前,我也曾为同样的问题苦苦挣扎。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接