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

OptionDescription
-t, --typesGenerate TypeScript types
-e, --entriesGenerate library entry points
-w, --web-typesGenerate web-types.json for IDEs
-c, --custom-dataGenerate VS Code custom data
-i, --ide-helpersGenerate IDE helpers
--component-metaGenerate component metadata
-p, --pantryGenerate pantry configuration
-m, --model-filesGenerate model files
-o, --openapiGenerate OpenAPI specification
--core-symlinkGenerate core framework symlink
-p, --project [project]Target a specific project
--verboseEnable 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

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

GeneratorOutput File(s)
types*.d.ts files
web-typesweb-types.json
custom-datacustom-elements.json
ide-helpers.ide-helpers/
component-metacomponent-meta.json
openapiopenapi.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:

  1. Check for syntax errors in source files
  2. Run with --verbose for details
  3. Ensure all dependencies are installed

IDE Not Recognizing Types

After generating types:

  1. Restart your IDE
  2. Ensure tsconfig.json includes generated types
  3. 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