2026-05-21 21:25:04 -05:00
|
|
|
#!/usr/bin/env php
|
|
|
|
|
<?php
|
2026-05-31 13:36:05 -05:00
|
|
|
|
2026-05-21 21:25:04 -05:00
|
|
|
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
*
|
|
|
|
|
* FILE INFORMATION
|
2026-05-21 21:33:52 -05:00
|
|
|
* DEFGROUP: moko-platform.CLI
|
|
|
|
|
* INGROUP: moko-platform
|
2026-05-21 21:25:04 -05:00
|
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
|
|
|
|
|
* PATH: /cli/badge_update.php
|
|
|
|
|
* BRIEF: Update [VERSION: XX.XX.XX] badges in all markdown files
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-05-31 11:39:10 -05:00
|
|
|
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
2026-05-21 21:25:04 -05:00
|
|
|
|
2026-05-31 11:39:10 -05:00
|
|
|
use MokoEnterprise\CliFramework;
|
2026-05-21 21:25:04 -05:00
|
|
|
|
2026-05-31 11:39:10 -05:00
|
|
|
class BadgeUpdateCli extends CliFramework
|
|
|
|
|
{
|
|
|
|
|
protected function configure(): void
|
|
|
|
|
{
|
|
|
|
|
$this->setDescription('Update VERSION badges in all markdown files');
|
|
|
|
|
$this->addArgument('--path', 'Repository root path', '.');
|
|
|
|
|
$this->addArgument('--version', 'Version string XX.YY.ZZ', '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function run(): int
|
|
|
|
|
{
|
|
|
|
|
$path = $this->getArgument('--path');
|
|
|
|
|
$version = $this->getArgument('--version');
|
|
|
|
|
|
|
|
|
|
if (empty($version)) {
|
|
|
|
|
$this->log('ERROR', 'Usage: badge_update.php --path . --version XX.YY.ZZ');
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2026-05-21 21:25:04 -05:00
|
|
|
|
2026-05-31 11:39:10 -05:00
|
|
|
$root = realpath($path) ?: $path;
|
|
|
|
|
$pattern = '/\[VERSION:\s*\d{2}\.\d{2}\.\d{2}\]/';
|
|
|
|
|
$replacement = "[VERSION: {$version}]";
|
|
|
|
|
$updated = 0;
|
2026-05-21 21:25:04 -05:00
|
|
|
|
2026-05-31 11:39:10 -05:00
|
|
|
$iterator = new RecursiveIteratorIterator(
|
|
|
|
|
new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS)
|
|
|
|
|
);
|
2026-05-21 21:25:04 -05:00
|
|
|
|
2026-05-31 11:39:10 -05:00
|
|
|
foreach ($iterator as $file) {
|
|
|
|
|
$filePath = $file->getPathname();
|
2026-05-21 21:25:04 -05:00
|
|
|
|
2026-05-31 11:39:10 -05:00
|
|
|
if (preg_match('#[/\\\\](\.git|vendor)[/\\\\]#', $filePath)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!preg_match('/\.md$/i', $filePath)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-05-21 21:25:04 -05:00
|
|
|
|
2026-05-31 11:39:10 -05:00
|
|
|
$content = file_get_contents($filePath);
|
|
|
|
|
if (preg_match($pattern, $content)) {
|
|
|
|
|
$newContent = preg_replace($pattern, $replacement, $content);
|
|
|
|
|
if ($newContent !== $content) {
|
|
|
|
|
if (!$this->dryRun) {
|
|
|
|
|
file_put_contents($filePath, $newContent);
|
|
|
|
|
}
|
|
|
|
|
$relative = str_replace($root . DIRECTORY_SEPARATOR, '', $filePath);
|
|
|
|
|
$this->log('INFO', "Updated: {$relative}");
|
|
|
|
|
$updated++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-21 21:25:04 -05:00
|
|
|
|
2026-05-31 11:39:10 -05:00
|
|
|
$this->success("Updated {$updated} file(s) to {$replacement}");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2026-05-21 21:25:04 -05:00
|
|
|
}
|
|
|
|
|
|
2026-05-31 11:39:10 -05:00
|
|
|
$app = new BadgeUpdateCli();
|
|
|
|
|
exit($app->execute());
|