@ic-reactor/cli
v0.9.0
Published
CLI tool to generate shadcn-style React hooks for ICP canisters
Maintainers
Readme
@ic-reactor/cli
Command-line code generation for IC Reactor. It uses the shared
@ic-reactor/codegen pipeline to generate declarations and typed reactor entry
files from your .did files, with optional React hook exports.
Install
pnpm add -D @ic-reactor/cliAfter installation, the local executable is ic-reactor.
Quick Start
pnpm exec ic-reactor init
pnpm exec ic-reactor generateIf you prefer one-off usage without installing first:
pnpm dlx @ic-reactor/cli init
pnpm dlx @ic-reactor/cli generateWhat init Creates
- an
ic-reactor.jsonconfig file - an optional
src/clients.tshelper with a sharedClientManager
Example Config
{
"$schema": "./node_modules/@ic-reactor/cli/schema.json",
"outDir": "src/declarations",
"clientManagerPath": "../../clients",
"target": "react",
"canisters": {
"backend": {
"name": "backend",
"didFile": "./backend/backend.did"
}
}
}Commands
init
pnpm exec ic-reactor init [options]
Options:
-y, --yes Skip prompts and use defaults
-o, --out-dir <path> Output directory for generated filesgenerate / g
pnpm exec ic-reactor generate [options]
Options:
-c, --canister <name> Generate only one configured canister
--clean Clean the output directory before generation
--bindgen-only Generate only .did, .did.d.ts, and .js declarationsGenerated Output
For each canister, the CLI generates:
<canister>.didcopy<canister>.did.d.tsTypeScript service types<canister>.jsIDL factory moduleindex.generated.tsmanaged reactor implementation, with optional typed hook exportsindex.tsuser-facing entrypoint
The CLI regenerates index.generated.ts on every run. It creates index.ts
once, then preserves it unless the file is still the default wrapper or an
older generated scaffold that can be migrated automatically.
Set target to choose the generated runtime:
react(default): generates the reactor plus bound React hookscore: generates only the typed reactor exports with no React dependency Use--bindgen-onlywhen you only want the generated declaration files. In that mode, the CLI skipsindex.generated.tsandindex.tsentirely and leaves any existing reactor files untouched.
You can define target globally or per canister in ic-reactor.json.
When To Use The CLI
- non-Vite apps
- CI or explicit build pipelines
- projects that want manual control over when generation runs
Use @ic-reactor/vite-plugin instead when you want watch-mode regeneration
inside a Vite app.
Requirements
- Node.js 18+
- TypeScript 5+
@ic-reactor/reactin the consuming app if you usetarget: "react"@ic-reactor/corein the consuming app if you usetarget: "core"withReactororDisplayReactor@ic-reactor/candidin the consuming app if you usetarget: "core"with a candid reactor class
See Also
- Docs: https://ic-reactor.b3pay.net/v3/packages/cli
@ic-reactor/codegen: ../codegen/README.md@ic-reactor/vite-plugin: ../vite-plugin/README.md
