phpro / grumphp

A PHP code-quality tool
MIT License
4.14k stars 430 forks source link

How can I not create configuration file by default in silent mode #837

Closed hussainweb closed 3 years ago

hussainweb commented 3 years ago
Q A
Version 1.1.0
Bug? no
New feature? yes
Question? yes
Documentation? no
Related tickets ...

I am wrapping the functionality of GrumPHP in a separate package which is opinionated for typical Drupal setups. It's working quite well except for a problem during installation.

When requiring that package (or GrumPHP directly), it asks if it should create a configuration file. The default response to that question is yes. In silent mode (--no-interaction), this question isn't asked and configuration is created by default. The problem is that my package provides an opinionated starter configuration which should be used. It gets copied at the end of composer install by another plugin which is why when this plugin's install event runs, there is no configuration file and one is created. At the end of composer install, there are two configuration files: grumphp.yml and grumphp.yml.dist.

Is there any way to avoid this? If not, is it feasible to change the default value for this question to "No" so that the configuration isn't created? I realize that this is a big change so if there is any other way, I'm happy to change my package to handle this.

veewee commented 3 years ago

You can disable the plug-in in the composer file of the project. See https://github.com/phpro/grumphp/blob/master/doc/installation/exotic.md#register-paths-in-your-composer-file

Is this something that could work for you? Another option might be to change the priority in which composer runs the plugins? Not sure how to do that at the moment though.

hussainweb commented 3 years ago

Thank you, @veewee. I'm a little confused. Won't disable-plugin even disable installing the hooks? In my case, I want the hooks and everything. I just want to provide my configuration file over what GrumPHP generates, so that's the only change I need.

To be clear, I understand that changing this default is a big decision and I won't suggest either way. But apart from that, I don't see any way to simply configure it. The only way around this is I somehow generate/copy the file before and I will look into that as well.

veewee commented 3 years ago

Hello @hussainweb,

Yes it will disable the complete plugin, but it allows you to run your own commands at the end of the install like only grumphp git:init and not grumphp configure. Not sure if that is something that is possible in the drupal/core-composer-scaffold plugin?

Changing the order in grumphp itself would result in a grumphp.yml.dist file being prefered over a grumphp.yml, which is not how it should work.

Another solution would be to add another composer setting that disables configuration scheduling: https://github.com/phpro/grumphp/blob/master/src/Composer/GrumPHPPlugin.php#L143

However, these settings need to be set in the project's root composer file, which is probably also not something that easily can be set by your package?

Gonna close this issue for now. Feel free to provide additional information if you don't feel like your question is answered.

hussainweb commented 3 years ago

Thanks, @veewee. That's a good idea. I will explore if I can just use composer's post-install event to run grumphp git:init. In that case, I don't have to worry about the order of execution.