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
Fix #247: Implements blueprint:build --only and --skip #276
Fix #247: Implements blueprint:build --only and --skip #276
Conversation
Seems like a nice addition 🚀 However, I am not sure adding the same
public function type(); In each of the generators e.g. public function type()
{
return 'tests';
} Then the I maintain a addon that swaps out the Both yours and this implementation will allow present and future addons could use their own types which is cool 😎. One other issue specifically for the |
Thank you @dmason30, this was exactly the kind of feedback I was looking for. I'll take a stab at it probably somewhere this week, and also do the testing. I have never tested command line utilities before, so I'm still looking at the best way to go about this. Do you have any pointers for me in that regard? Perhaps @jasonmccreary could also chip in on what would be the right way to go about this? Thanks all! |
@dmason30 I took your suggestion and applied it. The That is indeed a much nicer, and more DRY approach, than having that I have also added, as per your suggestion, the The only thing missing is the tests. As mentioned earlier, I am not sure how to approach this in the test code. I'm looking at If anyone can make a suggestion, that would be great. |
When testing by hand on a blank project, using the Upon inspection, it seems that all Also, found in // TODO: mark skipped... So, I think there once was a thought to have a generator marking 'skipped', for instance by setting If that is the case, I think the Generators themselves should determine whether or not they 'shouldGenerate', so that we can set the Or, we could simply add a new issue to that effect? |
@axit-joost, I think certain resources make sense to skip, not overwrite. For example, form requests, views, jobs, mailables, etc. Most of Blueprint uses references and assumptions based on convention. So if one of those references/resources already exists, it should not overwrite it with a default version. As such, I do consider this different from what you're proposing. Furthermore, having every generator be responsible for knowing if it should be skipped or generated seems like a harder approach than Blueprint knowing not to run a generator. To make it easier, I wouldn't expect you to be able to skip low-level components. My expectation is you could skip things like controllers, models, views, tests, factories, etc. But not mailables, jobs, etc. The latter would lead to Blueprint generating incomplete/invalid code anyway. |
@jasonmccreary thanks for your feedback. Gathering from your response, I compiled this list:
To verify: The Generators that have The downside, in my opinion, is that you will have a However, for a best of both worlds, we could alternatively change the output of the If you then would (Sorry for being this lengthy again, I just want to be thorough) |
I don't really know what you mean about All I will say is I always look for the minimal change. So while I appreciate the contribution, I will not merge something that overly complicates the generators or changes the current output. I see these options as disabling generation of certain resources. We can trust a developer who specifies these options knows the code which is or is not generated. |
I think this is done. I believe this hits the sweet spot of:
The only thing is that my local php-cs-fixer may have done something to the preferred whitespace (e.g. concat spacing, et al.). So you might want to hit 'ignore whitespace' when reviewing the code. If you want me to fix this, or any other issues, please let me know. |
Cool. Merged. I'll let it marinate on |
it's a nice feature. would be great if you can extend the documentation and the information on the command help text by the list of types one can use. If you aren't used to the internal types of blueprint - like me - you'r lost and need to dig into git to find it. |
@jasonmccreary This is nice feature to be used, but its not there in documentation. Updating those will be useful. Thanks in advance |
Closes #247
This is an implementation of the
--only
and--skip
command line options for theblueprint:build
command.Both commands take a comma separated list of 'file classes' (for the lack of a better word), those being:
The command passes the string values to
Blueprint\Builder::execute()
as additional, optional parameters$only
and$skip
. The action body will convert these strings to arrays, and passes those arrays to$blueprint->generate()
alongside of the$registry
. This action iterates over the registered$this->generators
and for each one calloutput()
, again passing the$tree
,$only
and$skip
.Each registered generator implements
Blueprint\Contracts\Generator
. The contract is updated to includearray $only, array $skip
in theoutput()
signature, which demands all of the generators adhere to this.Inside the
output()
action of each generator, I have wrapped the output generation inside anif
statement that references a$this->shouldGenerate()
method, passing the$only
and$skip
to that method, which returns a boolean value whether it should generate or not.Currently, the
shouldGenerate()
utilizesin_array()
calls, using a hardcoded string to identify the 'file class'. Perhaps this should be extracted to a protected instance variable, but I am unsure what to call it.With regards to the test suite: of course this blew up everything, as everything Mocked needed to be modified. In this Work in Progress I've managed to get the test suite to green again, but I still need to implement test cases to verify the proper workings of both command line options.
Now, before I do that, I thought it might be wise to put it under early review before continuing.
I am looking forward to all your feedback, so that I can modify/proceed accordingly.