> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anonymous.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI Reference

> Complete guide to the Firetype command-line interface

# 🛠️ CLI Reference

Firetype provides a powerful CLI tool for generating type definitions from your schema files.

## Generate Command

Generate TypeScript types from your Firestore schema definitions.

```bash theme={null}
npx @anonymous-dev/firetype generate [options]
```

### Options

| Option           | Description                                                                | Required | Default |
| ---------------- | -------------------------------------------------------------------------- | -------- | ------- |
| `--input=<path>` | Directory containing your schema definitions (output will be written here) | Yes      | -       |
| `--mode=<mode>`  | SDK mode: `admin`, `client`, or omit for both                              | No       | both    |

### Examples

```bash theme={null}
# Generate types for both SDKs
npx @anonymous-dev/firetype generate --input=./schemas
```

```bash theme={null}
# Generate only admin SDK types
npx @anonymous-dev/firetype generate --mode=admin --input=./schemas
```

```bash theme={null}
# Generate only client SDK types
npx @anonymous-dev/firetype generate --mode=client --input=./src/database
```

```bash theme={null}
# Organize schemas in subdirectories
npx @anonymous-dev/firetype generate --input=./src/schemas/firestore
```

## Help Command

Display help information for all available commands.

```bash theme={null}
npx @anonymous-dev/firetype help
```

## Generated Files

The CLI generates an `index.ts` file in your input directory containing:

* **Schema definitions**: Zod schemas compiled from your directory structure
* **Converters**: Type-safe Firestore converters with optional validation
* **API functions**: `createFireTypeAdmin()` and/or `createFireTypeClient()` functions

### File Structure Example

```text theme={null}
schemas/
└── index.ts          # Generated types and API functions
```

<Note>
  📝 **Note**: Always regenerate types after modifying your schemas. The generated file includes
  import statements for the required Firestore SDKs based on your `--mode` selection.
</Note>

## CLI Usage Patterns

### Development Workflow

```bash theme={null}
# Initial setup
mkdir -p schemas/database
npx @anonymous-dev/firetype generate --input=./schemas

# Development loop
# 1. Edit schemas
# 2. Regenerate types
npx @anonymous-dev/firetype generate --input=./schemas

# 3. Use in your code
import { createFireTypeAdmin } from "./schemas" // adjust path as needed
```

### Monorepo Setup

```bash theme={null}
# Shared types package
npx @anonymous-dev/firetype generate \
  --input=./packages/database/schemas

# Application-specific types
npx @anonymous-dev/firetype generate \
  --input=./apps/myapp/schemas
```

### CI/CD Integration

```yaml theme={null}
# .github/workflows/generate-types.yml
name: Generate Types
on:
  push:
    paths:
      - 'schemas/**'
jobs:
  generate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '18'
      - run: npm ci
      - run: npx @anonymous-dev/firetype generate --input=./schemas
      - run: npm run type-check
```

## Troubleshooting CLI Issues

### Common Issues

#### "Cannot find module" errors

**Problem**: TypeScript can't find the generated types.

**Solution**: Make sure you've generated types before importing them:

```bash theme={null}
npx @anonymous-dev/firetype generate --input=./schemas
```

#### Schema validation errors

**Problem**: Your schema files aren't being recognized.

**Solutions**:

* Ensure schema files export a `schema` constant: `export const schema = z.object({...})`
* Check that schema files are named exactly `schema.ts`
* Verify the directory structure matches your Firestore collections

#### CLI not found

**Problem**: `firetype` command not recognized.

**Solutions**:

* Use `npx @anonymous-dev/firetype` instead of `firetype`
* Check that the package is installed: `npm list @anonymous-dev/firetype`
* For local installation, ensure your `PATH` includes node\_modules/.bin

#### Type errors in generated code

**Problem**: TypeScript errors in the generated index.ts file.

**Solutions**:

* Update to the latest version: `npm update @anonymous-dev/firetype`
* Regenerate types after schema changes
* Check that your Zod schemas are valid

### Debug Mode

Enable verbose logging by setting the environment variable:

```bash theme={null}
DEBUG=firetype npx @anonymous-dev/firetype generate --input=./schemas
```
