|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the TYPO3 project - inspiring people to share! |
| 7 | + * (c) 2020-2023 Oliver Bartsch, Benni Mack & Elias Häußler |
| 8 | + * |
| 9 | + * For the full copyright and license information, please view |
| 10 | + * the LICENSE file that was distributed with this source code. |
| 11 | + */ |
| 12 | + |
| 13 | +namespace TYPO3\Tailor\Command\Extension; |
| 14 | + |
| 15 | +use Symfony\Component\Console\Command\Command; |
| 16 | +use Symfony\Component\Console\Input\InputArgument; |
| 17 | +use Symfony\Component\Console\Input\InputInterface; |
| 18 | +use Symfony\Component\Console\Input\InputOption; |
| 19 | +use Symfony\Component\Console\Output\OutputInterface; |
| 20 | +use Symfony\Component\Console\Style\SymfonyStyle; |
| 21 | +use TYPO3\Tailor\Filesystem; |
| 22 | +use TYPO3\Tailor\Helper\CommandHelper; |
| 23 | +use TYPO3\Tailor\Service\VersionService; |
| 24 | + |
| 25 | +/** |
| 26 | + * Command to create a local extension artefact (zip archive). |
| 27 | + */ |
| 28 | +class CreateExtensionArtefactCommand extends Command |
| 29 | +{ |
| 30 | + protected function configure(): void |
| 31 | + { |
| 32 | + $this->setDescription('Create an artefact file (zip archive) of an extension'); |
| 33 | + |
| 34 | + $this->addArgument( |
| 35 | + 'version', |
| 36 | + InputArgument::REQUIRED, |
| 37 | + 'The version of the extension, e.g. 1.2.3' |
| 38 | + ); |
| 39 | + $this->addArgument( |
| 40 | + 'extensionkey', |
| 41 | + InputArgument::OPTIONAL, |
| 42 | + 'The extension key' |
| 43 | + ); |
| 44 | + $this->addOption( |
| 45 | + 'path', |
| 46 | + null, |
| 47 | + InputOption::VALUE_REQUIRED, |
| 48 | + 'Path to the extension folder' |
| 49 | + ); |
| 50 | + $this->addOption( |
| 51 | + 'artefact', |
| 52 | + null, |
| 53 | + InputOption::VALUE_REQUIRED, |
| 54 | + 'Path or URL to a zip file' |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 59 | + { |
| 60 | + $io = new SymfonyStyle($input, $output); |
| 61 | + |
| 62 | + $version = $input->getArgument('version'); |
| 63 | + $extensionKey = CommandHelper::getExtensionKeyFromInput($input); |
| 64 | + $path = $input->getOption('path'); |
| 65 | + $artefact = $input->getOption('artefact'); |
| 66 | + $transactionPath = rtrim(realpath(getcwd() ?: './'), '/') . '/tailor-version-artefact'; |
| 67 | + |
| 68 | + if (!(new Filesystem\Directory())->create($transactionPath)) { |
| 69 | + throw new \RuntimeException(sprintf('Directory could not be created: %s', $transactionPath)); |
| 70 | + } |
| 71 | + |
| 72 | + $versionService = new VersionService($version, $extensionKey, $transactionPath); |
| 73 | + |
| 74 | + if ($path !== null) { |
| 75 | + $versionService->createZipArchiveFromPath($path); |
| 76 | + } elseif ($artefact !== null) { |
| 77 | + $versionService->createZipArchiveFromArtefact($artefact); |
| 78 | + } else { |
| 79 | + // If neither `path` nor `artefact` are defined, we just |
| 80 | + // create the ZipArchive from the current directory. |
| 81 | + $versionService->createZipArchiveFromPath(getcwd() ?: './'); |
| 82 | + } |
| 83 | + |
| 84 | + $io->success(sprintf('Extension artefact successfully generated: %s', $versionService->getVersionFilePath())); |
| 85 | + |
| 86 | + return 0; |
| 87 | + } |
| 88 | +} |
0 commit comments