Skip to content

Commit b2b1782

Browse files
committed
Add MetaFileBuilderCommand
1 parent c0fdce1 commit b2b1782

5 files changed

Lines changed: 679 additions & 332 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace DevTools\Command;
4+
5+
use DevTools\Writers\MetaDataWriter;
6+
use MetaDataTool\DocumentationCrawler;
7+
use Symfony\Component\Console\Command\Command;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Input\InputOption;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
use Symfony\Component\Filesystem\Filesystem;
12+
13+
class MetaFileBuilderCommand extends Command
14+
{
15+
protected static $defaultName = 'build-meta-file';
16+
17+
protected function configure(): void
18+
{
19+
$this
20+
->setDescription('Build the meta file based on the Exact Online API documentation')
21+
->setHelp(<<<'HELP'
22+
This command scans the Exact Online API documentation and stores the meta data discovered
23+
from the documentation.
24+
HELP
25+
)
26+
->setDefinition([
27+
new InputOption('destination', 'd', InputOption::VALUE_REQUIRED, 'The destination directory', getcwd()),
28+
]);
29+
}
30+
31+
protected function execute(InputInterface $input, OutputInterface $output): int
32+
{
33+
/* @todo add caching support */
34+
$endpoints = (new DocumentationCrawler())->run();
35+
36+
$writer = new MetaDataWriter(
37+
$this->getFullDestinationPath($input->getOption('destination')),
38+
new Filesystem()
39+
);
40+
41+
$writer->write($endpoints);
42+
43+
return 0;
44+
}
45+
46+
private function getFullDestinationPath(string $destination): string
47+
{
48+
if (strpos($destination, DIRECTORY_SEPARATOR) === 0) {
49+
return $destination;
50+
}
51+
52+
return getcwd() . DIRECTORY_SEPARATOR . $destination;
53+
}
54+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace DevTools\Writers;
4+
5+
use DevTools\MetaDataHelper;
6+
use MetaDataTool\ValueObjects\Endpoint;
7+
use MetaDataTool\ValueObjects\EndpointCollection;
8+
use Symfony\Component\Filesystem\Filesystem;
9+
use Twig\Environment;
10+
11+
class MetaDataWriter
12+
{
13+
/** @var string */
14+
private $basePath;
15+
/** @var Filesystem */
16+
private $filesystem;
17+
18+
public function __construct(
19+
string $basePath,
20+
Filesystem $filesystem
21+
) {
22+
$this->basePath = $basePath;
23+
$this->filesystem = $filesystem;
24+
}
25+
26+
public function write(EndpointCollection $endpointCollection): void
27+
{
28+
$metaData = [];
29+
30+
/** @var Endpoint $endpoint */
31+
foreach ($endpointCollection as $endpoint) {
32+
$metaData[$endpoint->getEndpoint()] = $endpoint;
33+
}
34+
35+
$content = json_encode($metaData, JSON_PRETTY_PRINT);
36+
$filename = $this->basePath . '/meta-data.json';
37+
38+
$this->filesystem->dumpFile($filename, $content);
39+
}
40+
41+
}

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"minimum-stability": "stable",
1212
"prefer-stable": true,
1313
"require": {
14+
"php": "^7.1",
15+
"ext-json": "*",
1416
"dannyvandersluijs/exact-online-meta-data-tool": "^1.0",
1517
"symfony/console": "^4.3",
1618
"symfony/filesystem": "^4.3",
@@ -37,7 +39,8 @@
3739
"phpcs": ["./vendor/bin/phpcs --standard=PSR2 DevTools template application.php"],
3840
"phpcbf": ["./vendor/bin/phpcbf --standard=PSR2 DevTools template application.php"],
3941
"phpstan": "./vendor/bin/phpstan analyse",
40-
"build-entities": ["./exact-online-api-client-dev-tools build-entities --destination entities"]
42+
"build-entities": ["./exact-online-api-client-dev-tools build-entities --destination entities"],
43+
"build-meta-data": ["./exact-online-api-client-dev-tools build-meta-file"]
4144
},
4245
"bin": [
4346
"exact-online-api-client-dev-tools"

0 commit comments

Comments
 (0)