-
Notifications
You must be signed in to change notification settings - Fork 288
Added path option to Trace command #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added path option to Trace command #488
Conversation
appClasses now loads files to infer its namespace
Added test to validate the path is sent to tracer command
I understand the goal, but this opens the door to a lot of complexity. For example, when generating models, how will Blueprint know where to put them? I'm open to this, but not if it means reworking foundational components and syntax. There's still a lot of value in generating a model, even if you need to move it to another namespace afterward. |
Hi @jasonmccreary, I may not be seeing the whole picture, but I think we don't need to rework anything else other than this. This issue came up because I had the need to create Seeders and Factories for Models outside the app folder. If it happens that devs don't change anything, and run the build in the generated models:
Spatie\Permission\Models\Permission: { name: string, guard_name: string }
Spatie\Permission\Models\Role: { name: string, guard_name: string } Build command will generate this;
If devs want it to be in root they just need to remove the namespace, build command with
I can't see any downsides on this, and beyond that by default everything works the same, I see this as an extra feature, an extra option to the Trace command. Let me know if I'm missing something. |
I guess I'm not understanding the goal as Blueprint should do this already (your |
Hi @jasonmccreary,
This is the point, I don't have a draft file, I want Blueprint Trace command to generate it for me, and it almost does the job. Shortly, I want blueprint to
Take models:
Spatie\Permission\Models\Permission: { name: string, guard_name: string }
Spatie\Permission\Models\Role: { name: string, guard_name: string } And from this draft I can run the build Blueprint build works great with this I hope I made it clear, let me know. |
@promatik, I understand now. However, it still seems like an awkward way to achieve what you want - generate seeders/factories for non-app models. You're effectively tracing a different path. Then copying that section of the I feel like there is an opportunity to create a cleaner path here. Out of curiosity, don't you still create these models within your own application for specific to this package, |
Exactly, that's exactly what I do, but everything is coded. And it works very well, except for what this PR tries to cover.
No, models will be used from its source, it may be on
If you have any idea, please let me know. As I see this, the current behavior is unchanged, Trace command just gets a new extra option. |
@promatik, alright, I see what you're doing now. I still think it's an awkward way to generate seeders/factories for additional models. With that said, there is valuing in tracing additional models to reference in draft files. I will merge this, but have one request first. Please use an options array for |
I did it @jasonmccreary, didn't know about options array, it's indeed much better. php artisan blueprint:trace
Traced 5 models php artisan blueprint:trace --path "vendor\spatie\laravel-permission\src\Models"
Traced 2 models php artisan blueprint:trace --path "app\Models" --path "vendor\spatie\laravel-permission\src\Models"
Traced 7 models |
So I understand it, if I assume the former based on the code, but want to ensure I understand it. Part of me wonders if the default behavior should be additive. |
Yes, if you define one or multiple
In my case it wouldn't hurt to scan both folders. Anyway I see this like a "pro" feature, if you define a Let me know if you want me to change that behavior. |
By the way @jasonmccreary, I replaced |
@promatik thanks. At first I though it should be additive. However, I agree this is a rather "pro" feature. So we'll assume the developer wants full control when using the |
Hi @jasonmccreary.
Until now Trace Command would read files from app path, or if set, it would read files from
config('blueprint.models_namespace')
.This PR adds the possibility to trace models outside
app
, for instance, developers may load files from.\vendor\...
or.\packages\...
, and they may provide multiple paths, comma separated.The
appClasses
function now loads the file content to get its namespace, previously it was using the path of the working folder (for instance,app
orapp\Models
) and the filename, to inferApp\Models\User
.Since now we can load files from other paths, like
vendor\spatie\laravel-permission\src\Models
we can't infer the namespace from that path, hence the file content is loaded to get the correct namespaceSpatie\Permission\Models\Role
.I've also fixed the tests in order to receive the extra path argument, and added a Test to check if the option is received.
I tried to make the PR as short as possible, changing only the necessary lines.
Let me know if I miss something with this approach.