Skip to content

Commit ed1e4ac

Browse files
committed
fix: refactor build and watch commands for better execution
1 parent 1990971 commit ed1e4ac

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

src/Service/ThemeBuilder/HyvaThemes/Builder.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OpenForgeProject\MageForge\Service\ThemeBuilder\BuilderInterface;
1515
use Symfony\Component\Console\Output\OutputInterface;
1616
use Symfony\Component\Console\Style\SymfonyStyle;
17+
use Symfony\Component\Process\Process;
1718

1819
class Builder implements BuilderInterface
1920
{
@@ -177,29 +178,19 @@ private function buildTheme(string $themePath, SymfonyStyle $io, bool $isVerbose
177178
return false;
178179
}
179180

180-
// Change to tailwind directory and run build
181-
$currentDir = getcwd();
182-
if ($currentDir === false) {
183-
$io->error('Cannot determine current directory');
184-
return false;
185-
}
186-
chdir($tailwindPath);
187-
188181
try {
189182
if ($isVerbose) {
190183
$io->text('Running npm build...');
191184
}
192185
// Use --quiet only in non-verbose mode to suppress routine output
193186
$buildCommand = $isVerbose ? 'npm run build' : 'npm run build --quiet';
194-
$this->shell->execute($buildCommand);
187+
$this->shell->execute('cd %s && ' . $buildCommand, [$tailwindPath]);
195188
if ($isVerbose) {
196189
$io->success('Hyvä theme build completed successfully.');
197190
}
198-
chdir($currentDir);
199191
return true;
200192
} catch (\Exception $e) {
201193
$io->error('Failed to build Hyvä theme: ' . $e->getMessage());
202-
chdir($currentDir);
203194
return false;
204195
}
205196
}
@@ -287,12 +278,12 @@ public function watch(
287278
$io->text('Starting watch mode... (use -v for verbose output)');
288279
}
289280

290-
chdir($tailwindPath);
291-
$exitCode = 0;
292-
// phpcs:ignore Magento2.Security.InsecureFunction.Found -- passthru required for interactive watch mode
293-
passthru('npm run watch', $exitCode);
281+
$process = new Process(['npm', 'run', 'watch'], $tailwindPath);
282+
$process->setTimeout(null);
283+
$exitCode = $process->run(function ($type, $buffer) use ($output): void {
284+
$output->write($buffer);
285+
});
294286

295-
// Check if the command failed
296287
if ($exitCode !== 0) {
297288
$io->error(sprintf('Watch mode exited with error code: %d', $exitCode));
298289
return false;

0 commit comments

Comments
 (0)