Template Files
The CLI includes four built-in template files:store.js- JavaScript store without persistencestore.ts- TypeScript store without persistencestore-persist.js- JavaScript store with persistence middlewarestore-persist.ts- TypeScript store with persistence middleware
Template Selection Logic
- JavaScript + No Persist →
store.js - JavaScript + Persist →
store-persist.js - TypeScript + No Persist →
store.ts - TypeScript + Persist →
store-persist.ts
Template Placeholders
The CLI replaces the following placeholders in your template files:__STORE_NAME__
Replaced with: Your store name (e.g., useCounterStore)
Used for:
- The store variable name
- The persistence key (in persist templates)
- The exported function name
__INITIAL_STATE__
Replaced with: Your initial state properties (without outer braces)
Used for: The initial state values in the store
Example:
__INITIAL_STATE_TYPES__
Replaced with: TypeScript type definitions for your initial state
Used for: The TypeScript interface (TypeScript templates only)
Example:
__ACTIONS_TYPES__
Replaced with: TypeScript type definitions for your actions
Used for: The actions interface (TypeScript templates only)
Example:
__ACTIONS__
Replaced with: Action method implementations
Used for: The actual action functions in the store
Example:
The generated action implementations are empty (
({})). You’ll need to add your custom logic after generation.Type Inference
The CLI automatically infers TypeScript types from your initial state values:| JavaScript Type | Generated TypeScript Type |
|---|---|
number | number |
string | string |
boolean | boolean |
null | null |
array | any[] |
object | Nested object type |
Template Structure Examples
Basic TypeScript Template
Persist TypeScript Template
Customizing Templates
The templates are located in thetemplates/ directory of the CLI package. While you can modify them, be aware that:
- Changes will be lost when updating the package
- All placeholders must remain intact for the CLI to work correctly
- Template paths are resolved relative to the CLI’s installation directory