7nohe / laravel-typegen

The library lets you generate TypeScript types from your Laravel code
79 stars 5 forks source link

[Feature Request] Support Non-Default Namespace for Model Type Export #28

Closed NaoyaMiyagawa closed 5 months ago

NaoyaMiyagawa commented 5 months ago

Issue

Currently, it gives Failed to generate {Model}. Skipping... error message when running typegen for models with non-default namespace, meaning not App\Models, as shown below:

sail pnpm typegen --model-path "app-modules/post/src/Models" --output "app-modules/post/resources/js/types"

> @ typegen /var/www/html
> laravel-typegen "--model-path" "app-modules/post/src/Models" "--output" "app-modules/post/resources/js/types" "--form-request"

Generating types...
Failed to generate Comment. Skipping...
Failed to generate Post. Skipping...
Types generated successfully!!

This becomes an issue when the repository uses an architecture such as modular monolith. Namespace under module can be like App/{Module}/Models or Custom/{Module}/Models, etc.

Expected Behavior

Types of models under non-default namespace can be exported as models under default.

Remarks

This change should not affect types of models under default namespace.

NaoyaMiyagawa commented 5 months ago

I'll give it a try to make a PR for this!

7nohe commented 5 months ago

That would be great! Thank you for your help.