Installation
composer require codebuds/ts-generator-bundle --dev
Add the bundle to config/bundles.php if not auto-discovered:
CodeBuds\TsGeneratorBundle\CodeBudsTsGeneratorBundle::class => ['dev' => true],
Basic Configuration
Override defaults in config/packages/codebuds_ts_generator.yaml:
codebuds_ts_generator:
namespace: 'App\\Entity\\'
interface_output_directory: '%kernel.project_dir%/assets/ts/interfaces'
type_output_directory: '%kernel.project_dir%/assets/ts/types'
enum_output_directory: '%kernel.project_dir%/assets/ts/enums'
entity_input_directory: '%kernel.project_dir%/src/Entity'
First Use Case Run the generator via CLI:
php bin/console codebuds:ts-generator:generate
Verify output in assets/ts/ (default paths). For a single entity:
php bin/console codebuds:ts-generator:generate --entity=User
Entity-to-TypeScript Pipeline
generate command to process all entities in entity_input_directory.--force flag to regenerate all files or omit to skip unchanged entities.--entity=ClassName or --directory=path/to/Entity.Integration with Build Tools
tsconfig.json to include generated paths:
{
"include": ["assets/ts/**/*"]
}
post-update-cmd in composer.json:
"scripts": {
"post-update-cmd": "php bin/console codebuds:ts-generator:generate --quiet"
}
TypeScript Usage Patterns
interface User extends GeneratedUserInterface { ... } // Extend for custom props
import { UserRole } from './enums/UserRole';
Custom Templates
vendor/codebuds/ts-generator-bundle/templates/ to config/codebuds/ts-generator/templates/ and modifying.Namespace Mismatches
namespace config doesn’t match entity paths.entity_input_directory (e.g., %kernel.project_dir%/src/Entity) and verify the namespace config matches your App\Entity root.Circular Dependencies
User ↔ Role ↔ Permission) may cause infinite loops in type generation.--exclude=EntityName or adjust template logic to handle self-references.File Overwrites
--force sparingly; prefer extending generated types/interfaces in separate files.Doctrine Proxy Classes
__CG__\App\Entity\User) break generation.entity_input_directory or filter them via custom logic in a service extension.--dry-run to preview changes without writing files.-v to CLI commands for detailed scanning logs.debug: true in config to log template rendering:
codebuds_ts_generator:
debug: true
Custom Generators
CodeBuds\TsGeneratorBundle\Generator\GeneratorInterface.Service Overrides
TsGenerator service to modify generation logic:
# config/services.yaml
CodeBuds\TsGeneratorBundle\Generator\TsGenerator:
arguments:
$customTemplatePath: '%kernel.project_dir%/custom/templates'
Event Listeners
codebuds.ts_generator.generate events to hook into the generation process:
// src/EventListener/CustomTsGeneratorListener.php
public function onGenerate(EntityEvent $event) {
$event->getEntity()->addCustomProperty('frontendName', 'user');
}
Configuration Overrides
# config/packages/dev/codebuds_ts_generator.yaml
codebuds_ts_generator:
interface_output_directory: '%kernel.project_dir%/var/ts/interfaces'
entity_input_directory to limit scanning to relevant paths (e.g., exclude tests/ or Migrations/)..gitignore and regenerate only when PHP entities change (e.g., via post-autoload-dump in composer.json).How can I help you explore Laravel packages today?