Mix Tasks Reference
View SourceThis document provides a comprehensive reference for all AshTypescript Mix tasks.
Installation Commands
mix igniter.install ash_typescript
Automated installer that sets up everything you need to get started with AshTypescript.
Usage
# Basic installation (RPC setup only)
mix igniter.install ash_typescript
# Full-stack React + TypeScript setup
mix igniter.install ash_typescript --framework react
What It Does
The installer performs the following tasks:
Dependency Setup
- Adds AshTypescript to your
mix.exsdependencies - Runs
mix deps.getto install the package
- Adds AshTypescript to your
Configuration
- Configures AshTypescript settings in
config/config.exs - Sets default output paths and RPC endpoints
- Configures AshTypescript settings in
RPC Controller
- Creates RPC controller at
lib/*_web/controllers/ash_typescript_rpc_controller.ex - Implements handlers for run and validate endpoints
- Creates RPC controller at
Phoenix Router
- Adds RPC routes to your Phoenix router
- Configures
/rpc/runand/rpc/validateendpoints
React Setup (with
--framework react)- Sets up complete React + TypeScript environment
- Configures esbuild or vite for frontend builds
- Creates welcome page with getting started guide
- Installs necessary npm packages
Options
| Option | Description |
|---|---|
--framework react | Set up React + TypeScript environment |
When to Use
- ✅ New projects starting with AshTypescript
- ✅ Adding AshTypescript to existing Phoenix projects
- ✅ Setting up frontend with React integration
- ❌ Projects that already have AshTypescript installed
This is the recommended approach for initial setup.
Code Generation Commands
mix ash.codegen
Recommended approach for most projects. This command runs code generation for all Ash extensions in your project, including AshTypescript.
# Generate types for all Ash extensions including AshTypescript
mix ash.codegen --dev
For detailed information about mix ash.codegen, see the Ash documentation.
mix ash_typescript.codegen
Generate TypeScript types, RPC clients, Zod schemas, and validation functions only for AshTypescript.
Usage
# Basic generation (AshTypescript only)
mix ash_typescript.codegen
# Custom output location
mix ash_typescript.codegen --output "frontend/src/api/ash.ts"
# Custom RPC endpoints
mix ash_typescript.codegen \
--run_endpoint "/api/rpc/run" \
--validate_endpoint "/api/rpc/validate"
# Check if generated code is up to date (CI usage)
mix ash_typescript.codegen --check
# Preview generated code without writing to file
mix ash_typescript.codegen --dry_run
Options
| Option | Type | Default | Description |
|---|---|---|---|
--output FILE | string | assets/js/ash_rpc.ts | Output file path for generated TypeScript |
--run_endpoint PATH | string | /rpc/run | RPC run endpoint path |
--validate_endpoint PATH | string | /rpc/validate | RPC validate endpoint path |
--check | boolean | false | Check if generated code is up to date (exit 1 if not) |
--dry_run | boolean | false | Print generated code to stdout without writing file |
Generated Content
When run, this task generates:
TypeScript Interfaces
- Resource types with field metadata
- Schema types for field selection
- Result types for each action
RPC Client Functions
- HTTP-based RPC functions for each action
- Channel-based RPC functions (if enabled)
- Type-safe configuration objects
Filter Input Types
- Comprehensive filter operators
- Type-safe query building
- Nested relationship filtering
Zod Validation Schemas (if enabled)
- Runtime type validation
- Schema for each resource
- Nested validation support
Form Validation Functions
- Client-side validation helpers
- Error message handling
- Field-level validation
Typed Query Constants
- Pre-configured field selections
- SSR-optimized types
- Type-safe result extraction
Custom Type Imports
- Imports for custom types
- Integration with external types
- Type mapping support
Examples
Basic Generation:
mix ash_typescript.codegen
Custom Output Location:
mix ash_typescript.codegen --output "frontend/src/api/ash.ts"
Custom RPC Endpoints:
mix ash_typescript.codegen \
--run_endpoint "/api/rpc/run" \
--validate_endpoint "/api/rpc/validate"
CI Check:
# In CI pipeline - fails if generated code is out of date
mix ash_typescript.codegen --check
Preview Without Writing:
# See what would be generated
mix ash_typescript.codegen --dry_run | less
When to Use
- ✅ Want to run codegen specifically for AshTypescript
- ✅ Need custom output paths or endpoints
- ✅ Debugging generated TypeScript code
- ✅ CI/CD pipelines with
--checkflag - ❌ Have other Ash extensions that need codegen (use
mix ash.codegen)
Test Environment Code Generation
For projects using test-only resources (common in library development), use the test environment:
# Generate types in test environment
MIX_ENV=test mix ash_typescript.codegen
# Or use the test.codegen alias (if defined)
mix test.codegen
Setting Up Test Codegen Alias
Add to your mix.exs:
defp aliases do
[
"test.codegen": ["cmd MIX_ENV=test mix ash_typescript.codegen"],
# ... other aliases
]
endWorkflow Integration
Development Workflow
# 1. Make changes to resources or domain configuration
vim lib/my_app/resources/todo.ex
# 2. Generate TypeScript types
mix ash.codegen --dev
# 3. Verify TypeScript compilation (in frontend directory)
cd assets && npm run typecheck
# 4. Run tests
mix test
CI/CD Workflow
# In your CI pipeline (.github/workflows/ci.yml, etc.)
# Check generated code is up to date
mix ash_typescript.codegen --check
# If out of date, CI fails with:
# "Generated TypeScript code is out of date. Run: mix ash_typescript.codegen"
Example GitHub Actions:
- name: Check TypeScript codegen
run: mix ash_typescript.codegen --check
- name: Type check generated code
run: |
cd assets
npm run typecheckPre-commit Hook
Add to .git/hooks/pre-commit:
#!/bin/bash
# Regenerate TypeScript on commit
mix ash_typescript.codegen --check || {
echo "TypeScript code out of date. Regenerating..."
mix ash_typescript.codegen
git add assets/js/ash_rpc.ts
}
Troubleshooting
Common Issues
"No domains found"
Problem: Command runs but generates empty output or reports no domains.
Solution: Ensure you're in the correct MIX_ENV:
# Wrong - uses dev environment
mix ash_typescript.codegen
# Correct - uses test environment for test resources
MIX_ENV=test mix ash_typescript.codegen
Generated code doesn't compile
Problem: TypeScript compilation fails after generation.
Solution: Check for:
- Invalid field names (use field name mapping)
- Custom types not defined in imported modules
- Missing type mapping overrides for dependency types
See Configuration Reference for field name mapping and type overrides.
Changes not reflected
Problem: Made changes to resources but generated TypeScript unchanged.
Solution:
- Recompile Elixir code:
mix compile --force - Regenerate TypeScript:
mix ash_typescript.codegen - Verify output file path matches configuration
Permission errors
Problem: Cannot write to output file.
Solution: Check file permissions and directory structure:
# Ensure directory exists
mkdir -p assets/js
# Check permissions
ls -la assets/js
# Fix if needed
chmod 755 assets/js
See Also
- Configuration Reference - Configure code generation
- Getting Started Tutorial - Initial setup guide
- Troubleshooting Reference - Common problems and solutions