Overview
The ReadOnly CLI provides commands to sync files, generate types, and watch for changes in real-time.Commands
sync
Fetch files from ReadOnly and generate TypeScript types (one-time operation).
- Fetches all files from your project using the API key
- Saves files to
node_modules/.cache/readonly/ - Generates TypeScript type definitions in
node_modules/_generated/readonly/
codegen
Regenerate TypeScript types from cached files without fetching from the server.
- Reads cached files from
node_modules/.cache/readonly/ - Regenerates TypeScript type definitions
dev / watch
Watch for file changes and sync automatically (real-time).
- Establishes a WebSocket connection to ReadOnly
- Performs initial sync
- Watches for file changes in real-time
- Automatically syncs and regenerates types when files are updated
help
Display help information.
Environment Variables
All commands require the following environment variables:READONLY_API_KEY (required)
Your project API key (starts with ro_)
READONLY_API_URL (optional)
API URL (defaults to https://api.readonly.store) - only needed for self-hosted instances.
READONLY_CACHE_DIR (optional)
Cache directory name (relative to node_modules/). Defaults to .cache.
READONLY_OUTPUT_DIR (optional)
Output directory name for generated types (relative to node_modules/). Defaults to _generated.
Usage Examples
Basic Sync
Development Mode
Keep this running alongside your dev server:Using .env File
Create a.env file:
.env
Production
Run alongside your application:Error Handling
The CLI includes automatic retry logic with exponential backoff for network errors:- Initial retry delay: 1 second
- Maximum retry delay: 30 seconds
- Backoff strategy: Exponential
Exit Codes
| Code | Description |
|---|---|
0 | Success |
1 | Error occurred |