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;
|
2026-01-09 16:53:33 +01:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
2025-12-28 15:26:33 +01:00
|
|
|
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")
|
2026-01-09 16:19:53 +01:00
|
|
|
->addOption("rm", null, InputOption::VALUE_NONE, "With --publish: remove the .zip after publishing")
|
2025-12-28 15:26:33 +01:00
|
|
|
->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")
|
2026-01-09 16:53:33 +01:00
|
|
|
->addArgument("version", InputArgument::OPTIONAL, "The tag to build (default is latest tag)")
|
2025-12-28 15:26:33 +01:00
|
|
|
;
|
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");
|
|
|
|
|
|
2026-01-09 16:53:33 +01:00
|
|
|
$version = $input->getArgument("version");
|
2026-01-09 16:57:41 +01:00
|
|
|
$force = $input->getOption("force");
|
|
|
|
|
|
|
|
|
|
$builder = new PackageBuilder($output);
|
2026-01-09 16:53:33 +01:00
|
|
|
|
|
|
|
|
$project = ProjectInfo::read(version:$version);
|
2025-12-28 15:26:33 +01:00
|
|
|
|
2026-01-09 16:57:41 +01:00
|
|
|
if (file_exists($project->filename) && !$force) {
|
2025-12-28 15:26:33 +01:00
|
|
|
$output->writeln("<fg=black;bg=yellow>Package file already exists. Pass --force to rebuild it.</>");
|
|
|
|
|
} else {
|
2026-01-09 16:57:41 +01:00
|
|
|
$builder->build($project, $input->getOption("dirty"), $force);
|
2025-12-28 15:26:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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:",
|
|
|
|
|
"",
|
2026-01-09 16:19:53 +01:00
|
|
|
" <info>gitea:{server}</> - to publish to <info>server</> as the default user",
|
|
|
|
|
" <info>gitea:{server}:{owner}</> - to publish to <info>server</> as <info>owner</>",
|
2025-12-28 15:26:33 +01:00
|
|
|
""
|
|
|
|
|
]);
|
|
|
|
|
return self::INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$publisher->publish($project, $registry);
|
|
|
|
|
|
2026-01-09 16:19:53 +01:00
|
|
|
if ($input->getOption("rm")) {
|
|
|
|
|
$output->writeln("Unlinking <comment>".$project->filename."</>");
|
|
|
|
|
unlink($project->filename);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-28 15:26:33 +01:00
|
|
|
}
|
2025-12-28 02:28:35 +01:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|