Skip to content

Commit

Permalink
[FEATURE] Take outputDir from env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
s2b committed Jul 8, 2024
1 parent 86330c4 commit 7d28e70
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/ConsoleRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
final class ConsoleRunner
{
private const OUTPUT_DIR = './fluidDocumentationOutput/';
private const DEFAULT_OUTPUT_DIR = './fluidDocumentationOutput';
private const SCHEMA_FILE = __DIR__ . '/Config.schema.json';
private const DEFAULT_TEMPLATES = [
'root' => __DIR__ . '/../templates/typo3/Root.rst',
Expand Down Expand Up @@ -173,7 +173,7 @@ public function handleGenerateCommand(array $configFiles, ClassLoader $autoloade
}

// Write JSON file with ViewHelper definitions
$this->writeFile(self::OUTPUT_DIR . $package->name . '.json', json_encode($package, JSON_THROW_ON_ERROR));
$this->writeFile($this->getOutputDir() . $package->name . '.json', json_encode($package, JSON_THROW_ON_ERROR));
}

$this->renderRootDocumentation($packages);
Expand Down Expand Up @@ -201,7 +201,7 @@ private function renderViewHelperDocumentation(ViewHelperPackage $package, ViewH
'sourceEdit' => isset($sourceEdit->editPrefix) ? $sourceEdit->editPrefix . str_replace('\\', '/', $viewHelper->metadata->name) . '.php' : '',
'jsonFile' => str_repeat('../', substr_count($viewHelper->uri, '/')) . $package->name . '.json',
]);
$this->writeFile(self::OUTPUT_DIR . $viewHelper->uri . '.rst', $view->render());
$this->writeFile($this->getOutputDir() . $viewHelper->uri . '.rst', $view->render());
}

/**
Expand All @@ -219,7 +219,7 @@ private function renderGroupDocumentation(
'tocTree' => array_map(fn($viewHelper) => $pathToRoot . $viewHelper->uri, $viewHelpers),
'headline' => $headline,
]);
$this->writeFile(self::OUTPUT_DIR . $uri . '.rst', $view->render());
$this->writeFile($this->getOutputDir() . $uri . '.rst', $view->render());
}

/**
Expand All @@ -234,7 +234,7 @@ private function renderRootDocumentation(array $packages): void

$view = $this->createView($firstPackage->templates['root']);
$view->assign('tocTree', array_map(fn($package) => $package->uri, $packages));
$this->writeFile(self::OUTPUT_DIR . 'Index.rst', $view->render());
$this->writeFile($this->getOutputDir() . 'Index.rst', $view->render());
}

private function createView(string $templateFile): TemplateView
Expand All @@ -256,11 +256,11 @@ private function writeFile(string $filePath, string $content): void

public function cleanupOutputDir(): void
{
if (!file_exists(self::OUTPUT_DIR)) {
if (!file_exists($this->getOutputDir())) {
return;
}

$di = new RecursiveDirectoryIterator(self::OUTPUT_DIR, FilesystemIterator::SKIP_DOTS);
$di = new RecursiveDirectoryIterator($this->getOutputDir(), FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($ri as $file) {
// Make phpstan happy
Expand All @@ -276,6 +276,11 @@ public function cleanupOutputDir(): void
}
}

public function getOutputDir(): string
{
return rtrim((string)(getenv('FLUID_DOCUMENTATION_OUTPUT_DIR') ?: self::DEFAULT_OUTPUT_DIR), '/') . '/';
}

private function createPackageFromConfigFile(string $filePath): ViewHelperPackage
{
// Read file
Expand Down

0 comments on commit 7d28e70

Please sign in to comment.