refactor(cli)!: hard-cut legacy scripts and standardize console runtime

- remove legacy bin/module-*.php and bin/doctor.php entry scripts

- move module/doctor execution into class-based runners under lib/Console

- add stable JSON output for doctor and module:sync

- introduce bin/dev for init/up/down/logs/console/qa workflow

- update DI wiring, phpstan scan config, tests, and docs to new CLI contract
This commit is contained in:
2026-04-01 17:14:20 +02:00
parent 0bf7f62fd8
commit 7121732fcf
38 changed files with 1686 additions and 986 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace MintyPHP\Console\Commands\Module;
use MintyPHP\Console\Command;
use MintyPHP\Console\Runner\Module\ModuleRunner;
use MintyPHP\Console\Runner\Module\ModuleRunnerInterface;
abstract class AbstractModuleCommand extends Command
{
private ?ModuleRunnerInterface $moduleRunner;
public function __construct(?ModuleRunnerInterface $moduleRunner = null)
{
$this->moduleRunner = $moduleRunner;
}
protected function moduleRunner(): ModuleRunnerInterface
{
if ($this->moduleRunner instanceof ModuleRunnerInterface) {
return $this->moduleRunner;
}
$this->moduleRunner = new ModuleRunner();
return $this->moduleRunner;
}
}

View File

@@ -2,9 +2,7 @@
namespace MintyPHP\Console\Commands\Module;
use MintyPHP\Console\Command;
final class AssetsSyncCommand extends Command
final class AssetsSyncCommand extends AbstractModuleCommand
{
public function name(): string
{
@@ -18,9 +16,20 @@ final class AssetsSyncCommand extends Command
public function execute(array $args, array $options): int
{
$this->requireBinScript('module-cli-bootstrap.php');
$this->requireBinScript('module-assets-sync.php');
$result = $this->moduleRunner()->assetsSync();
fwrite(STDOUT, sprintf(
"module-assets-sync: mode=%s created=%d updated=%d removed=%d unchanged=%d\n",
$result['mode'],
$result['created'],
$result['updated'],
$result['removed'],
$result['unchanged']
));
return moduleAssetsSyncRun();
if ($result['message'] !== 'module-assets-sync: ok') {
fwrite(STDOUT, $result['message'] . PHP_EOL);
}
return (int) $result['exit_code'];
}
}

View File

@@ -2,9 +2,7 @@
namespace MintyPHP\Console\Commands\Module;
use MintyPHP\Console\Command;
final class BuildCommand extends Command
final class BuildCommand extends AbstractModuleCommand
{
public function name(): string
{
@@ -18,9 +16,21 @@ final class BuildCommand extends Command
public function execute(array $args, array $options): int
{
$this->requireBinScript('module-cli-bootstrap.php');
$this->requireBinScript('module-build.php');
$result = $this->moduleRunner()->build();
if ($result['status'] === 'ok') {
fwrite(STDOUT, sprintf(
"module-build: runtime pages built - %d core entries + %d module entries.\n",
$result['core_entries'],
$result['module_entries']
));
} else {
fwrite(STDERR, $result['message'] . PHP_EOL);
}
return moduleBuildRun();
if ($result['message'] !== 'module-build: ok' && $result['status'] === 'ok') {
fwrite(STDOUT, $result['message'] . PHP_EOL);
}
return (int) $result['exit_code'];
}
}

View File

@@ -2,9 +2,7 @@
namespace MintyPHP\Console\Commands\Module;
use MintyPHP\Console\Command;
final class DeactivateCommand extends Command
final class DeactivateCommand extends AbstractModuleCommand
{
public function name(): string
{
@@ -37,18 +35,15 @@ final class DeactivateCommand extends Command
return 1;
}
// Rebuild global argv for the underlying script
global $argv;
$argv = ['module-deactivate.php', $moduleId];
if ($options['confirm'] ?? false) {
$argv[] = '--confirm';
}
if ($options['dry-run'] ?? false) {
$argv[] = '--dry-run';
}
$result = $this->moduleRunner()->deactivate(
$moduleId,
(bool) ($options['confirm'] ?? false),
(bool) ($options['dry-run'] ?? false)
);
$this->requireBinScript('module-deactivate.php');
$stream = $result['exit_code'] === 0 ? STDOUT : STDERR;
fwrite($stream, $result['message'] . PHP_EOL);
return moduleDeactivateRun();
return (int) $result['exit_code'];
}
}

View File

@@ -2,9 +2,7 @@
namespace MintyPHP\Console\Commands\Module;
use MintyPHP\Console\Command;
final class MigrateCommand extends Command
final class MigrateCommand extends AbstractModuleCommand
{
public function name(): string
{
@@ -18,9 +16,9 @@ final class MigrateCommand extends Command
public function execute(array $args, array $options): int
{
$this->requireBinScript('module-cli-bootstrap.php');
$this->requireBinScript('module-migrate.php');
$result = $this->moduleRunner()->migrate();
fwrite(STDOUT, $result['message'] . PHP_EOL);
return moduleMigrateRun();
return (int) $result['exit_code'];
}
}

View File

@@ -2,9 +2,7 @@
namespace MintyPHP\Console\Commands\Module;
use MintyPHP\Console\Command;
final class PermissionsSyncCommand extends Command
final class PermissionsSyncCommand extends AbstractModuleCommand
{
public function name(): string
{
@@ -18,9 +16,20 @@ final class PermissionsSyncCommand extends Command
public function execute(array $args, array $options): int
{
$this->requireBinScript('module-cli-bootstrap.php');
$this->requireBinScript('module-permissions-sync.php');
$result = $this->moduleRunner()->permissionsSync();
fwrite(STDOUT, sprintf(
"module-permissions-sync: created=%d updated=%d unchanged=%d deactivated=%d total=%d\n",
$result['created'],
$result['updated'],
$result['unchanged'],
$result['deactivated'],
$result['total']
));
return modulePermissionsSyncRun();
if ($result['message'] !== 'module-permissions-sync: ok') {
fwrite(STDOUT, $result['message'] . PHP_EOL);
}
return (int) $result['exit_code'];
}
}

View File

@@ -2,9 +2,7 @@
namespace MintyPHP\Console\Commands\Module;
use MintyPHP\Console\Command;
final class RuntimeSyncCommand extends Command
final class RuntimeSyncCommand extends AbstractModuleCommand
{
public function name(): string
{
@@ -16,10 +14,42 @@ final class RuntimeSyncCommand extends Command
return 'Run full module runtime sync (migrate, permissions, build, assets)';
}
public function usage(): string
{
return <<<'USAGE'
Usage: php bin/console module:sync [--format=json]
Options:
--format=json Output stable JSON for automation
USAGE;
}
public function execute(array $args, array $options): int
{
$this->requireBinScript('module-runtime-sync.php');
$format = strtolower((string) ($options['format'] ?? 'human'));
if (!in_array($format, ['human', 'json'], true)) {
fwrite(STDERR, "Invalid format '{$format}'. Supported: human, json\n");
return 1;
}
return moduleRuntimeSyncRun();
$result = $this->moduleRunner()->runtimeSync();
if ($format === 'json') {
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL;
return (int) $result['exit_code'];
}
foreach ($result['steps'] as $stepName => $step) {
echo sprintf(
"module-runtime-sync: step=%s status=%s exit_code=%d vendor_warnings_ignored=%d\n",
$stepName,
$step['status'],
$step['exit_code'],
$step['vendor_warnings_ignored']
);
}
echo $result['message'] . PHP_EOL;
return (int) $result['exit_code'];
}
}