1
0
Files
breadcrumb-the-shire/bin/module-build.php
fs ba1186c525 refactor: console improvements — auto-discovery, centralized bootstrap, per-command help
- ConsoleApplication.discoverCommands() scans lib/Console/Commands/ automatically;
  adding a new command no longer requires editing bin/console
- Command base class provides bootstrapApp(), bootstrapModuleApp(), requireBinScript()
  and projectRoot() helpers — eliminates fragile 4-level relative require_once paths
- Per-command --help support via optional usage() method on Command
- Docker-compose scheduler updated to use bin/console scheduler:run
- Old bin scripts now emit deprecation hint to stderr when called directly

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 19:16:36 +01:00

69 lines
2.4 KiB
PHP

#!/usr/bin/env php
<?php
/**
* Builds the runtime page root by symlinking module pages into storage/runtime/pages/.
*
* Usage: php bin/module-build.php
*
* The runtime page root mirrors the core pages/ directory and adds symlinks for
* each enabled module's pages. MintyPHP Router::$pageRoot points to this directory.
*
* This script is idempotent and uses a lock file to prevent concurrent builds.
*
* Exit codes:
* 0 — build successful (or nothing to do)
* 1 — error during build
*/
declare(strict_types=1);
use MintyPHP\App\Module\ModuleRegistry;
use MintyPHP\App\Module\ModuleRuntimePageBuilder;
require_once __DIR__ . '/module-cli-bootstrap.php';
function moduleBuildRun(): int
{
return moduleCliRunStep('module-build', static function (): int {
$runtimeDir = __DIR__ . '/../storage/runtime/pages';
$lockFile = __DIR__ . '/../storage/runtime/.module-build.lock';
// Ensure runtime directory exists
$runtimeParent = dirname($runtimeDir);
if (!is_dir($runtimeParent) && !mkdir($runtimeParent, 0775, true) && !is_dir($runtimeParent)) {
throw new \RuntimeException("Failed to create runtime directory: {$runtimeParent}");
}
return moduleCliWithFileLock(
$lockFile,
'module-build: another build is in progress, skipping.',
static function () use ($runtimeDir): int {
$registry = app(ModuleRegistry::class);
$modules = $registry->getModules();
$builder = new ModuleRuntimePageBuilder();
$result = $builder->build($runtimeDir, __DIR__ . '/../pages', $modules);
ModuleRuntimePageBuilder::writeFingerprint($runtimeDir, $modules);
if (count($modules) === 0) {
fwrite(STDOUT, "module-build: no modules, runtime -> core pages (symlink).\n");
} else {
fwrite(STDOUT, sprintf(
"module-build: runtime pages built - %d core entries + %d module entries.\n",
(int) ($result['core_entries'] ?? 0),
(int) ($result['module_entries'] ?? 0)
));
}
return 0;
}
);
});
}
if (PHP_SAPI === 'cli' && realpath((string) ($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {
fwrite(STDERR, "Hint: prefer `php bin/console module:build` instead.\n");
exit(moduleBuildRun());
}