mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
71 lines
1.9 KiB
PHP
Executable File
71 lines
1.9 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require __DIR__.'/../vendor/autoload.php';
|
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
use Symfony\Component\Finder\Finder;
|
|
|
|
$filesystem = new Filesystem();
|
|
|
|
// Define the shared resources
|
|
$shared = realpath(__DIR__.'/../.shared');
|
|
|
|
$resources = [
|
|
$shared,
|
|
__DIR__.'/../.github/FUNDING.yml',
|
|
__DIR__.'/../README.md',
|
|
__DIR__.'/../LICENSE',
|
|
];
|
|
|
|
// Directories to search for packages
|
|
$dirs = [__DIR__.'/../src'];
|
|
|
|
// Find all composer.json files within the specified directories
|
|
$finder = new Finder();
|
|
$finder->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]);
|
|
}
|
|
}
|
|
}
|
|
}
|