Generate Command
The buddy generate command provides code generation capabilities for various project artifacts, from TypeScript types to IDE helpers and component metadata.
Basic Usage
# Interactive generator selection
buddy generate
# Generate specific artifact
buddy generate:types
Command Syntax
buddy generate [options]
buddy generate:<type> [options]
Options
| Option | Description |
|---|---|
-t, --types | Generate TypeScript types |
-e, --entries | Generate library entry points |
-w, --web-types | Generate web-types.json for IDEs |
-c, --custom-data | Generate VS Code custom data |
-i, --ide-helpers | Generate IDE helpers |
--component-meta | Generate component metadata |
-p, --pantry | Generate pantry configuration |
-m, --model-files | Generate model files |
-o, --openapi | Generate OpenAPI specification |
--core-symlink | Generate core framework symlink |
-p, --project [project] | Target a specific project |
--verbose | Enable verbose output |
Available Generators
TypeScript Types
Generate types for components, functions, and views:
buddy generate:types
# or
buddy types:generate
Library Entry Points
Generate entry files for component and function libraries:
buddy generate:entries
Web Types
Generate web-types.json for IDE support (JetBrains, etc.):
buddy generate:web-types
VS Code Custom Data
Generate custom element data for VS Code:
buddy generate:vscode-custom-data
IDE Helpers
Generate IDE helper files for improved developer experience:
buddy generate:ide-helpers
Component Meta
Generate component metadata information:
buddy generate:component-meta
Pantry Config
Generate pantry configuration file:
buddy generate:pantry-config
Model Files
Generate ORM model files:
buddy generate:model-files
OpenAPI Specification
Generate OpenAPI (Swagger) specification:
buddy generate:openapi-spec
# or
buddy generate:openapi
Core Symlink
Generate symlink to core framework (for developers):
buddy generate:core-symlink
Examples
Generate All Types
buddy generate:types
Generate OpenAPI Spec
buddy generate:openapi-spec
Output:
buddy generate:openapi-spec
Generated OpenAPI specification
Completed in 1.23s
Generate Model Files
buddy generate:model-files
This reads your model definitions and generates:
- TypeScript interfaces
- Database migration helpers
- Model instance types
Generate with Verbose Output
buddy generate:types --verbose
IDE Integration
Web Types
After generating web types, JetBrains IDEs provide:
- Component autocompletion
- Prop validation
- Documentation on hover
VS Code Custom Data
After generating custom data, VS Code provides:
- Custom element completion
- Attribute hints
- Documentation
IDE Helpers
Generated helpers provide:
- Path aliases
- Type definitions
- Configuration hints
Auto-Generation
Many generators run automatically during development:
# Starts dev server and runs generators
buddy dev
Auto-triggered generators:
- TypeScript types
- Entry points
- IDE helpers
Generated Files
| Generator | Output File(s) |
|---|---|
| types | *.d.ts files |
| web-types | web-types.json |
| custom-data | custom-elements.json |
| ide-helpers | .ide-helpers/ |
| component-meta | component-meta.json |
| openapi | openapi.json |
Type Generation Details
Component Types
Generates types for your Vue components:
// Generated types
declare module '@stacksjs/components' {
export const Button: DefineComponent<{
variant?: 'primary' | 'secondary'
size?: 'sm' | 'md' | 'lg'
disabled?: boolean
}>
}
Function Types
Generates types for your functions:
// Generated types
declare module '@stacksjs/functions' {
export function formatDate(date: Date, format?: string): string
export function calculateTotal(items: Item[]): number
}
Model File Generation
The model file generator creates:
Instance Types
// Generated from User model
interface UserInstance {
id: number
name: string
email: string
createdAt: Date
updatedAt: Date
}
Query Helpers
// Generated query helpers
const user = await User.find(1)
const users = await User.where('active', true).get()
OpenAPI Generation
Generates a complete OpenAPI 3.0 specification:
{
"openapi": "3.0.0",
"info": {
"title": "My API",
"version": "1.0.0"
},
"paths": {
"/api/users": {
"get": {
"summary": "List all users",
"responses": {
"200": {
"description": "Success"
}
}
}
}
}
}
Troubleshooting
Types Not Generated
Error: No components found
Solution: Ensure components exist in the expected location:
app/
Components/
Button.vue
Modal.vue
Generation Fails
Error: Failed to generate types
Solutions:
- Check for syntax errors in source files
- Run with
--verbosefor details - Ensure all dependencies are installed
IDE Not Recognizing Types
After generating types:
- Restart your IDE
- Ensure
tsconfig.jsonincludes generated types - Check file paths are correct
OpenAPI Missing Routes
Ensure routes are properly annotated:
// Annotate your API routes
/**
* @openapi
* /api/users:
* get:
* summary: List users
*/
Best Practices
Commit Generated Files
Include generated files in version control for:
- Consistent IDE experience across team
- CI/CD compatibility
- Documentation
Regenerate After Changes
After modifying:
- Models:
buddy generate:model-files - Components:
buddy generate:types - API routes:
buddy generate:openapi
Use in CI/CD
# Verify generated files are up to date
- run: buddy generate:types
- run: git diff --exit-code
Related Commands
- buddy make:model - Create new model
- buddy build - Build project
- buddy dev - Development server