From 353e4b94f1a3e11b84db066ee0daaedddc9badec Mon Sep 17 00:00:00 2001 From: Tom Busby <16073340+Nimdoc@users.noreply.github.com> Date: Thu, 4 Apr 2024 07:45:58 +0200 Subject: [PATCH] Add --no-progress and --json options to mix:compile and mix:list (#1087) Co-authored-by: Ben Thomson Documented by https://github.com/wintercms/docs/pull/182 --- console/MixCompile.php | 11 +++++++---- console/MixList.php | 25 +++++++++++++++---------- console/fixtures/mix.webpack.js.fixture | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/console/MixCompile.php b/console/MixCompile.php index fb2c1860..73cd8260 100644 --- a/console/MixCompile.php +++ b/console/MixCompile.php @@ -22,7 +22,8 @@ class MixCompile extends Command {--s|silent : Silent mode} {--e|stop-on-error : Exit once an error is encountered} {--m|manifest= : Defines package.json to use for compile} - {--p|package=* : Defines one or more packages to compile}'; + {--p|package=* : Defines one or more packages to compile} + {--no-progress : Do not show mix progress}'; /** * @var string The console command description. @@ -101,7 +102,9 @@ public function handle(): int continue; } - $this->info(sprintf('Mixing package "%s"', $name)); + if (!$this->option('silent')) { + $this->info(sprintf('Mixing package "%s"', $name)); + } $exitCode = $this->mixPackage(base_path($relativeMixJsPath)); @@ -224,8 +227,8 @@ protected function createWebpackConfig(string $mixJsPath): void $fixture = File::get(__DIR__ . '/fixtures/mix.webpack.js.fixture'); $config = str_replace( - ['%base%', '%notificationInject%', '%mixConfigPath%', '%pluginsPath%', '%appPath%', '%silent%'], - [addslashes($basePath), 'mix._api.disableNotifications();', addslashes($mixJsPath), addslashes(plugins_path()), addslashes(base_path()), (int) $this->option('silent')], + ['%base%', '%notificationInject%', '%mixConfigPath%', '%pluginsPath%', '%appPath%', '%silent%', '%noProgress%'], + [addslashes($basePath), 'mix._api.disableNotifications();', addslashes($mixJsPath), addslashes(plugins_path()), addslashes(base_path()), (int) $this->option('silent'), (int) $this->option('no-progress')], $fixture ); diff --git a/console/MixList.php b/console/MixList.php index 74fcb6e5..23afc31c 100644 --- a/console/MixList.php +++ b/console/MixList.php @@ -14,7 +14,8 @@ class MixList extends Command /** * @var string The name and signature of this command. */ - protected $signature = 'mix:list'; + protected $signature = 'mix:list + {--json : Output as JSON}'; /** * @var string The console command description. @@ -23,8 +24,6 @@ class MixList extends Command public function handle(): int { - $this->line(''); - $mixedAssets = MixAssets::instance(); $mixedAssets->fireCallbacks(); @@ -35,16 +34,13 @@ public function handle(): int return 0; } - $this->info('Packages registered:'); - $this->line(''); - $errors = []; $rows = []; foreach ($packages as $name => $package) { $rows[] = [ 'name' => $name, - 'active' => $package['ignored'] ?? false ? 'No' : 'Yes', + 'active' => !$package['ignored'], 'path' => $package['path'], 'configuration' => $package['mix'], ]; @@ -54,9 +50,18 @@ public function handle(): int } } - $this->table(['Name', 'Active', 'Path', 'Configuration'], $rows); - - $this->line(''); + if ($this->option('json')) { + $this->line(json_encode($rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + } else { + $this->line(''); + $this->info('Packages registered:'); + $this->line(''); + $this->table(['Name', 'Active', 'Path', 'Configuration'], array_map(function ($row) { + $row['active'] = ($row['active']) ? 'Yes' : 'No'; + return $row; + }, $rows)); + $this->line(''); + } if (!empty($errors)) { foreach ($errors as $error) { diff --git a/console/fixtures/mix.webpack.js.fixture b/console/fixtures/mix.webpack.js.fixture index 6fe51062..b225f230 100644 --- a/console/fixtures/mix.webpack.js.fixture +++ b/console/fixtures/mix.webpack.js.fixture @@ -64,7 +64,7 @@ module.exports = async () => { }; break; case "WebpackBarPlugin": - if (%silent%) { + if (%silent% || %noProgress%) { plugins[index].apply = _ => void 0; } break;