Skip to content

Commit

Permalink
Add --no-progress and --json options to mix:compile and mix:list (#1087)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Thomson <[email protected]>
Documented by wintercms/docs#182
  • Loading branch information
Nimdoc authored Apr 4, 2024
1 parent 8218e05 commit 353e4b9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
11 changes: 7 additions & 4 deletions console/MixCompile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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
);

Expand Down
25 changes: 15 additions & 10 deletions console/MixList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -23,8 +24,6 @@ class MixList extends Command

public function handle(): int
{
$this->line('');

$mixedAssets = MixAssets::instance();
$mixedAssets->fireCallbacks();

Expand All @@ -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 ? '<fg=red>No</>' : '<info>Yes</info>',
'active' => !$package['ignored'],
'path' => $package['path'],
'configuration' => $package['mix'],
];
Expand All @@ -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']) ? '<info>Yes</info>' : '<fg=red>No</>';
return $row;
}, $rows));
$this->line('');
}

if (!empty($errors)) {
foreach ($errors as $error) {
Expand Down
2 changes: 1 addition & 1 deletion console/fixtures/mix.webpack.js.fixture
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = async () => {
};
break;
case "WebpackBarPlugin":
if (%silent%) {
if (%silent% || %noProgress%) {
plugins[index].apply = _ => void 0;
}
break;
Expand Down

0 comments on commit 353e4b9

Please sign in to comment.