mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-06 16:25:39 +08:00
Add GUIDE section for v3 docs
This commit is contained in:
87
src/StaticPHP/Command/Dev/GenExtDocsCommand.php
Normal file
87
src/StaticPHP/Command/Dev/GenExtDocsCommand.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Command\Dev;
|
||||
|
||||
use StaticPHP\Command\BaseCommand;
|
||||
use StaticPHP\Config\PackageConfig;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
#[AsCommand('dev:gen-ext-docs', 'Generate extension list JSON for documentation', [], true)]
|
||||
class GenExtDocsCommand extends BaseCommand
|
||||
{
|
||||
protected bool $no_motd = true;
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
if (!spc_mode(SPC_MODE_SOURCE)) {
|
||||
$this->output->writeln('<error>This command is only available in source mode.</error>');
|
||||
return static::USER_ERROR;
|
||||
}
|
||||
|
||||
$all = PackageConfig::getAll();
|
||||
$extensions = [];
|
||||
|
||||
foreach ($all as $pkg_name => $config) {
|
||||
if (($config['type'] ?? '') !== 'php-extension') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Strip ext- prefix for display name
|
||||
$name = str_starts_with($pkg_name, 'ext-') ? substr($pkg_name, 4) : $pkg_name;
|
||||
|
||||
// Determine OS support from php-extension.os field.
|
||||
// If the field is absent, the extension supports all three OSes.
|
||||
$os_list = $config['php-extension']['os'] ?? null;
|
||||
if ($os_list === null) {
|
||||
$linux = true;
|
||||
$macos = true;
|
||||
$windows = true;
|
||||
} else {
|
||||
$linux = in_array('Linux', $os_list, true);
|
||||
$macos = in_array('Darwin', $os_list, true);
|
||||
$windows = in_array('Windows', $os_list, true);
|
||||
}
|
||||
|
||||
$extensions[] = [
|
||||
'name' => $name,
|
||||
'linux' => $linux,
|
||||
'macos' => $macos,
|
||||
'windows' => $windows,
|
||||
'url' => $this->resolveSourceUrl($config, $name),
|
||||
];
|
||||
}
|
||||
|
||||
// Sort alphabetically by name
|
||||
usort($extensions, fn ($a, $b) => strcmp($a['name'], $b['name']));
|
||||
|
||||
$output = [
|
||||
'generated_at' => date('c'),
|
||||
'extensions' => $extensions,
|
||||
];
|
||||
|
||||
$output_path = ROOT_DIR . '/docs/.vitepress/ext-data.json';
|
||||
file_put_contents($output_path, json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);
|
||||
|
||||
$this->output->writeln("<info>Generated {$output_path} with " . count($extensions) . ' extensions.</info>');
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
private function resolveSourceUrl(array $config, string $ext_name): ?string
|
||||
{
|
||||
$source = $config['artifact']['source'] ?? null;
|
||||
if ($source === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return match ($source['type'] ?? '') {
|
||||
'pecl' => 'https://pecl.php.net/package/' . ($source['name'] ?? $ext_name),
|
||||
'git' => rtrim($source['url'] ?? '', '/'),
|
||||
'ghtar', 'ghrel', 'ghtagtar', 'pie' => isset($source['repo'])
|
||||
? 'https://github.com/' . $source['repo']
|
||||
: null,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ class SPCConfigCommand extends BaseCommand
|
||||
{
|
||||
$this->addArgument('extensions', InputArgument::OPTIONAL, 'The extensions will be compiled, comma separated');
|
||||
$this->addOption('with-libs', null, InputOption::VALUE_REQUIRED, 'add additional libraries, comma separated', '');
|
||||
$this->addOption('with-packages', null, InputOption::VALUE_REQUIRED, 'add additional libraries, comma separated', '');
|
||||
$this->addOption('with-packages', 'p', InputOption::VALUE_REQUIRED, 'add additional libraries, comma separated', '');
|
||||
$this->addOption('with-suggested-libs', 'L', null, 'Build with suggested libs for selected exts and libs');
|
||||
$this->addOption('with-suggests', null, null, 'Build with suggested packages for selected exts and libs');
|
||||
$this->addOption('with-suggested-exts', 'E', null, 'Build with suggested extensions for selected exts');
|
||||
|
||||
@@ -11,6 +11,7 @@ use StaticPHP\Command\CraftCommand;
|
||||
use StaticPHP\Command\Dev\DumpCapabilitiesCommand;
|
||||
use StaticPHP\Command\Dev\DumpStagesCommand;
|
||||
use StaticPHP\Command\Dev\EnvCommand;
|
||||
use StaticPHP\Command\Dev\GenExtDocsCommand;
|
||||
use StaticPHP\Command\Dev\IsInstalledCommand;
|
||||
use StaticPHP\Command\Dev\LintConfigCommand;
|
||||
use StaticPHP\Command\Dev\PackageInfoCommand;
|
||||
@@ -81,6 +82,7 @@ class ConsoleApplication extends Application
|
||||
new DumpStagesCommand(),
|
||||
new DumpCapabilitiesCommand(),
|
||||
new PackageInfoCommand(),
|
||||
new GenExtDocsCommand(),
|
||||
]);
|
||||
|
||||
// add additional commands from registries
|
||||
|
||||
Reference in New Issue
Block a user