|
@@ -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');
|