Code Comments and Inline DocumentationLesson 5.5
How to generate documentation from code using automated tools
JSDoc generation, Sphinx setup, TypeDoc, documentation CI pipeline, automated doc deployment, GitHub Pages, ReadTheDocs, doc generation best practices
Automated Documentation Generation
If your code has JSDoc or Python docstrings, you can generate a documentation site automatically. The code comments become the docs — they stay in sync by definition.
TypeDoc for TypeScript/JavaScript
# Install
npm install --save-dev typedoc
# Generate docs
npx typedoc --entryPointStrategy expand src/
# typedoc.json config
{
"entryPoints": ["src/index.ts"],
"out": "docs/api",
"includeVersion": true,
"plugin": ["typedoc-plugin-markdown"]
}Sphinx for Python
# Install
pip install sphinx sphinx-autodoc-typehints
# Initialize
sphinx-quickstart docs/
# Auto-generate from docstrings
sphinx-apidoc -o docs/source src/
cd docs && make htmlGitHub Actions Deployment
- name: Build docs
run: npx typedoc
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/apiThe key discipline: generated docs supplement handwritten docs, never replace them. API reference can be generated. Tutorials, guides, and explanations cannot. Write both.
