js-automatic-documentation
v1.0.13
Published
## Overview
Readme
js-automatic-documentation
Overview
js-automatic-documentation is a tool designed to automatically generate documentation from the Abstract Syntax Tree (AST) of JavaScript and TypeScript projects. By using the TypeScript compiler and the ts-morph library, the tool extracts information about imports, exports, and code structure, producing documentation in HTML and Markdown.
The tool also uses JSDoc comments to fill the generated documentation with descriptions, parameters, and return types. This makes it useful for projects with incomplete or missing documentation, providing more precise way to document projects.
Features
- Extracted information:
- Imports: Named, default, and namespace imports with their dependencies.
- Exports: Functions, classes, constants, and additional information like parameters and return types.
- JSDoc parsing:
- Uses the
doctrinelibrary to parse JSDoc comments and use them in the generated documentation.
- Uses the
- Multiple output formats:
- Supports both HTML and Markdown templates using the
mustachelibrary.
- Supports both HTML and Markdown templates using the
- Static file hosting:
- Serves generated HTML documentation locally with HTTP server using the
servelibrary.
- Serves generated HTML documentation locally with HTTP server using the
- CLI interface:
- Supports CLI options for selecting the format, project initialization, and server hosting.
- Ease of use:
- Available as an
npxpackage.
- Available as an
Installation
You can use this tool with npx:
npx js-automatic-documentation [project-path] --format [html|md]Usage
Generate documentation
Run the tool from your project directory to generate documentation:
npx js-automatic-documentation ./path/to/project --format htmlInitialize TypeScript configuration
To set up a tsconfig.json file for the project, use the --init flag:
npx js-automatic-documentation ./path/to/project --init
Serve documentation locally
Serve the documentation locally by providing the --listen flag with a port number:
npx js-automatic-documentation ./path/to/project --format html --listen 8080
Visit http://localhost:8080 to view the documentation.
CLI options
| Option | Alias | Description |
|-------------|-------|-----------------------------------|
| --format | -f | Output format (html or md). |
| --init | -i | Initialize a tsconfig.json file.|
| --listen | -l | Serve HTML documentation on a port.|
How it works
- AST parsing: The tool uses
ts-morphto analyze the TypeScript AST and extract data about imports, exports, and code structure. - JSDoc integration: The
doctrinelibrary processes JSDoc comments for additional data like descriptions and parameter details. - Template rendering: Documentation is generated using
mustachetemplates in HTML or Markdown format. - Static file hosting: An optional HTTP server hosts the generated HTML documentation.
Dependencies
| Dependency | Purpose |
|---------------|----------------------------------------------|
| ts-morph | Simplification of using TypeScript AST. |
| doctrine | JSDoc parsing and data extraction. |
| mustache | Template rendering for HTML/Markdown. |
| serve | Hosting static HTML files locally. |
| minimist | Parsing CLI flags. |
Run locally
Clone the project and install dependencies:
cd js-documentation
npm install
cd js-documentation/test
npm installGenerate documentation:
npx js-automatic-documentation ./test -l 8000