make sure target directory exists

This commit is contained in:
2019-06-01 12:22:47 +02:00
parent 8779cdaafa
commit 87b7835b56

View File

@@ -214,9 +214,6 @@ class TemplateService
*/
public function render(string $template, DataCollectorInterface $data, string $destDir): string
{
if (!is_dir($destDir)) {
mkdir($destDir, 0755, true);
}
$vars = $data->getData();
$name = isset($vars['name']) ? $vars['name'] : $this->docname;
$name .= isset($vars['theme']) ? '.'.$vars['theme'] : '';
@@ -224,6 +221,10 @@ class TemplateService
$html = $this->twig->render($template, $vars);
$html = $this->minifier->minify($html);
if (!is_dir(dirname($path))) {
mkdir(dirname($path), 0755, true);
}
if (!file_put_contents($path, $html)) {
throw new \RuntimeException('Error writing output file: '.$path);
}