Skip to content

Code Generation API

API for customizing USL code generation.

Custom Templates

Template Structure

templates/
├── typescript/
│   ├── entity.ts.hbs
│   ├── service.ts.hbs
│   └── policy.ts.hbs
└── rust/
    ├── entity.rs.hbs
    └── service.rs.hbs

Using Custom Templates

usl generate --target=typescript --templates=./templates

Template Variables

Available in Handlebars templates:

{{package.name}}
{{package.version}}
{{entity.name}}
{{entity.fields}}
{{service.actions}}

Hooks

Pre-generation

pre-generate.sh:

#!/bin/bash
echo "Running pre-generation hooks..."

Post-generation

post-generate.sh:

#!/bin/bash
echo "Running post-generation hooks..."
npm run format

Configuration

usl.toml:

[generate.typescript]
output = "./backend"
templates = "./templates"
hooks.pre = "./scripts/pre-generate.sh"
hooks.post = "./scripts/post-generate.sh"

Back to Index