Skip to content

Commit 410a9f2

Browse files
[FEATURE] Introduce command to create local extension artefact
* [FEATURE] Introduce command to create local extension artefact This commit adds a new `create-artefact` command. It can be used to create a local artefact file (zip archive) of an extension. This is basically the same which is already done in the `ter:publish` command, except for the TER publish part. The new command is especially useful to test custom configurations of package exclude files. In addition, it's a useful helper in cases where the TER REST API might not be accessible. * [TASK] Use different transaction path for `create-artefact` command * [TASK] Include transaction path in exception message * [TASK] Drop AbstractCommand in favor of CommandHelper utility class * [TASK] Use admonitions and create custom section for packaging excludes
1 parent 38dbec4 commit 410a9f2

15 files changed

+382
-97
lines changed

README.md

+143-66
Large diffs are not rendered by default.

bin/tailor

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ foreach ([__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php
3636
$application->add(new Command\Auth\CreateTokenCommand('ter:token:create'));
3737
$application->add(new Command\Auth\RefreshTokenCommand('ter:token:refresh'));
3838
$application->add(new Command\Auth\RevokeTokenCommand('ter:token:revoke'));
39+
$application->add(new Command\Extension\CreateExtensionArtefactCommand('create-artefact'));
3940
$application->add(new Command\Extension\DeleteExtensionCommand('ter:delete'));
4041
$application->add(new Command\Extension\ExtensionDetailsCommand('ter:details'));
4142
$application->add(new Command\Extension\ExtensionVersionsCommand('ter:versions'));

conf/ExcludeFromPackaging.php

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'bin',
2222
'build',
2323
'public',
24+
'tailor-version-artefact',
2425
'tailor-version-upload',
2526
'tests',
2627
'tools',

src/Command/AbstractClientRequestCommand.php

-23
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
use Symfony\Component\Console\Style\SymfonyStyle;
2121
use TYPO3\Tailor\Dto\Messages;
2222
use TYPO3\Tailor\Dto\RequestConfiguration;
23-
use TYPO3\Tailor\Environment\Variables;
24-
use TYPO3\Tailor\Exception\ExtensionKeyMissingException;
25-
use TYPO3\Tailor\Filesystem\ComposerReader;
2623
use TYPO3\Tailor\Formatter\ConsoleFormatter;
2724
use TYPO3\Tailor\HttpClientFactory;
2825
use TYPO3\Tailor\Service\RequestService;
@@ -95,26 +92,6 @@ protected function setConfirmationRequired(bool $confirmationRequired): self
9592
return $this;
9693
}
9794

98-
protected function getExtensionKey(InputInterface $input): string
99-
{
100-
if ($input->hasArgument('extensionkey')
101-
&& ($key = ($input->getArgument('extensionkey') ?? '')) !== ''
102-
) {
103-
$extensionKey = $key;
104-
} elseif (Variables::has('TYPO3_EXTENSION_KEY')) {
105-
$extensionKey = Variables::get('TYPO3_EXTENSION_KEY');
106-
} elseif (($extensionKeyFromComposer = (new ComposerReader())->getExtensionKey()) !== '') {
107-
$extensionKey = $extensionKeyFromComposer;
108-
} else {
109-
throw new ExtensionKeyMissingException(
110-
'The extension key must either be set as argument, as environment variable or in the composer.json.',
111-
1605706548
112-
);
113-
}
114-
115-
return $extensionKey;
116-
}
117-
11895
abstract protected function getRequestConfiguration(): RequestConfiguration;
11996
abstract protected function getMessages(): Messages;
12097
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
}

src/Command/Extension/DeleteExtensionCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use TYPO3\Tailor\Dto\Messages;
2020
use TYPO3\Tailor\Dto\RequestConfiguration;
2121
use TYPO3\Tailor\Formatter\ConsoleFormatter;
22+
use TYPO3\Tailor\Helper\CommandHelper;
2223

2324
/**
2425
* Command for TER REST endpoint `DELETE /extension/{key}`
@@ -40,7 +41,7 @@ protected function configure(): void
4041

4142
protected function execute(InputInterface $input, OutputInterface $output): int
4243
{
43-
$this->extensionKey = $this->getExtensionKey($input);
44+
$this->extensionKey = CommandHelper::getExtensionKeyFromInput($input);
4445
return parent::execute($input, $output);
4546
}
4647

src/Command/Extension/ExtensionDetailsCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use TYPO3\Tailor\Dto\Messages;
2020
use TYPO3\Tailor\Dto\RequestConfiguration;
2121
use TYPO3\Tailor\Formatter\ConsoleFormatter;
22+
use TYPO3\Tailor\Helper\CommandHelper;
2223

2324
/**
2425
* Command for TER REST endpoint `GET /extension/{key}`
@@ -39,7 +40,7 @@ protected function configure(): void
3940

4041
protected function execute(InputInterface $input, OutputInterface $output): int
4142
{
42-
$this->extensionKey = $this->getExtensionKey($input);
43+
$this->extensionKey = CommandHelper::getExtensionKeyFromInput($input);
4344
return parent::execute($input, $output);
4445
}
4546

src/Command/Extension/ExtensionVersionsCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use TYPO3\Tailor\Dto\Messages;
2020
use TYPO3\Tailor\Dto\RequestConfiguration;
2121
use TYPO3\Tailor\Formatter\ConsoleFormatter;
22+
use TYPO3\Tailor\Helper\CommandHelper;
2223

2324
/**
2425
* Command for TER REST endpoint `GET /extension/{key}/versions`
@@ -39,7 +40,7 @@ protected function configure(): void
3940

4041
protected function execute(InputInterface $input, OutputInterface $output): int
4142
{
42-
$this->extensionKey = $this->getExtensionKey($input);
43+
$this->extensionKey = CommandHelper::getExtensionKeyFromInput($input);
4344
// @todo the response format needs to be adjusted!
4445
return parent::execute($input, $output);
4546
}

src/Command/Extension/RegisterExtensionCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use TYPO3\Tailor\Command\AbstractClientRequestCommand;
1919
use TYPO3\Tailor\Dto\Messages;
2020
use TYPO3\Tailor\Dto\RequestConfiguration;
21+
use TYPO3\Tailor\Helper\CommandHelper;
2122

2223
/**
2324
* Command for TER REST endpoint `POST /extension/{key}`
@@ -37,7 +38,7 @@ protected function configure(): void
3738

3839
protected function execute(InputInterface $input, OutputInterface $output): int
3940
{
40-
$this->extensionKey = $this->getExtensionKey($input);
41+
$this->extensionKey = CommandHelper::getExtensionKeyFromInput($input);
4142
return parent::execute($input, $output);
4243
}
4344

src/Command/Extension/TransferExtensionCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use TYPO3\Tailor\Command\AbstractClientRequestCommand;
1919
use TYPO3\Tailor\Dto\Messages;
2020
use TYPO3\Tailor\Dto\RequestConfiguration;
21+
use TYPO3\Tailor\Helper\CommandHelper;
2122

2223
/**
2324
* Command for TER REST endpoint `POST /extension/{key}/transfer/{username}`
@@ -43,7 +44,7 @@ protected function configure(): void
4344
protected function execute(InputInterface $input, OutputInterface $output): int
4445
{
4546
$this->username = $input->getArgument('username');
46-
$this->extensionKey = $this->getExtensionKey($input);
47+
$this->extensionKey = CommandHelper::getExtensionKeyFromInput($input);
4748
return parent::execute($input, $output);
4849
}
4950

src/Command/Extension/UpdateExtensionCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use TYPO3\Tailor\Dto\Messages;
2121
use TYPO3\Tailor\Dto\RequestConfiguration;
2222
use TYPO3\Tailor\Formatter\ConsoleFormatter;
23+
use TYPO3\Tailor\Helper\CommandHelper;
2324

2425
/**
2526
* Command for TER REST endpoint `PUT /extension/{key}`
@@ -55,7 +56,7 @@ protected function configure(): void
5556

5657
protected function execute(InputInterface $input, OutputInterface $output): int
5758
{
58-
$this->extensionKey = $this->getExtensionKey($input);
59+
$this->extensionKey = CommandHelper::getExtensionKeyFromInput($input);
5960
return parent::execute($input, $output);
6061
}
6162

src/Command/Extension/UploadExtensionVersionCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use TYPO3\Tailor\Dto\RequestConfiguration;
2424
use TYPO3\Tailor\Filesystem;
2525
use TYPO3\Tailor\Formatter\ConsoleFormatter;
26+
use TYPO3\Tailor\Helper\CommandHelper;
2627
use TYPO3\Tailor\Service\VersionService;
2728

2829
/**
@@ -56,7 +57,7 @@ protected function configure(): void
5657
protected function execute(InputInterface $input, OutputInterface $output): int
5758
{
5859
$this->version = $input->getArgument('version');
59-
$this->extensionKey = $this->getExtensionKey($input);
60+
$this->extensionKey = CommandHelper::getExtensionKeyFromInput($input);
6061
$this->transactionPath = rtrim(realpath(getcwd() ?: './'), '/') . '/tailor-version-upload';
6162

6263
if (!(new Filesystem\Directory())->create($this->transactionPath)) {

src/Command/Extension/VersionDetailsCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use TYPO3\Tailor\Dto\Messages;
2020
use TYPO3\Tailor\Dto\RequestConfiguration;
2121
use TYPO3\Tailor\Formatter\ConsoleFormatter;
22+
use TYPO3\Tailor\Helper\CommandHelper;
2223

2324
/**
2425
* Command for TER REST endpoint `GET /extension/{key}/{version}`
@@ -44,7 +45,7 @@ protected function configure(): void
4445
protected function execute(InputInterface $input, OutputInterface $output): int
4546
{
4647
$this->version = $input->getArgument('version');
47-
$this->extensionKey = $this->getExtensionKey($input);
48+
$this->extensionKey = CommandHelper::getExtensionKeyFromInput($input);
4849
return parent::execute($input, $output);
4950
}
5051

src/Helper/CommandHelper.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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-2024 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\Helper;
14+
15+
use Symfony\Component\Console\Input\InputInterface;
16+
use TYPO3\Tailor\Environment\Variables;
17+
use TYPO3\Tailor\Exception\ExtensionKeyMissingException;
18+
use TYPO3\Tailor\Filesystem\ComposerReader;
19+
20+
/**
21+
* Helper class for console commands.
22+
*/
23+
final class CommandHelper
24+
{
25+
public static function getExtensionKeyFromInput(InputInterface $input): string
26+
{
27+
if ($input->hasArgument('extensionkey')
28+
&& ($key = ($input->getArgument('extensionkey') ?? '')) !== ''
29+
) {
30+
$extensionKey = $key;
31+
} elseif (Variables::has('TYPO3_EXTENSION_KEY')) {
32+
$extensionKey = Variables::get('TYPO3_EXTENSION_KEY');
33+
} elseif (($extensionKeyFromComposer = (new ComposerReader())->getExtensionKey()) !== '') {
34+
$extensionKey = $extensionKeyFromComposer;
35+
} else {
36+
throw new ExtensionKeyMissingException(
37+
'The extension key must either be set as argument, as environment variable or in the composer.json.',
38+
1605706548
39+
);
40+
}
41+
42+
return $extensionKey;
43+
}
44+
}

0 commit comments

Comments
 (0)