2026-04-15 02:35:30 +00:00
|
|
|
#!/usr/bin/env php
|
|
|
|
|
<?php
|
|
|
|
|
/* 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-11 17:01:17 -05:00
|
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
|
2026-04-15 02:35:30 +00:00
|
|
|
* PATH: /cli/version_read.php
|
2026-05-26 19:26:45 +00:00
|
|
|
* BRIEF: Read version — manifest.xml is canonical, falls back to README.md and Joomla XML
|
2026-04-15 02:35:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
$path = '.';
|
|
|
|
|
foreach ($argv as $i => $arg) {
|
|
|
|
|
if ($arg === '--path' && isset($argv[$i + 1])) {
|
|
|
|
|
$path = $argv[$i + 1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:47:49 -05:00
|
|
|
$root = realpath($path) ?: $path;
|
|
|
|
|
|
2026-05-26 19:26:45 +00:00
|
|
|
// -- 1. Read from .mokogitea/manifest.xml (canonical source) --
|
|
|
|
|
$mokoVersion = null;
|
|
|
|
|
$mokoManifest = "{$root}/.mokogitea/manifest.xml";
|
|
|
|
|
if (file_exists($mokoManifest)) {
|
|
|
|
|
$xml = @simplexml_load_file($mokoManifest);
|
|
|
|
|
if ($xml !== false) {
|
|
|
|
|
$v = (string)($xml->identity->version ?? '');
|
|
|
|
|
if (preg_match('/^\d{2}\.\d{2}\.\d{2}$/', $v)) {
|
|
|
|
|
$mokoVersion = $v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If manifest.xml has a version, that is authoritative
|
|
|
|
|
if ($mokoVersion !== null) {
|
|
|
|
|
echo $mokoVersion . "\n";
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -- 2. Fallback: README.md --
|
2026-05-23 22:47:49 -05:00
|
|
|
$readmeVersion = null;
|
|
|
|
|
$readme = "{$root}/README.md";
|
|
|
|
|
if (file_exists($readme)) {
|
|
|
|
|
$content = file_get_contents($readme);
|
2026-05-25 00:13:50 -05:00
|
|
|
if (preg_match('/VERSION:\s*(\d{2}\.\d{2}\.\d{2})/m', $content, $m)) {
|
2026-05-23 22:47:49 -05:00
|
|
|
$readmeVersion = $m[1];
|
|
|
|
|
}
|
2026-04-15 02:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
2026-05-26 19:26:45 +00:00
|
|
|
// -- 3. Fallback: Joomla manifest XML --
|
2026-05-23 22:47:49 -05:00
|
|
|
$manifestVersion = null;
|
|
|
|
|
$manifestFiles = array_merge(
|
|
|
|
|
glob("{$root}/src/pkg_*.xml") ?: [],
|
|
|
|
|
glob("{$root}/src/*.xml") ?: [],
|
|
|
|
|
glob("{$root}/src/packages/*/*.xml") ?: [],
|
|
|
|
|
glob("{$root}/*.xml") ?: []
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach ($manifestFiles as $xmlFile) {
|
|
|
|
|
$xmlContent = file_get_contents($xmlFile);
|
|
|
|
|
if (strpos($xmlContent, '<extension') === false && strpos($xmlContent, '<version>') === false) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-05-25 00:13:50 -05:00
|
|
|
if (preg_match('|<version>(\d{2}\.\d{2}\.\d{2})(?:-[a-z]+)?</version>|', $xmlContent, $xm)) {
|
2026-05-23 22:47:49 -05:00
|
|
|
$candidate = $xm[1];
|
|
|
|
|
if ($manifestVersion === null || version_compare($candidate, $manifestVersion, '>')) {
|
|
|
|
|
$manifestVersion = $candidate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-26 19:26:45 +00:00
|
|
|
// -- Output the higher version --
|
2026-05-23 22:47:49 -05:00
|
|
|
$version = null;
|
|
|
|
|
if ($readmeVersion !== null && $manifestVersion !== null) {
|
|
|
|
|
$version = version_compare($manifestVersion, $readmeVersion, '>') ? $manifestVersion : $readmeVersion;
|
|
|
|
|
} elseif ($manifestVersion !== null) {
|
|
|
|
|
$version = $manifestVersion;
|
|
|
|
|
} elseif ($readmeVersion !== null) {
|
|
|
|
|
$version = $readmeVersion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($version === null) {
|
2026-05-26 19:26:45 +00:00
|
|
|
fwrite(STDERR, "No version found in manifest.xml, README.md, or Joomla XML\n");
|
2026-05-23 22:47:49 -05:00
|
|
|
exit(1);
|
2026-04-15 02:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:47:49 -05:00
|
|
|
echo $version . "\n";
|
|
|
|
|
exit(0);
|