Skip to content

Commit

Permalink
Fix mjml binary finder
Browse files Browse the repository at this point in the history
  • Loading branch information
riasvdv committed Jan 3, 2025
1 parent 41c7214 commit 0bcff64
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/Mjml.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,25 @@ protected function checkForDeprecationWarning(string $result): string
return $result;
}

public function getCommand(TemporaryDirectory $tempDir, string $templatePath, string $outputPath, $arguments): array
public function getCommand(string $templatePath, string $outputPath, $arguments): array
{
$executableFinder = new ExecutableFinder;
$mjml = $executableFinder->find('mjml');
$extraDirectories = [
'/usr/local/bin',
'/opt/homebrew/bin',
];

if (! $mjml) {
$tempDir->delete();
$mjmlPathFromEnv = getenv('MJML_PATH');

throw CouldNotConvertMjml::make('No MJML binary found. Make sure it is installed on your system.');
if ($mjmlPathFromEnv) {
array_unshift($extraDirectories, $mjmlPathFromEnv);
}

$command = [$mjml, $templatePath, '-o', $outputPath];
$command = [
(new ExecutableFinder)->find('mjml', 'mjml', $extraDirectories),
$templatePath,
'-o',
$outputPath,
];

foreach ($arguments as $configKey => $configValue) {
$command[] = "-c.{$configKey}";
Expand Down Expand Up @@ -208,7 +215,7 @@ protected function getLocalResult(array $arguments): MjmlResult

$outputPath = $tempDir->path("{$filename}.html");

$command = $this->getCommand($tempDir, $templatePath, $outputPath, $arguments[1]);
$command = $this->getCommand($templatePath, $outputPath, $arguments[1]);

$process = new Process($command);
$process->run();
Expand Down

0 comments on commit 0bcff64

Please sign in to comment.