我正在开发一个应用程序,随着时间的推移,它会变得相当庞大。我决定使用JsDoc3
and DocStrap
记录所有模块。模块是通过 require.js 定义的,在某些地方它们的嵌套深度可达 3 或 4 层。
到目前为止,我了解到 JsDoc 文档分为四个主要部分:模块、类、教程、全局。每个部分都有一个标题下拉菜单和一个侧边栏,每个部分都以线性方式按字母顺序列出所有模块。
我想知道是否有选项可以以某种方式显示/分组模块和类以反映项目结构。我看到一个 git 存储库,其中记录了所有带有大量斜杠的类module1/submodule1/class1
,但感觉确实要消化这种类型的导航。更不用说布局在侧边栏溢出长标题时遇到了麻烦。
目前我有一个类似于下面的架构的项目布局。它又宽又深,我希望它能进一步发展。
/Editor
---/Services
------/UI
------...
---...
---editorApp.js
/Engine
---/Core
------/...
---/Entities
------/...
---/Graphics
------/...
---/...
...
engine.js
/Web
---/Services
------/UI
------...
---...
---webApp.js
很好的问题。我也遇到了同样的问题。
I use 命名空间将类组合到一个包中。一个大项目可能有多个命名空间。 Areally大项目可以有命名空间,其成员本身就是命名空间。
命名空间基本上是一组静态对象。您可以使用@namespace
记录不应构造的对象文字或“静态类”,例如本机Math
class.
不幸的是有没有简单的方法将模块标记为命名空间的成员 https://stackoverflow.com/questions/29469819/jsdoc-what-is-a-relationship-between-modules-and-namespaces,所以我放弃了@module
完全标记,仅使用@class
and @namespace
。关于模块的另一个非常烦人的事情是你必须在前面添加module:
在 JSDoc 注释中每次提到模块的前面。例如。你必须做@type {module:my_mod}
而不是仅仅@type {my_mod}
.
所以你的项目的结构将如下所示:
编辑器.js
/**
* description of Editor.
* @namespace Editor
*/
const Editor = {
Services: require('./Services.js'),
...
}
module.exports = Editor
服务.js
/**
* description of Services.
* @namespace Editor.Services
* ^^^^^^^ shows it’s a member of Editor
*/
const Services = {
UI: require('./UI.js'),
...
}
module.exports = Services
UI.js(假设 UI 是一个类)
/**
* description of UI.
* @memberof Editor.Services
* ^^^^^^^^^ need to tell JSDoc UI is a member
* @class
* ^^^^^^ optional, as JSDoc knows ES6 classes
*/
class UI {
constructor() {...}
}
module.exports = UI
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)