Getting Started

Quick start guide for forge-ts

Get up and running with forge-ts in minutes.

Step 1: Install

Install the forge-ts package using your preferred package manager:

npm install -D forge-ts

Or with pnpm:

pnpm add -D forge-ts

Step 2: Configure

Create a forge-ts.config.ts file in your project root:

import { defineConfig } from "@forge-ts/core";

export default defineConfig({
  rootDir: ".",
  outDir: "docs/generated",
  gen: { enabled: true, formats: ["markdown"] },
});

Step 3: Write TSDoc

Add TSDoc comments to your exported functions and types. Good TSDoc includes a summary, @param tags, @returns, @example blocks, and a visibility tag:

/**
 * Adds two numbers together.
 *
 * @param a - The first operand.
 * @param b - The second operand.
 * @returns The sum of a and b.
 * @example
 * ```typescript
 * add(1, 2); // => 3
 * ```
 * @public
 */
export function add(a: number, b: number): number {
  return a + b;
}

Step 4: Generate docs

Run forge-ts check to validate TSDoc coverage, then build your docs:

npx forge-ts check

Then build the documentation site:

npx forge-ts build

Your code examples become live documentation:

import { loadConfig } from "@forge-ts/core";
import { generateApi } from "@forge-ts/api";

const config = await loadConfig();
const result = await generateApi(config);
console.log(result.success); // true if the spec was written successfully

CLI Commands

Quick reference for all forge-ts CLI commands:

CommandDescription
forge-ts checkLint TSDoc coverage and report rule violations
forge-ts buildGenerate documentation from source code
forge-ts docs init --target fumadocsScaffold a documentation site for an SSG target
forge-ts docs devPreview the generated documentation site locally
forge-ts testRun @example blocks as executable doctests

What's Next?

On this page