0

I have a Nodejs project made of several folders. Each folder is intended to be a java-like package of classes.

src
    folderA
        A.js
        ...

    folderB
        B.js
        ...
    ...

Each class A, B, ... is exported as a default export, as in:

/**
* A class
*/
export default class A {
    constructor() {
        ...
    }
    ...
}

However, when I run jsDoc I get some module.exports.html page containing the documentation of all the classes in a single html page, whereas I whould like, of course, a documentation reflecting the structure of my project.

Reading from here it seems that the only way to go is creating my custom template, which is something I wish not to do. It appears to me unlikely that jsDoc does not support the documentation of an ES6 project, since jsDoc supports ES6 classes.

Is the structure of my project somehow wrong? How is it expected to be structured a project made of ES6 classes? Is there a way to reflect the project structure into the documentation by jsDoc? Is there a different tool which I could use instead of jsDoc?

  • Does this answer your question? [Export multiple classes in ES6 modules](https://stackoverflow.com/questions/38340500/export-multiple-classes-in-es6-modules) – Adrian J. Moreno May 02 '23 at 18:48
  • @AdrianJ.Moreno, that post has helped me in finding a way to organize my documentation but I have found it not very clear so that, I have decided to provide a more detailed explanation. However, I could delete my answer if it appears to be a duplicate. – user15883430 May 02 '23 at 20:29
  • Leave the question. If anyone else considers it a duplicate, they'll mark it as so. If it does get closed., it will just link to the other answer, but keep your explanation as-is. If anything, it could provide a better, more recent explanation regarding how you organized your code for better documentation, regardless of whether the core "answer" is a duplicate. – Adrian J. Moreno May 02 '23 at 22:12

1 Answers1

0

As suggested from here I have finally ended by removing the default keyword from each class export, as in:

/**
* A class
*/
export class A {
    constructor() {
        ...
    }
    ...
}

and creating an index.js file for each folder. Supposing the folder to define a package myPackage containing classes A0 and A1, the content of the index.js file becomes

import {A0} from './A0.js';
import {A1} from './A1.js';

/**
 * This package offers the classes:
 *
 * - {@link A0}
 * - {@link A1}
 *
 * Its purpose is ...
 *
 * @module myPackage
*/
export default {
    A0, 
    A1
}

As a result, jsDoc generates a Home Page with:

  • a list of all the packages
  • a flat list of all the classes of all the packages

For each package, the corresponding comment links only the classes belonging to the package itself, so that, the corresponding HTML page acts both as an overview of the package purpose and as an index linking the classes of the package.

Perhaps, such use of an index.js file as overview/index of the folder is obvious, however, no one has answered to my question, so that, I hope that my answer could be useful to someone else.