Composer脚本无法正常工作

I'm working on a Magento project in which I want to copy a file from a module directory to the root directory on composer install.

I thought I could use composer scripts for this but I can't get it to work. I've tried using both the post-autoload-dump and post-install-cmd events. Any suggestions, maybe I can use another event that is fired after composer install is run? Or am I missing something else

My Module Structure

app/code/Holy/Composer/
├── Scripts.php
└── composer.json

composer.json

{
  "name": "holy/module-composer",
  "description": "Copies app/code/vendor/module/file.php to project root",
  "autoload": {
    "psr-4": {
      "Holy\\Composer\\": ""
    }
  },
  "scripts": {
    "post-install-cmd": "Holy\\Composer\\Scripts::postInstall",
    "post-autoload-dump": "Holy\\Composer\\Scripts::postAutoloadDump"
  }
}

Scripts.php

<?php

namespace Holy\Composer;

use Composer\Script\Event;
use Composer\Installer\PackageEvent;

class Scripts
{
    public static function postInstall(Event $event)
    {
        $composer = $event->getComposer();

        $filename = './app/code/Vendor/Module/file.php';

        if (file_exists($filename)) {
            echo "Copying $filename to the root directory.";
            copy($filename, './file.php');

        } else {
            echo "$filename does not exist, cannot copy it to the root directory";
        }
    }

    public static function postAutoloadDump(Event $event)
    {
        $vendorDir = $event->getComposer()->getConfig()->get('vendor-dir');
        require $vendorDir . '/autoload.php';

        $filename = './app/code/Vendor/Module/ampiframe.php';

        if (file_exists($filename)) {
            echo "Copying $filename to the root directory.";
            copy($filename, './file.php');

        } else {
            echo "$filename does not exist, cannot copy it to the root directory";
        }
    }
}

Temrinal Output

$ composer install
Warning: This development build of composer is over 60 days old. It is recommended to update it by running "/usr/local/bin/composer self-update" to get the latest version.
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Package sjparkinson/static-review is abandoned, you should avoid using it. Use phpro/grumphp instead.
Package fabpot/php-cs-fixer is abandoned, you should avoid using it. Use friendsofphp/php-cs-fixer instead.
Generating autoload files

$ ls
CHANGELOG.md         LICENSE_AFL.txt  index.php            pub
CONTRIBUTING.md      app              lib                  setup
COPYING.txt          bin              nginx.conf.sample    var
Gruntfile.js.sample  composer.json    package.json.sample  vendor
ISSUE_TEMPLATE.md    composer.lock    php.ini.sample
LICENSE.txt          dev              phpserver

After runnin

See https://getcomposer.org/doc/articles/scripts.md for the documentation of scripts. The most relevant part is:

Note: Only scripts defined in the root package's composer.json are executed. If a dependency of the root package specifies its own scripts, Composer does not execute those additional scripts.

So, you cannot define any scripts in your module. There is a bug report about that, but the maintainer of composer is not a friend of executing the scripts of dependencies