2022-11-17 12:18:34 +03:00
## Dealing with `civicrm/composer-compile-plugin` prompts
2021-06-02 17:00:32 +03:00
2022-11-17 12:18:34 +03:00
During installation you will see this prompt:
```sh
civicrm/composer-compile-plugin contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "civicrm/composer-compile-plugin" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?]
```
And after almost any Composer operation you will see this prompt:
2021-06-02 17:00:32 +03:00
```sh
The following packages have new compilation tasks:
- retailcrm/api-client-php has 1 task
Allow these packages to compile? ([y]es, [a]lways, [n]o, [l]ist, [h]elp)
```
That's because the API client utilizes code generation to speed up the serialization and deserialization of the requests. However,
2022-11-17 12:18:34 +03:00
these prompts may be annoying and sometimes can even break the application lifecycle pipeline (in the CI/CD environment). We can't just
2021-06-02 17:00:32 +03:00
disable it for everyone [because of security concerns ](https://github.com/composer/composer/issues/1193 ). But you can disable it for your project.
2021-12-13 10:46:08 +03:00
There are three ways of disabling this prompt:
1. During the installation.
2. Automated way.
3. Manual way.
2022-11-17 12:18:34 +03:00
### Disable compilation prompts during the installation
2021-12-13 10:46:08 +03:00
2022-11-17 12:18:34 +03:00
Press `'y'` when you see this message:
```sh
civicrm/composer-compile-plugin contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "civicrm/composer-compile-plugin" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?]
```
2021-06-02 17:00:32 +03:00
2022-11-17 12:18:34 +03:00
And when you see this prompt, press `'a'` :
```sh
The following packages have new compilation tasks:
- retailcrm/api-client-php has 1 task
2021-06-02 17:00:32 +03:00
2022-11-17 12:18:34 +03:00
Allow these packages to compile? ([y]es, [a]lways, [n]o, [l]ist, [h]elp)
```
2021-12-13 10:46:08 +03:00
2022-11-17 12:18:34 +03:00
That's it. Code generation is now enabled.
2021-06-02 17:00:32 +03:00
2022-11-17 12:18:34 +03:00
### I've chosen something else, now API client doesn't work!
2021-06-02 17:00:32 +03:00
2022-11-17 12:18:34 +03:00
That happens. We provide special CLI utility which will automatically configure your `composer.json` to enable code generation.
Just run this command inside your project after API client installation:
2021-06-02 17:00:32 +03:00
```sh
./vendor/bin/retailcrm-client compiler:prompt
```
2022-11-17 12:18:34 +03:00
You should see this message after running the command:
```sh
✓ Done, code generation has been enabled.
```
2021-06-02 17:00:32 +03:00
2022-11-17 12:18:34 +03:00
You may also want to run code generation manually once. It can be achieved by running this command:
2021-06-02 17:00:32 +03:00
```sh
2022-11-17 12:18:34 +03:00
composer compile --all
2021-06-02 17:00:32 +03:00
```
2022-11-17 12:18:34 +03:00
**Note:** `retailcrm-client` should be in your binary directory. By default it is set to `vendor/bin` . You can check `config.bin-dir`
value in your `composer.json` and update paths in the commands above accordingly.
**Note (2):** `compiler:prompt` command has `--revert` flag. You can use it if you want to disable automatic code generation for some reason.
2021-06-02 17:00:32 +03:00
2022-11-17 12:18:34 +03:00
### Disabling compilation prompts manually
2021-06-02 17:00:32 +03:00
2022-11-17 12:18:34 +03:00
It is possible to replicate the same actions manually. First, you will need to enable compiler plugin. Add the plugin
to the `config.allow-plugins` segment of your `composer.json` file:
2021-06-02 17:00:32 +03:00
2022-11-17 12:18:34 +03:00
```json
"allow-plugins": {
"civicrm/composer-compile-plugin": true
}
```
2021-06-02 17:00:32 +03:00
2022-11-17 12:18:34 +03:00
After that add these params into the `extra` segment of your `composer.json` :
2021-06-02 17:00:32 +03:00
```json
"compile-mode": "whitelist",
"compile-whitelist": ["retailcrm/api-client-php"]
```
2022-11-17 12:18:34 +03:00
Your `composer.json` file should look like this:
2021-06-02 17:00:32 +03:00
```json
{
"name": "author/some-project",
"description": "Description of the project.",
"type": "project",
"license": "MIT",
"require": {
"php": ">=7.3.0",
"symfony/http-client": "^5.2",
"nyholm/psr7": "^1.4",
"retailcrm/api-client-php": "~6.0"
},
2022-11-17 12:18:34 +03:00
"config": {
"allow-plugins": {
"civicrm/composer-compile-plugin": true
}
},
2021-06-02 17:00:32 +03:00
"extra": {
"compile-mode": "whitelist",
"compile-whitelist": ["retailcrm/api-client-php"]
}
}
```
Voilà! You won't see the annoying prompt again.