diff --git a/src/Console/Module/InitCommand.php b/src/Console/Module/InitCommand.php index f7b7a92e..15dcfe75 100644 --- a/src/Console/Module/InitCommand.php +++ b/src/Console/Module/InitCommand.php @@ -15,15 +15,13 @@ class InitCommand extends Command protected $module; - protected $moduleVersion = 9; - protected $directory; public function handle(): void { $this->checkOption(); - // $this->initDB(); + $this->initDB(); $this->initAdminDirectory(); } @@ -68,10 +66,6 @@ protected function initAdminDirectory() { $this->setDirectory(); - if (is_dir($this->directory . '/app')) { - $this->moduleVersion = 10; - } - $this->createAuthController(); $this->createBootstrapFile(); $this->createRoutesFile(); @@ -87,14 +81,14 @@ private function makeDir($path = '') $this->laravel['files']->makeDirectory("{$this->directory}/$path", 0755, true, true); } - private function getAppPath() + public function getPath($path, $isApp = false) { - return $this->directory . ($this->moduleVersion == 10 ? '/app' : ''); + return AdminModule::getModulePath($this->module->getName(), $path, $isApp); } public function createAuthController(): void { - $authController = $this->getAppPath() . '/Http/Controllers/AuthController.php'; + $authController = $this->getPath('/Http/Controllers/AuthController.php', true); $contents = $this->getStub('AuthController'); $this->laravel['files']->put( $authController, @@ -105,17 +99,16 @@ public function createAuthController(): void protected function createBootstrapFile() { - $file = $this->getAppPath() . '/bootstrap.php'; - + $file = $this->getPath('/bootstrap.php', true); $contents = $this->getStub('bootstrap'); + $this->laravel['files']->put($file, $contents); $this->line('Bootstrap file was created: ' . str_replace(base_path(), '', $file)); } protected function createRoutesFile() { - $file = $this->directory . ($this->moduleVersion == 10 ? '/routes/admin.php' : '/Routes/admin.php'); - + $file = $this->getPath('/routes/admin.php'); $contents = $this->getStub('routes'); $content = str_replace('{{Namespace}}', $this->getNamespace('Http\Controllers'), $contents); $content = str_replace('{{module}}', $this->module->getLowerName(), $content); @@ -126,8 +119,9 @@ protected function createRoutesFile() public function createHomeController(): void { - $homeController = $this->getAppPath() . '/Http/Controllers/HomeController.php'; + $homeController = $this->getPath('/Http/Controllers/HomeController.php', true); $contents = $this->getStub('HomeController'); + $this->laravel['files']->put( $homeController, str_replace('{{Namespace}}', $this->getNamespace('Http\Controllers'), $contents) @@ -137,8 +131,9 @@ public function createHomeController(): void public function createSettingController() { - $settingController = $this->getAppPath() . '/Http/Controllers/SettingController.php'; + $settingController = $this->getPath('/Http/Controllers/SettingController.php', true); $contents = $this->getStub('SettingController'); + $this->laravel['files']->put( $settingController, str_replace('{{Namespace}}', $this->getNamespace('Http\Controllers'), $contents) @@ -150,7 +145,7 @@ public function createSettingController() protected function getNamespace($name = null): string { - $prefix = $this->moduleVersion == 10 ? 'app\\' : ''; + $prefix = AdminModule::isV10() ? 'app\\' : ''; return config('modules.namespace') . "\\{$this->module->getName()}\\{$prefix}{$name}"; } @@ -176,14 +171,15 @@ protected function createViews() protected function createConfig() { - $config = $this->directory . ($this->moduleVersion == 10 ? "/config/admin.php" : "/Config/admin.php"); + $config = $this->getPath("/config/admin.php"); $contents = $this->getStub('config'); - $_path = 'Modules/' . $this->module->getName() . ($this->moduleVersion == 10 ? '/app' : '') . '/bootstrap.php'; - $content = str_replace('{{bootstrap}}', 'base_path(\'' . $_path . '\')', $contents); - $content = str_replace('{{route_prefix}}', $this->module->getLowerName() . '-api', $content); - $content = str_replace('{{module_name}}', $this->module->getLowerName(), $content); - $content = str_replace('{{route_namespace}}', $this->getNamespace('Http\Controllers'), $content); - $content = str_replace('{{model_namespace}}', $this->getNamespace('Models'), $content); + $_path = 'Modules/' . $this->module->getName() . (AdminModule::isV10() ? '/app' : '') . '/bootstrap.php'; + + $content = str_replace('{{bootstrap}}', 'base_path(\'' . $_path . '\')', $contents); + $content = str_replace('{{route_prefix}}', $this->module->getLowerName() . '-api', $content); + $content = str_replace('{{module_name}}', $this->module->getLowerName(), $content); + $content = str_replace('{{route_namespace}}', $this->getNamespace('Http\Controllers'), $content); + $content = str_replace('{{model_namespace}}', $this->getNamespace('Models'), $content); $this->laravel['files']->put($config, $content); $this->line('Config file was created: ' . str_replace(base_path(), '', $config)); @@ -191,12 +187,12 @@ protected function createConfig() protected function createModel() { - if ($this->moduleVersion == 9) { + if (!AdminModule::isV10()) { $this->makeDir('Models'); } $run = function ($name) { - $file = $this->getAppPath() . "/Models/{$name}.php"; + $file = $this->getPath("/Models/{$name}.php", true); $contents = $this->getStub($name); $content = str_replace('{{Namespace}}', $this->getNamespace('Models'), $contents); $content = str_replace('{{module}}', $this->module->getLowerName(), $content); diff --git a/src/Console/Module/UpdateCommand.php b/src/Console/Module/UpdateCommand.php index ad9fb81e..280a470d 100644 --- a/src/Console/Module/UpdateCommand.php +++ b/src/Console/Module/UpdateCommand.php @@ -41,16 +41,13 @@ protected function updateViews() } foreach ($modules as $module) { - $module = Module::find(ucfirst($module)); - $script = ''; + $module = Module::find(ucfirst($module)); + + $script = ''; + $content = preg_replace('/