diff --git a/src/Console/Command.php b/src/Console/Command.php new file mode 100644 index 0000000..22c4b97 --- /dev/null +++ b/src/Console/Command.php @@ -0,0 +1,14 @@ + + */ +abstract class Command extends BaseCommand +{ + // +} diff --git a/src/Console/PublishCommand.php b/src/Console/PublishCommand.php new file mode 100644 index 0000000..e87becf --- /dev/null +++ b/src/Console/PublishCommand.php @@ -0,0 +1,44 @@ + + */ +class PublishCommand extends Command +{ + /* ------------------------------------------------------------------------------------------------ + | Properties + | ------------------------------------------------------------------------------------------------ + */ + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'media:publish'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Publish media config, assets and other stuff.'; + + /* ------------------------------------------------------------------------------------------------ + | Main Functions + | ------------------------------------------------------------------------------------------------ + */ + /** + * Execute the console command. + */ + public function handle() + { + $this->call('vendor:publish', [ + '--provider' => MediaServiceProvider::class, + ]); + } +} diff --git a/src/MediaServiceProvider.php b/src/MediaServiceProvider.php index 461e58b..82b8794 100644 --- a/src/MediaServiceProvider.php +++ b/src/MediaServiceProvider.php @@ -58,13 +58,6 @@ public function register() $this->syncFilesystemConfig(); } - private function syncFilesystemConfig() - { - foreach ($this->config()->get('arcanesoft.media.filesystem.disks', []) as $disk => $config) { - $this->config()->set("filesystems.disks.$disk", $config); - } - } - /** * Boot the service provider. */ @@ -78,6 +71,7 @@ public function boot() $this->publishViews(); $this->publishTranslations(); $this->publishSidebarItems(); + $this->publishAssets(); } /** @@ -91,4 +85,28 @@ public function provides() // ]; } + + /* ------------------------------------------------------------------------------------------------ + | Other Functions + | ------------------------------------------------------------------------------------------------ + */ + /** + * Sync the filesystem config. + */ + private function syncFilesystemConfig() + { + foreach ($this->config()->get('arcanesoft.media.filesystem.disks', []) as $disk => $config) { + $this->config()->set("filesystems.disks.$disk", $config); + } + } + + /** + * Publish the assets. + */ + private function publishAssets() + { + $this->publishes([ + $this->getBasePath() . '/resources/assets/js' => resource_path("assets/back/js/components/{$this->vendor}/{$this->package}"), + ], 'assets-js'); + } } diff --git a/src/Providers/CommandServiceProvider.php b/src/Providers/CommandServiceProvider.php index 358a18c..6f8295b 100644 --- a/src/Providers/CommandServiceProvider.php +++ b/src/Providers/CommandServiceProvider.php @@ -1,8 +1,48 @@ + */ class CommandServiceProvider extends ServiceProvider { + /* ------------------------------------------------------------------------------------------------ + | Properties + | ------------------------------------------------------------------------------------------------ + */ + /** + * Console commands. + * + * @var array + */ + protected $commands = [ + Console\PublishCommand::class, + ]; + /* ------------------------------------------------------------------------------------------------ + | Main Functions + | ------------------------------------------------------------------------------------------------ + */ + /** + * Register the service provider. + */ + public function register() + { + $this->commands($this->commands); + } + + /** + * Get the provided commands. + * + * @return array + */ + public function provides() + { + return $this->commands; + } } diff --git a/tests/Providers/CommandServiceProviderTest.php b/tests/Providers/CommandServiceProviderTest.php new file mode 100644 index 0000000..1681217 --- /dev/null +++ b/tests/Providers/CommandServiceProviderTest.php @@ -0,0 +1,65 @@ + + */ +class CommandServiceProviderTest extends TestCase +{ + /* ------------------------------------------------------------------------------------------------ + | Properties + | ------------------------------------------------------------------------------------------------ + */ + /** @var \Arcanesoft\Media\Providers\CommandServiceProvider */ + private $provider; + + /* ------------------------------------------------------------------------------------------------ + | Main Functions + | ------------------------------------------------------------------------------------------------ + */ + public function setUp() + { + parent::setUp(); + + $this->provider = $this->app->getProvider(\Arcanesoft\Media\Providers\CommandServiceProvider::class); + } + + public function tearDown() + { + unset($this->provider); + + parent::tearDown(); + } + + /* ------------------------------------------------------------------------------------------------ + | Test Functions + | ------------------------------------------------------------------------------------------------ + */ + /** @test */ + public function it_can_be_instantiated() + { + $expectations = [ + \Illuminate\Support\ServiceProvider::class, + \Arcanedev\Support\ServiceProvider::class, + \Arcanesoft\Media\Providers\CommandServiceProvider::class, + ]; + + foreach ($expectations as $expected) { + $this->assertInstanceOf($expected, $this->provider); + } + } + + /** @test */ + public function it_can_provides() + { + $expected = [ + \Arcanesoft\Media\Console\PublishCommand::class, + ]; + + $this->assertSame($expected, $this->provider->provides()); + } +}