AssetLoader: Allow to make copies of assets

This commit is contained in:
Johannes Meyer 2021-05-04 10:18:17 +02:00
parent ffd1e1d5a3
commit d11bbb0f52
1 changed files with 13 additions and 3 deletions

View File

@ -7,8 +7,10 @@ class AssetLoader
'asset/css' => 'vendor/fortawesome/font-awesome/css/fontawesome.css'
];
public static function update()
public static function update(Composer\Script\Event $event)
{
$copy = in_array('copy-assets', $event->getArguments(), true);
if (is_dir('asset')) {
// Check for removed files
$fs = new Composer\Util\Filesystem();
@ -48,11 +50,15 @@ class AssetLoader
if ($asset->isDir()) {
mkdir($relativePath, 0755, true);
} elseif ($asset->isFile()) {
if ($copy) {
copy($asset->getPathname(), $relativePath);
} else {
symlink($asset->getPathname(), $relativePath);
}
}
}
}
}
// Register font-awesome files as assets
foreach (static::$awesomeVendorFiles as $targetPath => $sourcePath) {
@ -79,9 +85,13 @@ class AssetLoader
'/\\'
)]);
if (! file_exists($relativePath) && $awesomeFile->isFile()) {
if ($copy) {
copy($awesomeFile->getPathname(), $relativePath);
} else {
symlink($awesomeFile->getPathname(), $relativePath);
}
}
}
}
}
}