Skip to content

Commit 0bcff64

Browse files
committed
Fix mjml binary finder
1 parent 41c7214 commit 0bcff64

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/Mjml.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,25 @@ protected function checkForDeprecationWarning(string $result): string
141141
return $result;
142142
}
143143

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

149-
if (! $mjml) {
150-
$tempDir->delete();
151+
$mjmlPathFromEnv = getenv('MJML_PATH');
151152

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

155-
$command = [$mjml, $templatePath, '-o', $outputPath];
157+
$command = [
158+
(new ExecutableFinder)->find('mjml', 'mjml', $extraDirectories),
159+
$templatePath,
160+
'-o',
161+
$outputPath,
162+
];
156163

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

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

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

213220
$process = new Process($command);
214221
$process->run();

0 commit comments

Comments
 (0)