You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
willaengine/app/Console/Commands/VuexBuild.php

89 lines
2.7 KiB

<?php
namespace App\Console\Commands;
use App\Services\MorphModelFinder;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
class VuexBuild extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:vuex {module} {store-module} {--category}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a vuex modules';
/**
* @var MorphModelFinder
*/
private $morphModelFinder;
/**
* Create a new command instance.
*
* @param MorphModelFinder $morphModelFinder
*/
public function __construct(MorphModelFinder $morphModelFinder)
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return void
*/
public function handle(): void
{
$isCategory = $this->option('category');
$module = $this->argument('module');
$storeModule = $this->argument('store-module');
$moduleFiles = ['actions.js', 'mutations.js', 'state.js', 'getters.js'];
$baseRepositoryPath = 'modules/wm-' . $module . '/resources/js/abstraction/repositories/' . $storeModule;
$baseResourcePath = 'modules/wm-' . $module . '/resources/js/abstraction/resources/' . $storeModule;
$baseActionPath = 'modules/wm-' . $module . '/resources/js/store/modules/' . $storeModule . '/';
$baseDefaultActionPath = 'resources/js/Default/store/store/';
// $name = $this->choice(
// 'file exist, Do yo really Replace File?',
// ['Taylor', 'Dayle'],
// 'Dayle'
// );
if ($storeModule && $module) {
foreach ($moduleFiles as $moduleFile) {
if (Storage::disk('local')->exists($baseActionPath . $moduleFile)) {
if ($this->confirm('file exist, Do yo really Replace File?', true)) {
$data = Storage::disk('local')->get($baseDefaultActionPath . $moduleFile);
$data = str_replace('|-module-|', Str::snake($storeModule), $data);
$data = str_replace('|-Module-|', Str::title($storeModule), $data);
$data = str_replace('|-MODULE-|', Str::upper($storeModule), $data);
$data = str_replace('|-BaseModule-|', Str::title($module), $data);
$data = str_replace('|-baseModule-|', Str::camel($module), $data);
Storage::disk('local')->put($baseActionPath . $moduleFile, $data);
}
}
}
}
$this->info('modules Store Created');
}
}