Skip to content

Commit abc60e6

Browse files
committed
remove html and json directories only if cache is disabled
1 parent 16cf554 commit abc60e6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/Command/CommandInitializerTrait.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ trait CommandInitializerTrait
2424
private $io;
2525
/** @var OutputInterface */
2626
private $output;
27+
/** @var InputInterface */
28+
private $input;
2729
/** @var Builder */
2830
private $builder;
2931
/** @var Filesystem */
@@ -40,14 +42,15 @@ trait CommandInitializerTrait
4042
private function doInitialize(InputInterface $input, OutputInterface $output, string $sourceDir, string $outputDir)
4143
{
4244
$this->io = new SymfonyStyle($input, $output);
45+
$this->input = $input;
4346
$this->output = $output;
4447

4548
$this->buildContext->initializeRuntimeConfig(
4649
$sourceDir,
4750
$this->initializeHtmlOutputDir($this->filesystem, $outputDir),
4851
$this->initializeJsonOutputDir($outputDir),
4952
$this->initializeParseSubPath($input, $sourceDir),
50-
(bool) $input->getOption('disable-cache')
53+
$this->isCacheDisabled()
5154
);
5255

5356
$this->builder = new Builder(
@@ -71,7 +74,12 @@ private function initializeSourceDir(InputInterface $input, Filesystem $filesyst
7174

7275
private function initializeHtmlOutputDir(Filesystem $filesystem, string $path): string
7376
{
74-
return rtrim($this->getRealAbsolutePath($path, $filesystem), '/');
77+
$htmlOutputDir = rtrim($this->getRealAbsolutePath($path, $filesystem), '/');
78+
if ($this->isCacheDisabled() && $filesystem->exists($htmlOutputDir)) {
79+
$filesystem->remove($htmlOutputDir);
80+
}
81+
82+
return $htmlOutputDir;
7583
}
7684

7785
private function initializeParseSubPath(InputInterface $input, string $sourceDir): string
@@ -98,7 +106,7 @@ private function initializeParseSubPath(InputInterface $input, string $sourceDir
98106
private function initializeJsonOutputDir(string $outputDir): string
99107
{
100108
$jsonOutputDir = $this->getRealAbsolutePath($outputDir.'/json', $this->filesystem);
101-
if ($this->filesystem->exists($jsonOutputDir)) {
109+
if ($this->isCacheDisabled() && $this->filesystem->exists($jsonOutputDir)) {
102110
$this->filesystem->remove($jsonOutputDir);
103111
}
104112

@@ -144,6 +152,11 @@ private function startBuild()
144152
);
145153
}
146154

155+
private function isCacheDisabled(): bool
156+
{
157+
return (bool) $this->input->getOption('disable-cache');
158+
}
159+
147160
public function postParseDocument(PostParseDocumentEvent $postParseDocumentEvent): void
148161
{
149162
$file = $postParseDocumentEvent->getDocumentNode()->getEnvironment()->getCurrentFileName();

0 commit comments

Comments
 (0)