|
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 | { |
@@ -122,32 +123,21 @@ public function build( |
122 | 123 | return false; |
123 | 124 | } |
124 | 125 |
|
125 | | - // Change to tailwind directory and run build |
126 | | - $currentDir = getcwd(); |
127 | | - if ($currentDir === false) { |
128 | | - $io->error('Cannot determine current directory'); |
129 | | - return false; |
130 | | - } |
131 | | - chdir($tailwindPath); |
132 | | - |
133 | 126 | try { |
134 | 127 | if ($isVerbose) { |
135 | 128 | $io->text('Running npm build...'); |
136 | 129 | } |
137 | 130 | // Use --quiet only in non-verbose mode to suppress routine output |
138 | 131 | $buildCommand = $isVerbose ? 'npm run build' : 'npm run build --quiet'; |
139 | | - $this->shell->execute($buildCommand); |
| 132 | + $this->shell->execute('cd %s && ' . $buildCommand, [$tailwindPath]); |
140 | 133 | if ($isVerbose) { |
141 | 134 | $io->success('Custom TailwindCSS theme build completed successfully.'); |
142 | 135 | } |
143 | 136 | } catch (\Exception $e) { |
144 | 137 | $io->error('Failed to build custom TailwindCSS theme: ' . $e->getMessage()); |
145 | | - chdir($currentDir); |
146 | 138 | return false; |
147 | 139 | } |
148 | 140 |
|
149 | | - chdir($currentDir); |
150 | | - |
151 | 141 | // Deploy static content |
152 | 142 | if (!$this->staticContentDeployer->deploy( |
153 | 143 | $themeCode, |
@@ -263,12 +253,12 @@ public function watch( |
263 | 253 | $io->text('Starting watch mode... (use -v for verbose output)'); |
264 | 254 | } |
265 | 255 |
|
266 | | - chdir($tailwindPath); |
267 | | - $exitCode = 0; |
268 | | - // phpcs:ignore Magento2.Security.InsecureFunction.Found -- passthru required for interactive watch mode |
269 | | - passthru('npm run watch', $exitCode); |
| 256 | + $process = new Process(['npm', 'run', 'watch'], $tailwindPath); |
| 257 | + $process->setTimeout(null); |
| 258 | + $exitCode = $process->run(function ($type, $buffer) use ($output): void { |
| 259 | + $output->write($buffer); |
| 260 | + }); |
270 | 261 |
|
271 | | - // Check if the command failed |
272 | 262 | if ($exitCode !== 0) { |
273 | 263 | $io->error(sprintf('Watch mode exited with error code: %d', $exitCode)); |
274 | 264 | return false; |
|
0 commit comments