From 804564a09ad6bb6455a6dad6831cb8d72884b08f Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Mon, 19 Apr 2021 15:51:28 -0400 Subject: [PATCH] Asset Publish Command (#2731) --- .../src/Console/ConsoleServiceProvider.php | 2 + .../src/Database/Console/MigrateCommand.php | 7 -- .../Console/AssetsPublishCommand.php | 82 +++++++++++++++++++ 3 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 framework/core/src/Foundation/Console/AssetsPublishCommand.php diff --git a/framework/core/src/Console/ConsoleServiceProvider.php b/framework/core/src/Console/ConsoleServiceProvider.php index 7887fde72..1ad0e69b4 100644 --- a/framework/core/src/Console/ConsoleServiceProvider.php +++ b/framework/core/src/Console/ConsoleServiceProvider.php @@ -12,6 +12,7 @@ namespace Flarum\Console; use Flarum\Database\Console\MigrateCommand; use Flarum\Database\Console\ResetCommand; use Flarum\Foundation\AbstractServiceProvider; +use Flarum\Foundation\Console\AssetsPublishCommand; use Flarum\Foundation\Console\CacheClearCommand; use Flarum\Foundation\Console\InfoCommand; use Illuminate\Console\Scheduling\Schedule as LaravelSchedule; @@ -37,6 +38,7 @@ class ConsoleServiceProvider extends AbstractServiceProvider $this->container->singleton('flarum.console.commands', function () { return [ + AssetsPublishCommand::class, CacheClearCommand::class, InfoCommand::class, MigrateCommand::class, diff --git a/framework/core/src/Database/Console/MigrateCommand.php b/framework/core/src/Database/Console/MigrateCommand.php index 18631fac1..309b20f85 100644 --- a/framework/core/src/Database/Console/MigrateCommand.php +++ b/framework/core/src/Database/Console/MigrateCommand.php @@ -88,12 +88,5 @@ class MigrateCommand extends AbstractCommand } $this->container->make(SettingsRepositoryInterface::class)->set('version', Application::VERSION); - - $this->info('Publishing assets...'); - - $this->container->make('files')->copyDirectory( - $this->paths->vendor.'/components/font-awesome/webfonts', - $this->paths->public.'/assets/fonts' - ); } } diff --git a/framework/core/src/Foundation/Console/AssetsPublishCommand.php b/framework/core/src/Foundation/Console/AssetsPublishCommand.php new file mode 100644 index 000000000..917667e65 --- /dev/null +++ b/framework/core/src/Foundation/Console/AssetsPublishCommand.php @@ -0,0 +1,82 @@ +container = $container; + $this->paths = $paths; + + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('assets:publish') + ->setDescription('Publish core and extension assets.'); + } + + /** + * {@inheritdoc} + */ + protected function fire() + { + $this->info('Publishing core assets...'); + + $target = $this->container->make('filesystem')->disk('flarum-assets'); + $local = new Filesystem(); + + $pathPrefix = $this->paths->vendor.'/components/font-awesome/webfonts'; + $assetFiles = $local->allFiles($pathPrefix); + + foreach ($assetFiles as $fullPath) { + $relPath = substr($fullPath, strlen($pathPrefix)); + $target->put("fonts/$relPath", $local->get($fullPath)); + } + + $this->info('Publishing extension assets...'); + + $extensions = $this->container->make(ExtensionManager::class); + $extensions->getMigrator()->setOutput($this->output); + + foreach ($extensions->getEnabledExtensions() as $name => $extension) { + if ($extension->hasAssets()) { + $this->info('Publishing for extension: '.$name); + $extension->copyAssetsTo($target); + } + } + } +}