handoff-docgen is a Node.js + TypeScript package for generating React component documentation with:
- baseline metadata from
react-docgen-typescript - deep recursive type mapping via TypeScript Compiler API
- deterministic JSON output for CI and downstream tooling
npm install handoff-docgenhandoff-docgen --dir ./src/components --out ./dist/docs.generated.json --tsconfig ./tsconfig.jsonOptions:
--dirdirectory to scan for.tsxcomponents--outoutput JSON file path--tsconfigtsconfig used by both docgen and deep mapper--max-depthrecursion depth cap (default7)--path-modeoutput path mode:relative(default) orabsolute--project-rootbase path used forrelativepath mode (defaults to tsconfig directory)--exclude-dirdirectory name to skip during scanning (repeatable)
import { createGenerator, generateDocs } from "handoff-docgen";
// One-off generation
const docs = await generateDocs({
componentDirectory: "./src/components",
tsconfigPath: "./tsconfig.json",
maxDepth: 7,
pathMode: "relative",
excludeDirectories: ["dist", "build"]
});
// Reusable generator instance (great for repeated runs)
const generator = createGenerator({
componentDirectory: "./src/components",
tsconfigPath: "./tsconfig.json",
maxDepth: 7
});
const nextDocs = await generator.generate();
const docsForAnotherDir = await generator.generate({
componentDirectory: "./src/marketing-components"
});handoff-docgen intentionally focuses on generation, not storage. Persist to disk (JSON, DB, API) in your host app/CLI based on your pipeline needs.
Example custom file persistence in host app:
import { mkdir, writeFile } from "node:fs/promises";
import path from "node:path";
import { generateDocs } from "handoff-docgen";
const docs = await generateDocs({
componentDirectory: "./src/components",
tsconfigPath: "./tsconfig.json"
});
const out = path.resolve("./dist/docs.generated.json");
await mkdir(path.dirname(out), { recursive: true });
await writeFile(out, JSON.stringify(docs, null, 2), "utf8");handoff-docgen supports both ESM and CommonJS consumers.
ESM:
import { generateDocs } from "handoff-docgen";CommonJS:
const { generateDocs } = require("handoff-docgen");If your TypeScript project compiles with "module": "commonjs", the CommonJS require form is supported.
Each prop includes:
- docgen baseline (
docgenType,required,defaultValue,description) - deep mapping (
deepType,typeRefs,warnings) - parsed JSDoc annotations (
annotations)
Deep mapper handles:
- interfaces/type aliases
- unions/intersections
- arrays/sets/maps/records
- enums/literals
- cycle detection and depth truncation
npm run build
npm run typecheck
npm run test:consumersgenerateDocs(options)- one-off generation, returnsGeneratedDocscreateGenerator(options)- returns reusable generator withgenerate(overrides?)- CLI
handoff-docgen- generate + write JSON file for shell workflows