Execute command after composer install

Hi everyone,

I’m trying to generate a file out of a Settings.yaml configuration as soon as my package has been added to the project via composer. What I did so far:

<?php
namespace DIU\Neos\PWA\Composer;

use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\Script\Event;
use Composer\Installer\PackageEvent;
use Neos\Flow\Package\PackageManager;
use Neos\Utility\Files;

/**
 * Class for Composer install scripts
 */
class InstallerScripts
{
    /**
     * Make sure required paths and files are available outside of Package
     * Run on every Composer install or update - must be configured in root manifest
     *
     * @param Event $event
     * @return void
     */
    public static function postInstallCreateFile(Event $event){
       # I need the root path as I want to add the file here, copied from Neos Flow package 
       if (!defined('FLOW_PATH_ROOT')) {
            define('FLOW_PATH_ROOT', Files::getUnixStylePath(getcwd()) . '/');
        }

        echo "hello world";
        // add command to create file from Settings.yaml
    }
} 

and I have added this to my composer.json of my package:

...
    "scripts": {
        "post-install-cmd": [
            "DIU\\Neos\\PWA\\Composer\\InstallerScripts::postInstallCreateFile"
        ],
        "post-update-cmd": [
            "DIU\\Neos\\PWA\\Composer\\InstallerScripts::postInstallCreateFile"
        ]
    }
...

Unfortunately it looks like my command won’t get executed. I always see only
Neos\Flow\Composer\InstallerScripts::postUpdateAndInstall
instead of my command. Can I hook in here somehow? Can I even use the Flow commands when they are executed from composer ?

Thanx a lot!

So composer run-script post-install-cmd gives no output from your package? Or how do you test it?

Yes, this is my output:

ddev:/var/www/html$ composer run-script post-install-cmd
> Neos\Flow\Composer\InstallerScripts::postUpdateAndInstall

I would expect at least:

ddev:/var/www/html$ composer run-script post-install-cmd
> Neos\Flow\Composer\InstallerScripts::postUpdateAndInstall
> DIU\Neos\PWA\InstallerScripts::postInstallCreateFile

and an error message if something isn’t working.

I also deleted all caches and the Packages folder and tried composer update/install with no effect.

The package it self ( command controller, Fusion, …) works like expected.

From reading this

https://getcomposer.org/doc/articles/scripts.md#defining-scripts

It’s written as it’s only the root composer.json file where scripts are taken into account. Did you add them to your own package or the root composer.json file?

1 Like