#!/usr/bin/env php * * SPDX-License-Identifier: GPL-3.0-or-later * * FILE INFORMATION * DEFGROUP: moko-platform.CLI * INGROUP: moko-platform * REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform * PATH: /cli/badge_update.php * BRIEF: Update [VERSION: XX.XX.XX] badges in all markdown files * * Usage: * php badge_update.php --path /repo --version 04.01.00 */ declare(strict_types=1); $path = '.'; $version = null; foreach ($argv as $i => $arg) { if ($arg === '--path' && isset($argv[$i + 1])) $path = $argv[$i + 1]; if ($arg === '--version' && isset($argv[$i + 1])) $version = $argv[$i + 1]; } if ($version === null) { fwrite(STDERR, "Usage: badge_update.php --path . --version XX.YY.ZZ\n"); exit(1); } $root = realpath($path) ?: $path; $pattern = '/\[VERSION:\s*\d{2}\.\d{2}\.\d{2}\]/'; $replacement = "[VERSION: {$version}]"; $updated = 0; $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS) ); foreach ($iterator as $file) { $filePath = $file->getPathname(); // Skip .git and vendor directories if (preg_match('#[/\\\\](\.git|vendor)[/\\\\]#', $filePath)) { continue; } // Only process markdown files if (!preg_match('/\.md$/i', $filePath)) { continue; } $content = file_get_contents($filePath); if (preg_match($pattern, $content)) { $newContent = preg_replace($pattern, $replacement, $content); if ($newContent !== $content) { file_put_contents($filePath, $newContent); $relative = str_replace($root . DIRECTORY_SEPARATOR, '', $filePath); echo "Updated: {$relative}\n"; $updated++; } } } echo "Updated {$updated} file(s) to {$replacement}\n"; exit(0);