View on GitHub

Matt's homepage

Bookmark this to keep an eye on new things I am learning.

JSDoc

Documenting you code with labels

Return Home

Installing

Install with the following command:

npm i jsdoc --save-dev

^ back to top ^

Configuration

In order for JSDoc to scan the required file types, we need a jsdoc config file.

JSDoc config

Create a jsdoc.conf.json file in the root of your project, then populate it with the following:

{
  "source": {
    "include": ["src"],
    "includePattern": ".+\\.(m?js(doc|x)?|cjs|ts)$",
    "excludePattern": "(^|\\/|\\\\)_"
  },
  "plugins": [],
  "opts": {
    "encoding": "utf8",
    "destination": "./docs",
    "recurse": true,
    "verbose": true
  }
}

^ back to top ^

Package script

Edit your package.json file and add the following to the scripts section:

"doc": "cls && node ./node_modules/jsdoc/jsdoc.js -c ./jsdoc.conf.json"

You can now create JSDocs with npm run doc

^ back to top ^

Git ignore

Edit your .gitignore file and add a line to ignore dynamically created doco.

/docs

^ back to top ^

Creating documentation

Create documentation by running the following command:

npm run doc

This will create a /docs folder with html documentation.

^ back to top ^