Skip to content

Commit cffd205

Browse files
Copilotdermatz
andcommitted
#add - Implement verbose output support for watch task
Co-authored-by: dermatz <6103201+dermatz@users.noreply.github.com>
1 parent 36eee7f commit cffd205

4 files changed

Lines changed: 60 additions & 8 deletions

File tree

src/Console/Command/Theme/WatchCommand.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ protected function configure()
5050
InputOption::VALUE_OPTIONAL,
5151
'Theme to watch (format: Vendor/theme)'
5252
)
53+
->addOption(
54+
'verbose',
55+
'v',
56+
InputOption::VALUE_NONE,
57+
'Enable verbose output'
58+
)
5359
->setAliases(['frontend:watch']);
5460
}
5561

@@ -59,6 +65,7 @@ protected function configure()
5965
protected function executeCommand(InputInterface $input, OutputInterface $output): int
6066
{
6167
$themeCode = $input->getArgument('themeCode');
68+
$isVerbose = $this->isVerbose($output);
6269

6370
if (empty($themeCode)) {
6471
$themeCode = $input->getOption('theme');
@@ -89,6 +96,6 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
8996
}
9097

9198
$builder = $this->builderPool->getBuilder($themePath);
92-
return $builder->watch($themePath, $this->io, $output, true) ? self::SUCCESS : self::FAILURE;
99+
return $builder->watch($themePath, $this->io, $output, $isVerbose) ? self::SUCCESS : self::FAILURE;
93100
}
94101
}

src/Service/ThemeBuilder/HyvaThemes/Builder.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ private function buildTheme(string $themePath, SymfonyStyle $io, bool $isVerbose
121121
if ($isVerbose) {
122122
$io->text('Running npm build...');
123123
}
124-
$this->shell->execute('npm run build --quiet');
124+
// Use --quiet only in non-verbose mode to suppress routine output
125+
$buildCommand = $isVerbose ? 'npm run build' : 'npm run build --quiet';
126+
$this->shell->execute($buildCommand);
125127
if ($isVerbose) {
126128
$io->success('Hyvä theme build completed successfully.');
127129
}
@@ -226,8 +228,21 @@ public function watch(string $themePath, SymfonyStyle $io, OutputInterface $outp
226228
}
227229

228230
try {
231+
if ($isVerbose) {
232+
$io->text('Starting watch mode with verbose output...');
233+
} else {
234+
$io->text('Starting watch mode... (use -v for verbose output)');
235+
}
236+
229237
chdir($tailwindPath);
230-
passthru('npm run watch');
238+
$exitCode = 0;
239+
passthru('npm run watch', $exitCode);
240+
241+
// Check if the command failed
242+
if ($exitCode !== 0) {
243+
$io->error(sprintf('Watch mode exited with error code: %d', $exitCode));
244+
return false;
245+
}
231246
} catch (\Exception $e) {
232247
$io->error('Failed to start watch mode: ' . $e->getMessage());
233248
return false;

src/Service/ThemeBuilder/MagentoStandard/Builder.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ public function build(string $themePath, SymfonyStyle $io, OutputInterface $outp
5050
if ($isVerbose) {
5151
$io->text('Running grunt clean...');
5252
}
53-
$this->shell->execute('node_modules/.bin/grunt clean --quiet');
53+
// Use --quiet only in non-verbose mode to suppress routine output
54+
$quietFlag = $isVerbose ? '' : '--quiet';
55+
$this->shell->execute("node_modules/.bin/grunt clean $quietFlag");
5456

5557
if ($isVerbose) {
5658
$io->text('Running grunt less...');
5759
}
58-
$this->shell->execute('node_modules/.bin/grunt less --quiet');
60+
$this->shell->execute("node_modules/.bin/grunt less $quietFlag");
5961

6062
if ($isVerbose) {
6163
$io->success('Grunt tasks completed successfully.');
@@ -193,7 +195,20 @@ public function watch(string $themePath, SymfonyStyle $io, OutputInterface $outp
193195
}
194196

195197
try {
196-
passthru('node_modules/.bin/grunt watch');
198+
if ($isVerbose) {
199+
$io->text('Starting watch mode with verbose output...');
200+
} else {
201+
$io->text('Starting watch mode... (use -v for verbose output)');
202+
}
203+
204+
$exitCode = 0;
205+
passthru('node_modules/.bin/grunt watch', $exitCode);
206+
207+
// Check if the command failed
208+
if ($exitCode !== 0) {
209+
$io->error(sprintf('Watch mode exited with error code: %d', $exitCode));
210+
return false;
211+
}
197212
} catch (\Exception $e) {
198213
$io->error('Failed to start watch mode: ' . $e->getMessage());
199214
return false;

src/Service/ThemeBuilder/TailwindCSS/Builder.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public function build(string $themePath, SymfonyStyle $io, OutputInterface $outp
7979
if ($isVerbose) {
8080
$io->text('Running npm build...');
8181
}
82-
$this->shell->execute('npm run build --quiet');
82+
// Use --quiet only in non-verbose mode to suppress routine output
83+
$buildCommand = $isVerbose ? 'npm run build' : 'npm run build --quiet';
84+
$this->shell->execute($buildCommand);
8385
if ($isVerbose) {
8486
$io->success('Custom TailwindCSS theme build completed successfully.');
8587
}
@@ -198,8 +200,21 @@ public function watch(string $themePath, SymfonyStyle $io, OutputInterface $outp
198200
}
199201

200202
try {
203+
if ($isVerbose) {
204+
$io->text('Starting watch mode with verbose output...');
205+
} else {
206+
$io->text('Starting watch mode... (use -v for verbose output)');
207+
}
208+
201209
chdir($tailwindPath);
202-
passthru('npm run watch');
210+
$exitCode = 0;
211+
passthru('npm run watch', $exitCode);
212+
213+
// Check if the command failed
214+
if ($exitCode !== 0) {
215+
$io->error(sprintf('Watch mode exited with error code: %d', $exitCode));
216+
return false;
217+
}
203218
} catch (\Exception $e) {
204219
$io->error('Failed to start watch mode: ' . $e->getMessage());
205220
return false;

0 commit comments

Comments
 (0)