Created
June 15, 2018 14:59
-
-
Save nulpatrol/e4e60c403dc35a22c4249f0d31c40fd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Illuminate\Foundation\Console; | |
use InvalidArgumentException; | |
use Illuminate\Console\Command; | |
class PresetCommand extends Command | |
{ | |
/** | |
* The console command signature. | |
* | |
* @var string | |
*/ | |
protected $signature = 'preset { type : The preset type (none, bootstrap, vue, react) } {--D|dev}'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Swap the front-end scaffolding for the application'; | |
/** | |
* Default presets | |
* | |
* @var array | |
*/ | |
private $defaultPresets = [ | |
'none' => Presets\None::class, | |
'bootstrap' => Presets\Bootstrap::class, | |
'vue' => Presets\Vue::class, | |
'react' => Presets\React::class, | |
]; | |
/** | |
* Execute the console command. | |
* | |
* @return void | |
*/ | |
public function handle() | |
{ | |
if (static::hasMacro($this->argument('type'))) { | |
return call_user_func(static::$macros[$this->argument('type')], $this); | |
} | |
if (! in_array($this->argument('type'), array_keys($this->defaultPresets))) { | |
throw new InvalidArgumentException('Invalid preset.'); | |
} | |
$preset_class = $this->defaultPresets[$this->argument('type')]; | |
forward_static_call([$preset_class, 'install'], $this->option('dev')); | |
if ($this->argument('type') === 'none') { | |
$this->info('Frontend scaffolding removed successfully.'); | |
} else { | |
$this->info('Frontend scaffolding installed successfully.'); | |
$this->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment