Skip to content

Commit fd02e2f

Browse files
committed
fix: improve build and watch command execution
1 parent ed1e4ac commit fd02e2f

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

src/Service/ThemeBuilder/TailwindCSS/Builder.php

Lines changed: 7 additions & 17 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
{
@@ -122,32 +123,21 @@ public function build(
122123
return false;
123124
}
124125

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-
133126
try {
134127
if ($isVerbose) {
135128
$io->text('Running npm build...');
136129
}
137130
// Use --quiet only in non-verbose mode to suppress routine output
138131
$buildCommand = $isVerbose ? 'npm run build' : 'npm run build --quiet';
139-
$this->shell->execute($buildCommand);
132+
$this->shell->execute('cd %s && ' . $buildCommand, [$tailwindPath]);
140133
if ($isVerbose) {
141134
$io->success('Custom TailwindCSS theme build completed successfully.');
142135
}
143136
} catch (\Exception $e) {
144137
$io->error('Failed to build custom TailwindCSS theme: ' . $e->getMessage());
145-
chdir($currentDir);
146138
return false;
147139
}
148140

149-
chdir($currentDir);
150-
151141
// Deploy static content
152142
if (!$this->staticContentDeployer->deploy(
153143
$themeCode,
@@ -263,12 +253,12 @@ public function watch(
263253
$io->text('Starting watch mode... (use -v for verbose output)');
264254
}
265255

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+
});
270261

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

0 commit comments

Comments
 (0)