|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Commands; |
| 4 | + |
| 5 | +use App\Core\Services\DependencyInstaller; |
| 6 | +use App\Core\Services\LaravelInstaller; |
| 7 | +use Illuminate\Console\Scheduling\Schedule; |
| 8 | +use LaravelZero\Framework\Commands\Command; |
| 9 | + |
| 10 | +use function Laravel\Prompts\error; |
| 11 | + |
| 12 | +class ProjectStart extends Command |
| 13 | +{ |
| 14 | + /** |
| 15 | + * The name and signature of the console command. |
| 16 | + * |
| 17 | + * @var string |
| 18 | + */ |
| 19 | + protected $signature = 'create-proyect'; |
| 20 | + |
| 21 | + /** |
| 22 | + * The console command description. |
| 23 | + * |
| 24 | + * @var string |
| 25 | + */ |
| 26 | + protected $description = 'Start a new Laravel Project'; |
| 27 | + |
| 28 | + public function __construct( |
| 29 | + private laravelInstaller $laravelInstaller, |
| 30 | + private DependencyInstaller $dependencies |
| 31 | + ){ |
| 32 | + parent::__construct(); |
| 33 | + } |
| 34 | + |
| 35 | + |
| 36 | + /** |
| 37 | + * Execute the console command. |
| 38 | + */ |
| 39 | + public function handle() |
| 40 | + { |
| 41 | + info('Welcome to laravel starter'); |
| 42 | + |
| 43 | + $this->task('Instaling Laravel', function () use(&$result): bool { |
| 44 | + $result = $this->laravelInstaller->install(); |
| 45 | + return $result->isSuccess(); |
| 46 | + }); |
| 47 | + |
| 48 | + if($result->isFailure()){ |
| 49 | + error('An error has occurred'); |
| 50 | + error('Here is more information about the failure:'); |
| 51 | + error($result->getContent()); |
| 52 | + |
| 53 | + return self::FAILURE; |
| 54 | + } |
| 55 | + |
| 56 | + $data = $result->getContent(); |
| 57 | + |
| 58 | + $dependencies = $data->options; |
| 59 | + $directory = $data->projectName; |
| 60 | + |
| 61 | + $this->task('Installing aditional libraries', function () use($dependencies, $directory) : bool { |
| 62 | + $this->dependencies->choose($dependencies); |
| 63 | + $this->dependencies->onDirectory($directory)->install(); |
| 64 | + return false; |
| 65 | + }); |
| 66 | + |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Define the command's schedule. |
| 72 | + */ |
| 73 | + public function schedule(Schedule $schedule): void |
| 74 | + { |
| 75 | + // $schedule->command(static::class)->everyMinute(); |
| 76 | + } |
| 77 | +} |
0 commit comments