PHPackages                             codebuds/generate-ts-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. codebuds/generate-ts-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

codebuds/generate-ts-bundle
===========================

Generate typescript code from the php files

0.2.0(2y ago)539MITPHPPHP ^8.1

Since Jun 28Pushed 2y ago2 watchersCompare

[ Source](https://github.com/codebuds33/generate-ts-bundle)[ Packagist](https://packagist.org/packages/codebuds/generate-ts-bundle)[ RSS](/packages/codebuds-generate-ts-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (22)Used By (0)

[![Code Coverage Badge](./plugin/.coverage/badge.svg)](./plugin/.coverage/badge.svg)

CodeBuds TypeScript Generator 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
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Types and Interfaces](#types-and-interfaces)
    - [Enums](#enums)
- [Contributing](#contributing)
- [License](#license)

Installation
------------

[](#installation)

To install the bundle, use composer:

```
composer require codebuds/ts-generator-bundle --dev
```

Configuration
-------------

[](#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:

```
#config/generate_ts.yaml
generate_ts:
    namespace: 'App\CustomNamespace\'
    type_output_directory: '%kernel.project_dir%/custom/types'
    interface_output_directory: '%kernel.project_dir%/custom/interfaces'
    enum_output_directory: '%kernel.project_dir%/custom/enums'
    entity_input_directory: '%kernel.project_dir%/custom/Entity'
    enum_input_directory: '%kernel.project_dir%/custom/Enum'
```

Usage
-----

[](#usage)

### Types and Interfaces

[](#types-and-interfaces)

To generate TypeScript interfaces, run the following command:

```
php bin/console codebuds:generate-ts:interfaces --force
```

To generate TypeScript types, run the following command:

```
php bin/console codebuds:generate-ts:types --force
```

Here is the output when the command generates new interfaces:

```
Generate TypeScript Interfaces
==============================

 0/3 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%

 [INFO] /srv/app/assets/interfaces/Sub1/SubSub1/SubSubEntity2.ts generated for /srv/app/src/Entity/Sub1/SubSub1/SubSubEntity2.php

 [INFO] /srv/app/assets/interfaces/Sub2/SubEntity2.ts generated for /srv/app/src/Entity/Sub2/SubEntity2.php

 [INFO] /srv/app/assets/interfaces/Root.ts generated for /srv/app/src/Entity/Root.php

 3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
```

If nothing changes in the output you will get

```
Generate TypeScript Interfaces
==============================

 0/3 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%

 ! [NOTE] No changes for /srv/app/assets/interfaces/Sub1/SubSub1/SubSubEntity2.ts

 ! [NOTE] No changes for /srv/app/assets/interfaces/Sub2/SubEntity2.ts

 ! [NOTE] No changes for /srv/app/assets/interfaces/Root.ts

 3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
```

#### Options

[](#options)

You can overwrite the configured values for the namespace, inputDirectory and outputDirectory when running the commande :

```
codebuds:generate-ts:interfaces --namespace=App/Test/ --inputDirectory=vendor/codebuds/generate-ts-bundle/src/Tests/data --outputDirectory=vendor/codebuds/generate-ts-bundle/src/Tests/output --force
```

Output
------

[](#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 :

```
