Browse Source

Development console

jqh 5 years ago
parent
commit
9650a3b760

+ 20 - 29
src/AdminServiceProvider.php

@@ -31,15 +31,20 @@ class AdminServiceProvider extends ServiceProvider
         Console\FormCommand::class,
         Console\ActionCommand::class,
         Console\MenuCacheCommand::class,
-        Console\Tests\InstallCommand::class,
-        Console\AssetsLinkCommand::class,
     ];
 
     /**
-     * The application's route middleware.
+     * 开发环境命令.
      *
      * @var array
      */
+    protected $devCommands = [
+        Console\Development\LinkCommand::class,
+    ];
+
+    /**
+     * @var array
+     */
     protected $routeMiddleware = [
         'admin.auth'       => Middleware\Authenticate::class,
         'admin.pjax'       => Middleware\Pjax::class,
@@ -50,8 +55,6 @@ class AdminServiceProvider extends ServiceProvider
     ];
 
     /**
-     * The application's route middleware groups.
-     *
      * @var array
      */
     protected $middlewareGroups = [
@@ -65,11 +68,6 @@ class AdminServiceProvider extends ServiceProvider
         ],
     ];
 
-    /**
-     * Boot the service provider.
-     *
-     * @return void
-     */
     public function boot()
     {
         $this->registerDefaultSections();
@@ -80,11 +78,6 @@ class AdminServiceProvider extends ServiceProvider
         $this->compatibleBlade();
     }
 
-    /**
-     * Register the service provider.
-     *
-     * @return void
-     */
     public function register()
     {
         require_once __DIR__.'/Support/AdminSection.php';
@@ -95,18 +88,19 @@ class AdminServiceProvider extends ServiceProvider
         $this->registerServices();
 
         $this->commands($this->commands);
+
+        if (config('app.debug') && config('app.env') === 'local') {
+            $this->commands($this->devCommands);
+        }
     }
 
-    /**
-     * Register the view file namespace.
-     */
     protected function registerViews()
     {
         $this->loadViewsFrom(__DIR__.'/../resources/views', 'admin');
     }
 
     /**
-     * Force to set https scheme if https enabled.
+     * 是否强制使用https
      *
      * @return void
      */
@@ -119,7 +113,7 @@ class AdminServiceProvider extends ServiceProvider
     }
 
     /**
-     * Register routes.
+     * 路由注册.
      */
     protected function registerRoutes()
     {
@@ -129,7 +123,7 @@ class AdminServiceProvider extends ServiceProvider
     }
 
     /**
-     * Remove default feature of double encoding enable in laravel 5.6 or later.
+     * 禁止laravel 5.6或更高版本中启用双编码的默认特性.
      *
      * @return void
      */
@@ -142,7 +136,7 @@ class AdminServiceProvider extends ServiceProvider
     }
 
     /**
-     * Register the package's publishable resources.
+     * 资源发布注册.
      *
      * @return void
      */
@@ -157,7 +151,7 @@ class AdminServiceProvider extends ServiceProvider
     }
 
     /**
-     * Register the service provider of extensions.
+     * 扩展注册.
      */
     public function registerExtensionProviders()
     {
@@ -169,7 +163,7 @@ class AdminServiceProvider extends ServiceProvider
     }
 
     /**
-     * Setup auth configuration.
+     * 设置 auth 配置.
      *
      * @return void
      */
@@ -179,7 +173,7 @@ class AdminServiceProvider extends ServiceProvider
     }
 
     /**
-     * Register default sections.
+     * 默认 section 注册.
      */
     protected function registerDefaultSections()
     {
@@ -201,9 +195,6 @@ class AdminServiceProvider extends ServiceProvider
         }, true);
     }
 
-    /**
-     * Register admin services.
-     */
     protected function registerServices()
     {
         $this->app->singleton('admin.assets', Assets::class);
@@ -215,7 +206,7 @@ class AdminServiceProvider extends ServiceProvider
     }
 
     /**
-     * Register the route middleware.
+     * 路由中间件注册.
      *
      * @return void
      */

+ 53 - 43
src/Console/AssetsLinkCommand.php → src/Console/Development/LinkCommand.php

@@ -1,43 +1,53 @@
-<?php
-
-namespace Dcat\Admin\Console;
-
-use Dcat\Admin\Admin;
-use Illuminate\Console\Command;
-
-class AssetsLinkCommand extends Command
-{
-    /**
-     * The console command signature.
-     *
-     * @var string
-     */
-    protected $signature = 'admin:assets-link';
-
-    /**
-     * Execute the console command.
-     *
-     * @return void
-     */
-    public function handle()
-    {
-        $basePath = Admin::assets()->getRealPath('@admin');
-        $publicPath = public_path($basePath);
-
-        if (! is_dir($publicPath.'/..')) {
-            app('files')->makeDirectory($publicPath.'/..', 0755, true, true);
-        }
-
-        if (file_exists(public_path($publicPath))) {
-            return $this->error("The \"{$basePath}\" directory already exists.");
-        }
-
-        $distPath = realpath(__DIR__.'/../../resources/dist');
-
-        $this->laravel->make('files')->link(
-            $distPath, $publicPath
-        );
-
-        $this->info("The [$basePath] directory has been linked.");
-    }
-}
+<?php
+
+namespace Dcat\Admin\Console\Development;
+
+use Dcat\Admin\Admin;
+use Illuminate\Console\Command;
+
+class LinkCommand extends Command
+{
+    /**
+     * The console command signature.
+     *
+     * @var string
+     */
+    protected $signature = 'admin:dev:link';
+
+    /**
+     * Execute the console command.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        $this->linkAssets();
+        $this->linkTests();
+    }
+
+    protected function linkTests()
+    {
+    }
+
+    protected function linkAssets()
+    {
+        $basePath = Admin::assets()->getRealPath('@admin');
+        $publicPath = public_path($basePath);
+
+        if (! is_dir($publicPath.'/..')) {
+            app('files')->makeDirectory($publicPath.'/..', 0755, true, true);
+        }
+
+        if (file_exists(public_path($publicPath))) {
+            return $this->error("The \"{$basePath}\" directory already exists.");
+        }
+
+        $distPath = realpath(__DIR__ . '/../../resources/dist');
+
+        $this->laravel->make('files')->link(
+            $distPath, $publicPath
+        );
+
+        $this->info("The [$basePath] directory has been linked.");
+    }
+}

+ 0 - 34
src/Console/Tests/InstallCommand.php

@@ -1,34 +0,0 @@
-<?php
-
-namespace Dcat\Admin\Console\Tests;
-
-use Illuminate\Console\Command;
-use Illuminate\Filesystem\Filesystem;
-
-class InstallCommand extends Command
-{
-    protected $signature = 'admin:tests:install';
-
-    protected $description = 'Install the admin tests package';
-
-    /**
-     * @var Filesystem
-     */
-    protected $files;
-
-    protected $directory;
-
-    public function handle()
-    {
-        $this->files = app('files');
-
-        $this->initTestsDirectory();
-
-        $this->files->copyDirectory(realpath(__DIR__.'/../../../browser-tests'), base_path('tests'));
-    }
-
-    protected function initTestsDirectory()
-    {
-        $this->directory = base_path();
-    }
-}