Kaynağa Gözat

主题编译命令增加编译所有内置主题功能

jqh 5 yıl önce
ebeveyn
işleme
6e3fd235dc

+ 2 - 5
resources/assets/dcat/sass/theme/_colors.scss

@@ -22,11 +22,8 @@ $orange: #dda451; //$warning
 $green: #21b978; //$success
 $cyan: #7367f0; //$primary
 
-
-$primary: $indigo;
-//$primary: #4e9876; // green
-//$primary: #5686d4; // blue
-//$primary: #4199de; //blue-light
+// 设置主题颜色
+@import "./primary";
 
 $info: $blue;
 $warning: $orange;

+ 6 - 0
resources/assets/dcat/sass/theme/_primary.scss

@@ -0,0 +1,6 @@
+// 设置主题颜色
+
+$primary: $indigo;
+//$primary: #4e9876; // green
+//$primary: #5686d4; // blue
+//$primary: #4199de; //blue-light

+ 40 - 15
src/Console/ThemeCommand.php

@@ -8,13 +8,16 @@ use TitasGailius\Terminal\Terminal;
 
 class ThemeCommand extends Command
 {
+    const ALL = 'all';
+    const DEFAULT = 'default';
+
     /**
      * The name and signature of the console command.
      *
      * @var string
      */
-    protected $signature = 'admin:theme {name} 
-        {--color= : Theme color} 
+    protected $signature = 'admin:theme {name} 
+        {--color= : Theme color code} 
         {--publish : Publish assets files}';
 
     /**
@@ -28,10 +31,10 @@ class ThemeCommand extends Command
      * @var array
      */
     protected $themes = [
-        'indigo'     => '$indigo',
-        'blue'       => '#5686d4',
-        'blue-light' => '#4199de',
-        'green'      => '#4e9876',
+        self::DEFAULT => '',
+        'blue'        => '#5686d4',
+        'blue-light'  => '#4199de',
+        'green'       => '#4e9876',
     ];
 
     /**
@@ -57,6 +60,11 @@ class ThemeCommand extends Command
         $this->files = $this->laravel['files'];
 
         $name = $this->argument('name');
+
+        if ($name === static::ALL) {
+            return $this->compileAllDefaultThemes();
+        }
+
         $publish = $this->option('publish');
         $color = $this->getColor($name);
 
@@ -64,9 +72,9 @@ class ThemeCommand extends Command
         $this->replaceFiles($name, $color);
 
         try {
-            $this->installNodeModules();
+            $this->npmInstall();
 
-            $this->info('npm run production...');
+            $this->info("[$name][$color] npm run production...");
 
             // 编译
             $response = Terminal::builder()
@@ -88,6 +96,16 @@ class ThemeCommand extends Command
         }
     }
 
+    /**
+     * 编译所有内置主题.
+     */
+    protected function compileAllDefaultThemes()
+    {
+        foreach ($this->themes as $name => $_) {
+            $this->call('admin:theme', ['name' => $name]);
+        }
+    }
+
     /**
      * 发布静态资源.
      */
@@ -106,13 +124,16 @@ class ThemeCommand extends Command
      */
     protected function replaceFiles($name, $color)
     {
+        if ($name === static::DEFAULT) {
+            return;
+        }
+
         $mixFile = $this->getMixFile();
         $contents = str_replace('let theme = null', "let theme = '{$name}'", $this->files->get($mixFile));
         $this->files->put($mixFile, $contents);
 
         $colorFile = $this->getColorFile();
-        $contents = str_replace('$primary: $indigo;', "\$primary: $color;", $this->files->get($colorFile));
-        $this->files->put($colorFile, $contents);
+        $this->files->put($colorFile, "\$primary: $color;");
     }
 
     /**
@@ -168,7 +189,7 @@ class ThemeCommand extends Command
      */
     protected function getColorFile()
     {
-        return $this->packagePath.'/resources/assets/dcat/sass/theme/_colors.scss';
+        return $this->packagePath.'/resources/assets/dcat/sass/theme/_primary.scss';
     }
 
     /**
@@ -180,9 +201,9 @@ class ThemeCommand extends Command
     }
 
     /**
-     * 安装node依赖.
+     * 安装依赖.
      */
-    protected function installNodeModules()
+    protected function npmInstall()
     {
         if (is_dir($this->packagePath.'/node_modules')) {
             return;
@@ -192,9 +213,9 @@ class ThemeCommand extends Command
 
         $response = Terminal::builder()
             ->timeout(1800)
-            ->run('npm install');
+            ->run("cd {$this->packagePath} && npm install");
 
-        $this->line($response);
+        $this->line($response->output());
     }
 
     /**
@@ -206,6 +227,10 @@ class ThemeCommand extends Command
      */
     protected function getColor($name)
     {
+        if ($name === static::DEFAULT) {
+            return '';
+        }
+
         INPUT_COLOR:
 
         $color = $this->option('color');