#!/usr/bin/env php files() ->in($dirs) ->name('composer.json') ->depth('< 3'); // Adjust depth as needed $packages = []; // Collect package directories foreach ($finder as $file) { $packages[] = dirname($file->getRealPath()); } foreach ($packages as $packageDir) { foreach ($resources as $resource) { if (!is_string($resource)) { continue; } $resourcePath = realpath($resource); if (!$resourcePath) { continue; // Skip if the resource doesn't exist } $relativePath = str_replace(realpath(__DIR__.'/../') ?: '', '', $resourcePath); $destination = $packageDir.$relativePath; if (is_file($resourcePath)) { // Ensure the destination directory exists $filesystem->mkdir(dirname($destination)); // Copy the file $filesystem->copy($resourcePath, $destination, true); } elseif (is_dir($resourcePath)) { if ($resourcePath === $shared) { // Copy contents of the shared directory into the package directory $filesystem->mirror($shared, $packageDir, null, ['override' => true]); } else { // Copy the entire directory to the destination $filesystem->mirror($resourcePath, $destination, null, ['override' => true]); } } } }