2022-05-27 04:08:51 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2022-05-27 04:08:51 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
class ReactBuilder extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2024-05-09 01:35:50 +02:00
|
|
|
protected $signature = 'ninja:react {--type=}';
|
2022-05-27 04:08:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Builds blade component for react includes';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
2024-04-04 13:03:56 +02:00
|
|
|
* @return void
|
2022-05-27 04:08:51 +02:00
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2024-05-09 01:35:50 +02:00
|
|
|
if($this->option('type') == 'local') {
|
2022-05-27 04:08:51 +02:00
|
|
|
|
2024-05-09 01:35:50 +02:00
|
|
|
|
2022-05-27 04:08:51 +02:00
|
|
|
|
2024-05-09 01:35:50 +02:00
|
|
|
$includes = '';
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2024-05-09 01:35:50 +02:00
|
|
|
$directoryIterator = false;
|
2022-05-27 04:08:51 +02:00
|
|
|
|
2024-05-09 01:35:50 +02:00
|
|
|
try {
|
|
|
|
$directoryIterator = new \RecursiveDirectoryIterator(public_path('react/v'.config('ninja.app_version').'/'), \RecursiveDirectoryIterator::SKIP_DOTS);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->error('React files not found');
|
|
|
|
return;
|
|
|
|
}
|
2022-05-27 04:08:51 +02:00
|
|
|
|
2024-05-09 01:35:50 +02:00
|
|
|
foreach (new \RecursiveIteratorIterator($directoryIterator) as $file) {
|
|
|
|
if ($file->getExtension() == 'js') {
|
|
|
|
if (str_contains($file->getFileName(), 'index-')) {
|
|
|
|
$includes .= '<script type="module" crossorigin src="/react/v'.config('ninja.app_version').'/'.$file->getFileName().'"></script>'."\n";
|
|
|
|
} else {
|
|
|
|
$includes .= '<link rel="modulepreload" href="/react/v'.config('ninja.app_version').'/'.$file->getFileName().'">'."\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str_contains($file->getFileName(), '.css')) {
|
|
|
|
$includes .= '<link rel="stylesheet" href="/react/v'.config('ninja.app_version').'/'.$file->getFileName().'">'."\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file_put_contents(resource_path('views/react/head.blade.php'), $includes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-27 04:08:51 +02:00
|
|
|
}
|
|
|
|
}
|