Skip to content

Getting Started

Generate Capacitor plugin documentation that includes members inherited through TypeScript
extends. Independently maintained fork of Ionic's
@capacitor/docgen.

Try it in a small sandbox

mkdir docgen-demo
cd docgen-demo
npm init -y
npm install --save-dev @rdlabo/capacitor-docgen@0.4.1

Do not install upstream @capacitor/docgen in the same project; both publish the docgen binary.

Create src/definitions.ts:

export interface SharedOptions {
  requestId?: string;
}

export interface CreateOptions extends SharedOptions {
  value: string;
}

export interface MyPlugin {
  create(options: CreateOptions): Promise<void>;
}

Create tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "strict": true
  },
  "files": ["src/definitions.ts"]
}

Create README.md with the placeholders that docgen updates:

<docgen-index></docgen-index>

<docgen-api></docgen-api>

Run:

npx docgen --project tsconfig.json --api MyPlugin --output-readme README.md --output-json dist/docs.json

The generated CreateOptions documentation includes both value and requestId. Edit the
TypeScript interfaces or JSDoc to change generated content; prose outside the markers stays.
Re-run the same command after edits.

For an existing plugin workflow, you can add a package.json script such as
"docgen": "docgen --api MyPlugin --output-readme README.md". It is optional for this sandbox.

Documentation