1
I have developed a Webserver Portable and am also creating a Portable console to use Composer.
I have a problem. I need to create a plugin for Composer.
I need that when downloading any package with Composer, it edits the "scripts" of the composer.json of that package, so that it works on the Portable console.
When downloading Laravel, for example:
Original Composer.json:
{
"name": "laravel/laravel",
...
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
...
},
...
}
Composer.json edited by the plugin:
{
"name": "laravel/laravel",
...
"scripts": {
"post-root-package-install": [
"F:/portable_php_path/php.exe -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
...
},
...
}
- Note that a physical path was generated for php.exe, because in the Portable version, it could be in any path.
(My question is about creating the Composer plugin. I have no problem editing the.json composer with PHP)
I read the tutorial to create a plugin on the Composer site, but I got confused. (https://getcomposer.org/doc/articles/plugins.md)
If you have another way to do this, it’s also interesting. I accept other suggestions and ideas.
I thank anyone who can help.
I created a portable server (Portable), which can be run even from a USB stick. I am now developing a Portable console as well. Then nothing will exist in the environment variables. I really need to use a physical path to PHP, either by replacing it in Composer.json automatically when some (all) packages are installed, or otherwise
– GilCarvalhoDev
But to run Poser on the CLI itself it will be necessary to run
set PATH=...
in the CLI interface, which is equivalent to "existing" @Gilsones– Guilherme Nascimento
I’ve already developed the Portable Console, and it works perfectly, with no environment variable. The problem even happens when a Composer.json has a "script" that calls php
– GilCarvalhoDev
And how Composer runs?
– Guilherme Nascimento
Thus: https://jsfiddle.net/gv74vLf4/
– GilCarvalhoDev
I didn’t ask about the script, I asked about how it executes the commands. So how do you call the Composer in the terminal?
– Guilherme Nascimento
No, it’s an HTML form, via post, for now... if everything goes well, I create something more comfortable.
– GilCarvalhoDev
So you do not want to create a "plugin" Composer, what you want is to create something entirely geared to a need your specific.
– Guilherme Nascimento
The need is to add a function to Composer, as soon as you download a package, check your Composer.json and replace it. I’m really confused if it is possible to do it through a plugin, or if by the Jsfiddle code I posted above, it would be possible to add events. I do not want to touch the code of Composer, because I intend to provide this server Portable
– GilCarvalhoDev
@Gilsones then Poser seems to be a little unnecessary, just for autoload makes the need, or maybe nothing is necessary, install everything you have to install on the pen drive and make available so.
– Guilherme Nascimento