|
14 | 14 | use OpenForgeProject\MageForge\Service\ThemeBuilder\BuilderInterface; |
15 | 15 | use Symfony\Component\Console\Output\OutputInterface; |
16 | 16 | use Symfony\Component\Console\Style\SymfonyStyle; |
| 17 | +use Symfony\Component\Process\Process; |
17 | 18 |
|
18 | 19 | class Builder implements BuilderInterface |
19 | 20 | { |
@@ -177,29 +178,19 @@ private function buildTheme(string $themePath, SymfonyStyle $io, bool $isVerbose |
177 | 178 | return false; |
178 | 179 | } |
179 | 180 |
|
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 | | - |
188 | 181 | try { |
189 | 182 | if ($isVerbose) { |
190 | 183 | $io->text('Running npm build...'); |
191 | 184 | } |
192 | 185 | // Use --quiet only in non-verbose mode to suppress routine output |
193 | 186 | $buildCommand = $isVerbose ? 'npm run build' : 'npm run build --quiet'; |
194 | | - $this->shell->execute($buildCommand); |
| 187 | + $this->shell->execute('cd %s && ' . $buildCommand, [$tailwindPath]); |
195 | 188 | if ($isVerbose) { |
196 | 189 | $io->success('Hyvä theme build completed successfully.'); |
197 | 190 | } |
198 | | - chdir($currentDir); |
199 | 191 | return true; |
200 | 192 | } catch (\Exception $e) { |
201 | 193 | $io->error('Failed to build Hyvä theme: ' . $e->getMessage()); |
202 | | - chdir($currentDir); |
203 | 194 | return false; |
204 | 195 | } |
205 | 196 | } |
@@ -287,12 +278,12 @@ public function watch( |
287 | 278 | $io->text('Starting watch mode... (use -v for verbose output)'); |
288 | 279 | } |
289 | 280 |
|
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 | + }); |
294 | 286 |
|
295 | | - // Check if the command failed |
296 | 287 | if ($exitCode !== 0) { |
297 | 288 | $io->error(sprintf('Watch mode exited with error code: %d', $exitCode)); |
298 | 289 | return false; |
|
0 commit comments