Files
composer-package-plugin/src/Command/PackageBuildCommand.php

72 lines
2.6 KiB
PHP
Raw Normal View History

2025-12-28 02:28:35 +01:00
<?php
namespace NoccyLabs\Composer\PackagePlugin\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Composer\Command\BaseCommand;
2025-12-28 15:26:33 +01:00
use NoccyLabs\Composer\PackagePlugin\Package\PackageBuilder;
use NoccyLabs\Composer\PackagePlugin\Package\PackagePublisher;
use NoccyLabs\Composer\PackagePlugin\Project\ProjectInfo;
use NoccyLabs\Composer\PackagePlugin\Registry\Credentials\InsecureStore;
use NoccyLabs\Composer\PackagePlugin\Registry\Gitea\GiteaProvider;
use NoccyLabs\Composer\PackagePlugin\Registry\RegistryFactory;
use Symfony\Component\Console\Input\InputOption;
2025-12-28 02:28:35 +01:00
2025-12-28 02:30:24 +01:00
class PackageBuildCommand extends BaseCommand
2025-12-28 02:28:35 +01:00
{
protected function configure(): void
{
$this
2025-12-28 02:30:24 +01:00
->setName('package:build')
->setAliases([ "package" ])
2025-12-28 15:26:33 +01:00
->setDescription("Package the library into a zipball, or publish directly")
->addOption("publish", null, InputOption::VALUE_REQUIRED, "Publish to registry immediately after building")
->addOption("dirty", null, InputOption::VALUE_NONE, "Build directly from source without cloning")
->addOption("force", null, InputOption::VALUE_NONE, "Build even if the output file already exists")
;
2025-12-28 02:28:35 +01:00
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
2025-12-28 15:26:33 +01:00
$registry = $input->getOption("publish");
$builder = new PackageBuilder($output);
$project = ProjectInfo::read();
if ($registry && file_exists($project->filename)) {
$output->writeln("<fg=black;bg=yellow>Package file already exists. Pass --force to rebuild it.</>");
} else {
$builder->build($project, $input->getOption("force"));
}
if ($registry) {
$credentials = new InsecureStore();
$providers = [
'gitea' => new GiteaProvider($credentials)
];
$factory = new RegistryFactory($providers);
$publisher = new PackagePublisher($factory, $output);
if (!$registry) {
$output->writeln([
"Missing registry to publish to. Please specify the registry like this:",
"",
" <info>gitea:<server></> - to publish to <info>server</> as the default user",
" <info>gitea:<server>/<owner></> - to publish to <info>server</> as <info>owner</>",
""
]);
return self::INVALID;
}
$publisher->publish($project, $registry);
}
2025-12-28 02:28:35 +01:00
return 0;
}
}