Download the PHP package codebuds/generate-ts-bundle without Composer
On this page you can find all versions of the php package codebuds/generate-ts-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codebuds/generate-ts-bundle
More information about codebuds/generate-ts-bundle
Files in codebuds/generate-ts-bundle
Package generate-ts-bundle
Short Description Generate typescript code from the php files
License MIT
Informations about the package generate-ts-bundle
CodeBuds TypeScript Generator Bundle
The CodeBuds TypeScript Generator Bundle is a Symfony bundle designed to improve developer experience by automatically generating TypeScript files based on PHP files. This bundle scans your PHP entities and creates corresponding TypeScript interfaces and types. It can also scan the PHP Enums to generate the equivalent TypeScript Enums.
Table of Contents
- Installation
- Configuration
- Usage
- Types and Interfaces
- Enums
- Contributing
- License
Installation
To install the bundle, use composer:
Configuration
This bundle provides three configurable parameters with default values:
- namespace: The PHP namespace for your entities. Default value is 'App\Entity\'.
- interface_output_directory: The directory where the generated TypeScript interface files will be stored. Default value is '%kernel.project_dir%/assets/interfaces'.
- type_output_directory: The directory where the generated TypeScript type files will be stored. Default value is ' %kernel.project_dir%/assets/types'.
- enum_output_directory: The directory where the generated TypeScript enum files will be stored. Default value is ' %kernel.project_dir%/assets/enums'.
- entity_input_directory: The directory containing the PHP files that will be used for TypeScript generation. Default value is '%kernel.project_dir%/src/Entity'.
- enum_input_directory: The directory containing the PHP enums that will be used for TypeScript enum generation. Default value is '%kernel.project_dir%/src/Enum'.
You can overwrite these default configurations by creating a YAML file inside your config directory:
Usage
Types and Interfaces
To generate TypeScript interfaces, run the following command:
To generate TypeScript types, run the following command:
Here is the output when the command generates new interfaces:
If nothing changes in the output you will get
Options
You can overwrite the configured values for the namespace, inputDirectory and outputDirectory when running the commande :
Output
The script will try to match the types. If you have an entity that has relations it will map those to the TypeScript Interfaces.
With an Entity like :
The interface output will be :
The type output will be :
Enums
To generate TypeScript enums, run the following command:
This works for simple enums :
Turns into
And for backed enums :
Turns into :
TODO
- union types
Contributing
If you want to contribute to this project, feel free to open issues and submit pull requests.
License
This bundle is open-source software licensed under the MIT license.