Skip to content

@ic-reactor/codegen

@ic-reactor/codegen contains the shared generation pipeline used by @ic-reactor/cli and @ic-reactor/vite-plugin. It is the advanced, programmatic entry point for generating declarations, reactor files, and client boilerplate from Candid definitions.

Terminal window
pnpm add -D @ic-reactor/codegen

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

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",
},
})
  • 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

Generated output can target any of these reactor classes:

  • DisplayReactor
  • Reactor
  • CandidReactor
  • CandidDisplayReactor
  • MetadataDisplayReactor
  • react (default): generates the reactor plus bound React hooks
  • core: generates only the typed reactor exports with no React dependency