# @ic-reactor/codegen

`@ic-reactor/codegen` contains the shared generation pipeline used by
[`@ic-reactor/cli`](https://ic-reactor.b3pay.net/v3/packages/cli) and
[`@ic-reactor/vite-plugin`](https://ic-reactor.b3pay.net/v3/packages/vite-plugin). It is the advanced,
programmatic entry point for generating declarations, reactor files, and client
boilerplate from Candid definitions.
**Note:** Most application teams should use the CLI or the Vite plugin directly. This
  package is mainly useful when you need custom generation workflows or want to
  embed the pipeline in your own tooling.

## Installation

```bash
pnpm add -D @ic-reactor/codegen
```

## Main Entry Point

The primary API is `runCanisterPipeline`, which coordinates parsing, naming,
declaration generation, and reactor file generation.

```typescript
import { runCanisterPipeline } from "@ic-reactor/codegen"

await runCanisterPipeline({
  canisterConfig: {
    name: "backend",
    didFile: "./backend/backend.did",
    mode: "DisplayReactor",
  },
  projectRoot: process.cwd(),
  globalConfig: {
    outDir: "src/declarations",
    clientManagerPath: "../../clients",
    target: "react",
  },
})
```

## What It Exposes

- `runCanisterPipeline` for full end-to-end generation.
- Naming helpers like `toPascalCase`, `getReactorName`, and `getServiceTypeName`.
- Parser helpers like `parseDIDFile` and `extractMethods`.
- Lower-level generators when you need declarations, reactor files, or client files separately.

For each canister, the pipeline writes:

- `index.generated.ts`: managed implementation, always regenerated
- `index.ts`: stable entry wrapper, preserved unless it still matches the
  default wrapper or an older generated scaffold that can be migrated

## Reactor Modes

Generated output can target any of these reactor classes:

- `DisplayReactor`
- `Reactor`
- `CandidReactor`
- `CandidDisplayReactor`
- `MetadataDisplayReactor`

## Runtime Target

- `react` (default): generates the reactor plus bound React hooks
- `core`: generates only the typed reactor exports with no React dependency

## See Also

[@ic-reactor/cli](https://ic-reactor.b3pay.net/v3/packages/cli)
  [@ic-reactor/vite-plugin](https://ic-reactor.b3pay.net/v3/packages/vite-plugin)
  [Codegen in Action](https://ic-reactor.b3pay.net/v3/examples/codegen-in-action)