1
0
Files
breadcrumb-the-shire/bin/module-assets-sync.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

62 lines
2.0 KiB
PHP

#!/usr/bin/env php
<?php
/**
* Publishes enabled module web assets into web/modules/.
*
* Usage: php bin/module-assets-sync.php
*
* APP_MODULE_ASSET_MODE:
* - symlink (default): create web/modules/<module-id> symlinks to modules/<id>/web
* - copy: copy module web directories (for environments without symlink support)
*
* Exit codes:
* 0 — sync successful
* 1 — error during sync
*/
declare(strict_types=1);
use MintyPHP\App\Module\ModuleRegistry;
use MintyPHP\App\Module\ModuleRuntimeAssetPublisher;
require_once __DIR__ . '/module-cli-bootstrap.php';
function moduleAssetsSyncRun(): int
{
return moduleCliRunStep('module-assets-sync', static function (): int {
$runtimeModulesDir = __DIR__ . '/../web/modules';
$lockFile = __DIR__ . '/../storage/runtime/.module-assets-sync.lock';
$mode = (string) getenv('APP_MODULE_ASSET_MODE');
if (trim($mode) === '') {
$mode = 'symlink';
}
return moduleCliWithFileLock(
$lockFile,
'module-assets-sync: another sync is in progress, skipping.',
static function () use ($runtimeModulesDir, $mode): int {
$registry = app(ModuleRegistry::class);
$publisher = new ModuleRuntimeAssetPublisher();
$result = $publisher->publish($runtimeModulesDir, $registry->getModules(), $mode);
fwrite(STDOUT, sprintf(
"module-assets-sync: mode=%s created=%d updated=%d removed=%d unchanged=%d\n",
$mode,
$result['created'],
$result['updated'],
$result['removed'],
$result['unchanged']
));
return 0;
}
);
});
}
if (PHP_SAPI === 'cli' && realpath((string) ($_SERVER['SCRIPT_FILENAME'] ?? '')) === __FILE__) {
fwrite(STDERR, "Hint: prefer `php bin/console module:assets-sync` instead.\n");
exit(moduleAssetsSyncRun());
}