Skip to content

Commit

Permalink
Add the action to publish the frontend resources
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Apr 7, 2022
1 parent 333f3b9 commit e2c82fb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Actions/PublishesDefaultFrontendResourceFiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Hyde\Framework\Actions;

use Hyde\Framework\Hyde;

/**
* Publishes default frontend resource files if they don't exist.
*
* This action is called when the Service Provider boots.
* @see \Hyde\Framework\HydeServiceProvider
* @todo Create option to disable this behaviour.
*/
class PublishesDefaultFrontendResourceFiles
{
public function __construct(protected ?bool $force = false)
{
//
}

public function __invoke(): void
{
$files = [
'app.css',
'hyde.css',
'hyde.js'
];

if (! is_dir(Hyde::path('resources/frontend'))) {
mkdir(Hyde::path('resources/frontend'), 0755, true);
}

foreach ($files as $file) {
$this->handleFile($file);
}
}

protected function handleFile(string $file): void
{
Hyde::copy(
Hyde::path('vendor/hyde/framework/resources/frontend/' . $file),
Hyde::path('resources/frontend/' . $file),
$this->force
);
}
}
2 changes: 2 additions & 0 deletions src/HydeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composer\InstalledVersions;
use Hyde\Framework\Actions\CreatesDefaultDirectories;
use Hyde\Framework\Actions\PublishesDefaultFrontendResourceFiles;
use Illuminate\Support\ServiceProvider;

class HydeServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -52,6 +53,7 @@ function () {
public function boot()
{
(new CreatesDefaultDirectories)->__invoke();
(new PublishesDefaultFrontendResourceFiles())->__invoke();

$this->loadViewsFrom(__DIR__.'/../resources/views', 'hyde');

Expand Down

0 comments on commit e2c82fb

Please sign in to comment.