Font Awesome Pro copy icons from custom kits
Description
I followed the procedure to copy Pro icons, but it seems the copying process doesn't support custom kits (subsets and custom icons) made on FontAwesome's website.
As far as I can tell, the sync process copies icons from node_modules/@fortawesome/fontawesome-* directories, but custom kits are installed in node_modules/@awesome.me/kit-* directory.
Now, as I see copying from Pro is different from copying from Kit, I don't actually know if this is a Feature Request or a Bug, so I left it as is.
Possible implementation
Maybe a new command might be needed, like:
php artisan blade-fontawesome:sync-icons --kit
Now, I don't know if there is a use case where multiple kits are downloaded and if those kits might overlap in icon sets.
This should only require the pro option to optionally have a kit-id passed through to it, so after installing the kit via NPM - boom.
I know this is really just an override but, I haven't put together a PR for it.
I've registered this in my bootstrap/app.php,
<?php
namespace App\Console\Commands\FontAwesome;
use DirectoryIterator;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use OwenVoke\BladeFontAwesome\Actions\CompileSvgsAction;
class SyncBladeIconsCommand extends Command
{
protected $signature = 'blade-fontawesome:sync-icons
{directory? : The root directory containing the npm Font Awesome fonts}
{--free : Use the fontawesome-free npm package}
{--pro= : Use the fontawesome-pro npm package, or specify a specific kit}';
protected $description = 'Synchronise Font Awesome icons from npm';
public function handle(): ?int
{
/** @phpstan-ignore-next-line */
$baseDirectory = (string) ($this->argument('directory') ?? base_path());
$proSourcePath = "{$baseDirectory}/node_modules/@fortawesome/fontawesome-pro/svgs";
if (is_string($kitId = $this->option('pro'))) {
$proSourcePath = "{$baseDirectory}/node_modules/@awesome.me/kit-{$kitId}/icons/svgs";
}
$freeSourcePath = "{$baseDirectory}/node_modules/@fortawesome/fontawesome-free/svgs";
if ($this->option('pro')) {
$fullSourcePath = $proSourcePath;
} elseif ($this->option('free')) {
$fullSourcePath = $freeSourcePath;
} else {
$fullSourcePath = collect([
$proSourcePath,
$freeSourcePath,
])->filter(fn (string $path): bool => is_dir($path))->first() ?? $proSourcePath;
}
if (! is_dir($fullSourcePath)) {
$this->warn("Unable to find Font Awesome SVGs in '{$baseDirectory}'");
return static::FAILURE;
}
$destinationPath = resource_path('icons/blade-fontawesome');
if (! File::copyDirectory($fullSourcePath, $destinationPath)) {
$this->warn("Unable to find Font Awesome SVGs in '{$baseDirectory}'");
return static::FAILURE;
}
$sets = [];
foreach (new DirectoryIterator($destinationPath) as $directory) {
if ($directory->isDot() || ! $directory->isDir()) {
continue;
}
(new CompileSvgsAction($directory->getPathname(), $directory->getPathname()))->execute();
$sets[] = $directory->getBasename();
}
$this->info('Successfully updated Font Awesome SVGs');
$this->line("- From: {$fullSourcePath}");
$this->line("- To: {$destinationPath}");
$this->line("\nSets copied: ".implode(', ', $sets));
return static::SUCCESS;
}
}
I think I'd prefer this as an additional --kit=<id> flag. That way it's more obvious. Feel free to PR this if you'd like to.