Browse Source

Sauvons du CO2 : ne pas repasser par phpdocumentor, si la doc existante est déjà sur le même commit. Sauf si option --force

master
Matthieu Marcillaud 9 months ago
parent
commit
4c1dadb956
  1. 2
      src/Command/FromDirectory.php
  2. 4
      src/Command/FromFile.php
  3. 4
      src/Command/FromGit.php
  4. 4
      src/Command/FromSpip.php
  5. 44
      src/Stage/AlreadyUpStage.php
  6. 2
      src/Stage/GitStage.php

2
src/Command/FromDirectory.php

@ -66,7 +66,7 @@ class FromDirectory extends Command
protected function pipeline(Context $context): void
{
$processor = new InterruptibleProcessor(fn (Context $context) => $context->empty('errors'));
$processor = new InterruptibleProcessor(fn (Context $context) => $context->empty('errors') and $context->empty('break'));
$pipeline = (new Pipeline($processor))
->pipe(new CheckStage())
->pipe(new PackageStage())

4
src/Command/FromFile.php

@ -12,6 +12,7 @@ use Spip\Autodoc\AutodocFile;
use Spip\Autodoc\Context;
use Spip\Autodoc\Exception\AutodocException;
use Spip\Autodoc\Git;
use Spip\Autodoc\Stage\AlreadyUpStage;
use Spip\Autodoc\Stage\CheckStage;
use Spip\Autodoc\Stage\GitStage;
use Spip\Autodoc\Stage\IndexStage;
@ -107,11 +108,12 @@ https://git.spip.net/spip-contrib-extensions/champs_extras_core@master;cextras
protected function pipeline(Context $context): void
{
$processor = new InterruptibleProcessor(fn (Context $context) => $context->empty('errors'));
$processor = new InterruptibleProcessor(fn (Context $context) => $context->empty('errors') and $context->empty('break'));
$pipeline = (new Pipeline($processor))
->pipe(new CheckStage())
->pipe(new GitStage())
->pipe(new PackageStage())
->pipe(new AlreadyUpStage())
->pipe(new PhpDocumentorConfigStage())
->pipe(new PhpDocumentorStage())
->pipe(new JsonAutodocStage());

4
src/Command/FromGit.php

@ -11,6 +11,7 @@ use League\Pipeline\Pipeline;
use Spip\Autodoc\Context;
use Spip\Autodoc\Exception\AutodocException;
use Spip\Autodoc\Git;
use Spip\Autodoc\Stage\AlreadyUpStage;
use Spip\Autodoc\Stage\CheckStage;
use Spip\Autodoc\Stage\GitStage;
use Spip\Autodoc\Stage\JsonAutodocStage;
@ -82,11 +83,12 @@ class FromGit extends Command
protected function pipeline(Context $context): void
{
$processor = new InterruptibleProcessor(fn (Context $context) => $context->empty('errors'));
$processor = new InterruptibleProcessor(fn (Context $context) => $context->empty('errors') and $context->empty('break'));
$pipeline = (new Pipeline($processor))
->pipe(new CheckStage())
->pipe(new GitStage())
->pipe(new PackageStage())
->pipe(new AlreadyUpStage())
->pipe(new PhpDocumentorConfigStage())
->pipe(new PhpDocumentorStage())
->pipe(new JsonAutodocStage());

4
src/Command/FromSpip.php

@ -9,6 +9,7 @@ namespace Spip\Autodoc\Command;
use League\Pipeline\InterruptibleProcessor;
use League\Pipeline\Pipeline;
use Spip\Autodoc\Context;
use Spip\Autodoc\Stage\AlreadyUpStage;
use Spip\Autodoc\Stage\CheckStage;
use Spip\Autodoc\Stage\GitSpipStage;
use Spip\Autodoc\Stage\GitStage;
@ -56,11 +57,12 @@ class FromSpip extends FromGit
$context->io->info("Generate SPIP without plugins dist.");
$gitStage = new GitStage();
}
$processor = new InterruptibleProcessor(fn (Context $context) => $context->empty('errors'));
$processor = new InterruptibleProcessor(fn (Context $context) => $context->empty('errors') and $context->empty('break'));
$pipeline = (new Pipeline($processor))
->pipe(new CheckStage())
->pipe($gitStage)
->pipe(new PackageStage())
->pipe(new AlreadyUpStage())
->pipe(new PhpDocumentorConfigStage())
->pipe(new PhpDocumentorStage())
->pipe(new JsonAutodocStage());

44
src/Stage/AlreadyUpStage.php

@ -0,0 +1,44 @@
<?php
namespace Spip\Autodoc\Stage;
use Spip\Autodoc\Context;
use Spip\Autodoc\Exception\ContextException;
/**
* Si la révision Git de l’input correspond à celle de l’output,
* c’est que la doc a déjà été générée… du coup on quitte…
*/
class AlreadyUpStage implements StageInterface
{
public function __invoke(Context $context): Context
{
if (!in_array(PackageStage::class, $context->get('stages'))) {
throw new ContextException(sprintf('Stage "%s" needs to be done after stage "%s".', 'AlreadyUpStage', 'PackageStage'));
}
if (
$context->empty('git')
or $context->phpdocumentor->options->force
) {
return $context;
}
$package = $context->get('package');
$prefix = $package->get('prefix') ?: $context->get('default_prefix');
if ($context->directory->empty('output')) {
$context->directory->set('output', $context->directory->output_base . '/' . $prefix);
}
$autodoc_json = $context->directory->output . '/autodoc.json';
if (file_exists($autodoc_json)) {
$json = json_decode(file_get_contents($autodoc_json));
if ($context->git->getCommit() === $json->revision) {
$context->io->text(sprintf('* Existing documentation is already on commit <info>%s</info>. We do not regenerate it.', $json->revision));
$context->set('break', true);
}
}
return $context;
}
}

2
src/Stage/GitStage.php

@ -27,6 +27,8 @@ class GitStage implements StageInterface
$git = $this->download($context);
$context->set('git', $git);
return $context;
}

Loading…
Cancel
Save