Skip to content

Instantly share code, notes, and snippets.

@nulpatrol
Created June 15, 2018 05:05
Show Gist options
  • Save nulpatrol/2900ddd5d3945fe3719195e99923ea15 to your computer and use it in GitHub Desktop.
Save nulpatrol/2900ddd5d3945fe3719195e99923ea15 to your computer and use it in GitHub Desktop.
<?php
namespace Illuminate\Foundation\Console;
use Illuminate\Broadcasting\PresenceChannel;
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) }';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Swap the front-end scaffolding for the application';
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.');
}
return $this->{$this->argument('type')}();
}
/**
* Install the "fresh" preset.
*
* @return void
*/
protected function none()
{
Presets\None::install();
$this->info('Frontend scaffolding removed successfully.');
}
/**
* Install the "bootstrap" preset.
*
* @return void
*/
protected function bootstrap()
{
Presets\Bootstrap::install();
$this->info('Bootstrap scaffolding installed successfully.');
$this->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
}
/**
* Install the "vue" preset.
*
* @return void
*/
protected function vue()
{
Presets\Vue::install();
$this->info('Vue scaffolding installed successfully.');
$this->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
}
/**
* Install the "react" preset.
*
* @return void
*/
protected function react()
{
Presets\React::install();
$this->info('React 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