CLI
The IC Reactor CLI (@ic-reactor/cli) helps you generate React hooks and TypeScript declarations from your Candid files. It’s useful if you’re not using Vite or want more control over the generation process.
Installation
Section titled “Installation”bash pnpm add -D @ic-reactor/cli
bash npm install -D @ic-reactor/cli
bash yarn add -D @ic-reactor/cli
bash bun add -D @ic-reactor/cli
Commands
Section titled “Commands”Initialize the configuration file (ic-reactor.json) in your project root.
npx ic-reactor initOptions:
-y, --yes: Skip prompts and use defaults.-o, --out-dir <path>: Output directory for generated hooks (default:src/declarations).
generate
Section titled “generate”Regenerates hooks and declarations for all configured canisters. Run this whenever your .did files change. It creates an index.ts file in each canister directory with fully typed hooks.
npx ic-reactor generateOptions:
-c, --canister <name>: Generate only for a specific canister.--clean: Clean output directory before generating.
Configuration
Section titled “Configuration”The ic-reactor.json file controls the CLI behavior.
{ "outDir": "src/declarations", "clientManagerPath": "../../clients", "canisters": { "backend": { "didFile": "src/backend/backend.did" } }}Options
Section titled “Options”| Key | Type | Description |
|---|---|---|
outDir | string | Base output directory for generated files (required). |
canisters | Record<string, CanisterConfig> | Map of canister names to configurations (required). |
clientManagerPath | string | Path to a custom ClientManager instance (optional). |
Canister Config
Section titled “Canister Config”| Key | Type | Description |
|---|---|---|
didFile | string | Path to the .did file (required). |
name | string | Canister name. |
outDir | string | Override output directory for this canister. |
clientManagerPath | string | Override client manager path. |
canisterId | string | Optional fixed canister ID. |
Examples
Section titled “Examples”- Codegen in Action: Comparison between CLI and Vite plugin generated code.
- TypeScript Demo: Using the CLI to generate pure TypeScript reactors without React.