Using JsDoc3 for large apps, How to group modules into sections/categories/submodules
Asked Answered
S

2

17

I am working on an app which will become quite huge in time. I have decided to use JsDoc3 and DocStrap to document all modules. Modules are defined via require.js and in some places they are nested up to 3 or 4 levels deep.

Until now I understand that JsDoc documentation is split into four main sections: Modules, Classes, Tutorials, Globals. Each section has a header dropdown menu and a sidebar each of them listing all of the modules in linear fashion, alphabetically.

I was wondering if there are options to display/group modules and Classes somehow to reflect the project structure. I saw a git repository that document all the classes with lots of slashes module1/submodule1/class1, but it feels really though to digest this type of navigation. Not to mention that the layout was having trouble with long titles overflowing from the sidebar.

Currently I have a project layout similar to the schema from bellow. It's wide and deep and I expect it to grow further.

/Editor
---/Services
------/UI
------...
---...
---editorApp.js
/Engine
---/Core
------/...
---/Entities
------/...
---/Graphics
------/...
---/...
...
engine.js
/Web
---/Services
------/UI
------...
---...
---webApp.js
Sokotra answered 2/1, 2016 at 22:54 Comment(1)
for anyone looking for more discussion, copy posted on GitHubRheumatism
R
13

Excellent question. I’ve run into the same problem too.

I use namespaces to group classes together into a single package. A big project could have multiple namespaces. A really big project could have namespaces whose members are themselves namespaces.

A namespace is basically a grouping of static objects. You can use @namespace to document an object literal, or a “static class” that shouldn’t be constructed, for example, the native Math class.

Unfortunately there is no easy way to label modules as members of namespaces, so I’ve abandoned the @module tag altogether, using only @class and @namespace. Another really annoying thing about modules is you have to prepend module: in front of every mention of a module in JSDoc comments. E.g. you must do @type {module:my_mod} instead of just @type {my_mod}.

So the structure of your project would look like this:

Editor.js

/**
 * description of Editor.
 * @namespace Editor
 */
 const Editor = {
   Services: require('./Services.js'),
   ...
 }
 module.exports = Editor

Services.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 (let’s say UI is a class)

/**
 * 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
Rheumatism answered 8/10, 2017 at 22:41 Comment(4)
when using @memberOf <namespace>, the documentation of the methods of the class will gets excluded.Vidavidal
It does when using the @inner modifier tagPlural
can you reference types/classes defined in other node modules using namespaces? i've been fighting with it and haven't gotten anywhere yetMalformation
@Malformation Sorry, I don't know what you mean. You might want to try opening a new question if yours is different from the OP's.Rheumatism
N
8

I've just published a new version of better-docs template which supports @category tag. Long story short you can add @category tag to your class/module/whatever and it will be namespaced in the sidebar.

Newmark answered 29/1, 2019 at 11:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.