Commit e21999c8 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Ajout d'une option à ng-model:generate pour limiter les fichiers générés.

parent 11beadb6
......@@ -23,6 +23,7 @@ use ApiPlatform\Core\Documentation\Documentation;
use Irstea\NgModelGeneratorBundle\ModelGenerator;
use Irstea\NgModelGeneratorBundle\Writers\ConsoleWriter;
use Irstea\NgModelGeneratorBundle\Writers\DirectoryWriter;
use Irstea\NgModelGeneratorBundle\Writers\FilteringFileWriter;
use Irstea\NgModelGeneratorBundle\Writers\MultiFileWriter;
use Irstea\NgModelGeneratorBundle\Writers\PhonyFileWriter;
use Irstea\NgModelGeneratorBundle\Writers\ZipWriter;
......@@ -72,7 +73,8 @@ final class NgModelGenerateCommand extends Command
->setDescription('Dump Typescript representations')
->addOption('zip', 'z', InputOption::VALUE_REQUIRED, 'Archive ZIP à créer')
->addOption('output', 'o', InputOption::VALUE_REQUIRED, 'Dossier de destination')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Ecrase la cible');
->addOption('force', 'f', InputOption::VALUE_NONE, 'Ecrase la cible')
->addOption('restrict', 'r', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Limite la sortie aux modèles de nom de fichier');
}
/**
......@@ -85,6 +87,19 @@ final class NgModelGenerateCommand extends Command
$output
);
if ($input->getOption('restrict')) {
$globs = $input->getOption('restrict');
$writer = new FilteringFileWriter($writer, function (string $path) use ($globs): bool {
foreach ($globs as $glob) {
if (fnmatch($glob, $path, FNM_PATHNAME)) {
return true;
}
}
return false;
});
}
try {
$this->generator->generate($this->documentation, $writer);
} finally {
......
<?php declare(strict_types=1);
/*
* irstea/ng-model-generator-bundle generates Typescript interfaces for Angular using api-platform metadata.
* Copyright (C) 2018 IRSTEA
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License and the GNU
* Lesser General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
namespace Irstea\NgModelGeneratorBundle\Writers;
/**
* Class FilteringFileWriter.
*/
final class FilteringFileWriter implements MultiFileWriter
{
/**
* @var MultiFileWriter
*/
private $writer;
/**
* @var callable
*/
private $accept;
/**
* FilteringFileWriter constructor.
*
* @param MultiFileWriter $writer
* @param callable $accept
*/
public function __construct(MultiFileWriter $writer, callable $accept)
{
$this->writer = $writer;
$this->accept = $accept;
}
/**
* {@inheritdoc}
*/
public function newFile(string $path): Writer
{
if (!($this->accept)($path)) {
return new NullWriter();
}
return $this->writer->newFile($path);
}
public function close(): void
{
$this->writer->close();
}
}
<?php declare(strict_types=1);
/*
* irstea/ng-model-generator-bundle generates Typescript interfaces for Angular using api-platform metadata.
* Copyright (C) 2018 IRSTEA
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License and the GNU
* Lesser General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
namespace Irstea\NgModelGeneratorBundle\Writers;
/**
* Class NullWriter.
*/
class NullWriter implements MultiFileWriter, Writer
{
/**
* {@inheritdoc}
*/
public function newFile(string $path): Writer
{
return $this;
}
public function close(): void
{
}
/**
* {@inheritdoc}
*/
public function write(string $data): void
{
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment