Skip to content

Instantly share code, notes, and snippets.

@montasim
Created July 6, 2024 14:29
Show Gist options
  • Save montasim/1d7dd19f7df79de290c0b84ca661f53b to your computer and use it in GitHub Desktop.
Save montasim/1d7dd19f7df79de290c0b84ca661f53b to your computer and use it in GitHub Desktop.
This configuration ensures that the documentation for your JavaScript project is comprehensive, maintaining high standards of readability and accessibility for developers.
{
"source": {
"include": ["src"],
"includePattern": ".+\\.js$",
"excludePattern": "(build/|node_modules/|documentation/)"
},
"plugins": ["plugins/markdown"],
"templates": {
"cleverLinks": true,
"monospaceLinks": true,
"default": {
"outputSourceFiles": true
}
},
"opts": {
"recurse": true,
"encoding": "utf8",
"destination": "./src/documentation/code"
},
"markdown": {
"parser": "gfm",
"hardwrap": true
},
"tags": {
"allowUnknownTags": true,
"dictionaries": ["jsdoc", "closure"]
}
}
@montasim
Copy link
Author

montasim commented Jul 6, 2024

File Overview

jsdoc.json is the primary configuration file for JSDoc. It specifies which files to include or exclude, how the output should be formatted and where it should be saved, what extensions or modifications to use via plugins, and other settings to control the documentation generation process.

Configuration Details

source: Defines which files JSDoc should consider for documentation.

include: Specifies the directories JSDoc should include in the documentation process, in this case, the src directory.
includePattern: A regular expression that matches files to be included. Here, it’s set to .+.js$, which includes all JavaScript files.
excludePattern: A regular expression to exclude specific patterns from being documented, such as build/, node_modules/, and documentation/ directories.
plugins: Lists the plugins that extend JSDoc's core functionality.

plugins/markdown: Allows JSDoc to parse markdown in comments, enhancing the ability to include formatted text in the generated documentation.
templates: Configures how the documentation looks and behaves.

cleverLinks and monospaceLinks: These options improve link appearance and usability within the generated documentation.
default:
outputSourceFiles: When set to true, includes the source files in the documentation output.
opts: Options related to the output and operation of JSDoc.

recurse: When true, JSDoc will recursively search through all subdirectories in the included paths for source files.
encoding: Specifies the file encoding, here set to "utf8".
destination: Sets the directory where the generated documentation should be placed, configured here as ./src/documentation/code.
markdown: Settings for how markdown within JSDoc comments should be parsed.

parser: Specifies the markdown parser to use, set to "gfm" (GitHub Flavored Markdown) for compatibility with GitHub's styling.
hardwrap: If true, lines break at the column width set in the markdown editor or viewer, enhancing readability.
tags: Controls how tags within JSDoc comments are handled.

allowUnknownTags: Allows the use of tags that aren't part of standard JSDoc tags, which can be useful for custom documentation needs.
dictionaries: Specifies which tag dictionaries to use, in this case, both "jsdoc" and "closure" for a comprehensive set of recognized tags.

Purpose and Benefits

Configuring JSDoc with a jsdoc.json file provides several advantages:

Automation: Automatically generates detailed documentation for your project, saving time and effort compared to manual documentation.
Consistency: Ensures documentation is consistently formatted and structured.
Customization: Allows for extensive customization of the documentation process to meet specific project needs.
Integration: Easily integrates with build processes and continuous integration pipelines to keep documentation up-to-date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment