Skip to main content

🛠️ 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.
npx @anonymous-dev/firetype generate [options]

Options

OptionDescriptionRequiredDefault
--input=<path>Directory containing your schema definitions (output will be written here)Yes-
--mode=<mode>SDK mode: admin, client, or omit for bothNoboth

Examples

# Generate types for both SDKs
npx @anonymous-dev/firetype generate --input=./schemas
# Generate only admin SDK types
npx @anonymous-dev/firetype generate --mode=admin --input=./schemas
# Generate only client SDK types
npx @anonymous-dev/firetype generate --mode=client --input=./src/database
# Organize schemas in subdirectories
npx @anonymous-dev/firetype generate --input=./src/schemas/firestore

Help Command

Display help information for all available commands.
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

schemas/
└── index.ts          # Generated types and API functions
📝 Note: Always regenerate types after modifying your schemas. The generated file includes import statements for the required Firestore SDKs based on your --mode selection.

CLI Usage Patterns

Development Workflow

# 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

# 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

# .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:
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:
DEBUG=firetype npx @anonymous-dev/firetype generate --input=./schemas