Files
Jonathan Miller b73c1eba25
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Report Issues (push) Has been cancelled
Generic: Project CI / Tests (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 2: Unit Tests (8.1) (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 2: Unit Tests (8.2) (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 2: Unit Tests (8.3) (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 3: Self-Health Check (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 4: Governance (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 5: Template Integrity (pull_request) Has been cancelled
Platform: mokoplatform CI / CI Summary (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Site Health (push) Has been cancelled
Generic: Repo Health / Access control (push) Has been cancelled
Generic: Repo Health / Site Health (pull_request) Has been cancelled
Universal: PR Check / Branch Policy (pull_request) Has been cancelled
Generic: Repo Health / Access control (pull_request) Has been cancelled
Universal: Build & Release / Promote to RC (pull_request) Has been cancelled
RC Revert / Rename rc/ back to dev/ (pull_request) Has been cancelled
Universal: Security Audit / Dependency Audit (pull_request) Has been cancelled
Branch Cleanup / Delete merged branch (pull_request) Has been cancelled
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Has been cancelled
Universal: PR Check / Validate PR (pull_request) Has been cancelled
Universal: Build & Release / Build & Release Pipeline (pull_request) Has been cancelled
Generic: Project CI / Lint & Validate (pull_request) Has been cancelled
Platform: mokoplatform CI / Gate 1: Code Quality (pull_request) Has been cancelled
feat: add manifest_detect.php CLI tool for auto-detecting manifest fields
Scans source files to detect platform, name, version, element_name,
package_type, language, entry_point, description, and license_spdx.
Supports Joomla, Dolibarr, Go, MCP/Node, and generic platforms.

Includes --diff and --update modes for comparing against and pushing
to the Gitea manifest API. Warns on missing core fields.

Also removes deprecated mcp/servers/mokowaas_api (consolidated to
separate repo) and syncs dev branch changes.
2026-06-07 15:37:24 -05:00

195 lines
5.9 KiB
PHP

#!/usr/bin/env php
<?php
/**
* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* FILE INFORMATION
* DEFGROUP: mokoplatform.Enterprise
* INGROUP: mokoplatform
* REPO: https://git.mokoconsulting.tech/MokoConsulting/mokoplatform
* PATH: /lib/Enterprise/ManifestReader.php
* BRIEF: Read and parse .mokogitea/manifest.xml — shared across all CLI tools
*/
declare(strict_types=1);
namespace MokoEnterprise;
/**
* Manifest Reader
*
* Parses .mokogitea/manifest.xml and provides typed access to all fields.
* Used by CLI tools and the Enterprise library to determine platform,
* build configuration, and deployment settings from the repository manifest.
*
* @since 09.01.00
*/
class ManifestReader
{
/** @var array<string, string> Parsed manifest fields */
private array $fields = [];
/** @var bool Whether a manifest was found and parsed */
private bool $loaded = false;
/**
* Load manifest from a repository root directory.
*
* @param string $root Repository root path
* @return self
*/
public static function fromPath(string $root): self
{
$reader = new self();
$reader->load($root);
return $reader;
}
/**
* Load and parse the manifest file.
*
* @param string $root Repository root path
*/
public function load(string $root): void
{
$candidates = [
"{$root}/.mokogitea/manifest.xml",
"{$root}/.mokogitea/.manifest.xml",
"{$root}/.mokogitea/.mokoplatform",
];
$manifestFile = null;
foreach ($candidates as $candidate) {
if (file_exists($candidate)) {
$manifestFile = $candidate;
break;
}
}
if ($manifestFile === null) {
return;
}
$xml = @simplexml_load_file($manifestFile);
if ($xml === false) {
// Fallback: YAML legacy format
$content = file_get_contents($manifestFile);
if (preg_match('/^platform:\s*(.+)/m', $content, $m)) {
$this->fields['platform'] = trim($m[1], " \t\n\r\"'");
}
$this->loaded = true;
return;
}
$this->fields = [
'name' => (string)($xml->identity->name ?? ''),
'org' => (string)($xml->identity->org ?? ''),
'description' => (string)($xml->identity->description ?? ''),
'license' => (string)($xml->identity->license ?? ''),
'license-spdx' => (string)($xml->identity->license['spdx'] ?? ''),
'version' => (string)($xml->identity->version ?? ''),
'platform' => (string)($xml->governance->platform ?? ''),
'standards-version' => (string)($xml->governance->{"standards-version"} ?? ''),
'language' => (string)($xml->build->language ?? ''),
'package-type' => (string)($xml->build->{"package-type"} ?? ''),
'entry-point' => (string)($xml->build->{"entry-point"} ?? ''),
'source-dir' => (string)($xml->deploy->{"source-dir"} ?? ''),
'remote-subdir' => (string)($xml->deploy->{"remote-subdir"} ?? ''),
'dev-host' => (string)($xml->deploy->{"dev-host"} ?? ''),
'demo-host' => (string)($xml->deploy->{"demo-host"} ?? ''),
];
// Strip empty values
$this->fields = array_filter($this->fields, fn($v) => $v !== '');
$this->loaded = true;
}
/**
* Whether a manifest was found and loaded.
*
* @return bool
*/
public function isLoaded(): bool
{
return $this->loaded;
}
/**
* Get a single field value.
*
* @param string $key Field name (e.g. 'platform', 'package-type')
* @param string $default Default value if field is missing
* @return string
*/
public function get(string $key, string $default = ''): string
{
return $this->fields[$key] ?? $default;
}
/**
* Get the platform slug, normalized to canonical values.
*
* @return string One of: joomla, dolibarr, generic, mcp, nodejs
*/
public function getPlatform(): string
{
$raw = $this->get('platform', 'generic');
return match ($raw) {
'waas-component' => 'joomla',
'crm-module' => 'dolibarr',
default => $raw,
};
}
/**
* Get the source/entry-point directory.
*
* Fallback chain: manifest entry-point → source/ → src/ → htdocs/ → 'source'.
* Uses SourceResolver for the directory fallback when no entry-point is set.
*
* @param string $root Repository root for existence checking
* @return string Resolved source directory path (e.g. 'source', 'src', 'htdocs')
*/
public function getSourceDir(string $root = ''): string
{
$entryPoint = $this->get('entry-point', '');
if ($entryPoint !== '') {
// Strip trailing filename (e.g. source/index.ts → source)
$dir = rtrim(dirname($entryPoint) === '.' ? $entryPoint : dirname($entryPoint), '/');
if ($root === '' || is_dir("{$root}/{$dir}")) {
return $dir;
}
}
// Fallback: use SourceResolver (source/ → src/ → htdocs/ → default 'source')
if ($root !== '') {
return SourceResolver::resolve($root);
}
return 'source';
}
/**
* Get the package type for build decisions.
*
* @return string e.g. 'package', 'dolibarr', 'generic', 'mcp-server'
*/
public function getPackageType(): string
{
return $this->get('package-type', 'generic');
}
/**
* Get all parsed fields.
*
* @return array<string, string>
*/
public function getAll(): array
{
return $this->fields;
}
}