Skip to content

Commit 199a04b

Browse files
Copilotdermatz
andauthored
Add verbose output support for watch task with error reporting (#69)
* Initial plan * #add - Implement verbose output support for watch task Co-authored-by: dermatz <[email protected]> * #docs - Update CHANGELOG with verbose output feature Co-authored-by: dermatz <[email protected]> * #fix - Address command injection vulnerability in MagentoStandard Builder Co-authored-by: dermatz <[email protected]> * ♻️ refactor: remove verbose option from watch command configuration * 🐛 fix: remove duplicate `--verbose` option from WatchCommand --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: dermatz <[email protected]> Co-authored-by: Mathias Elle <[email protected]>
1 parent ab8211e commit 199a04b

File tree

5 files changed

+68
-9
lines changed

5 files changed

+68
-9
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ All notable changes to this project will be documented in this file.
66

77
## UNRELEASED
88

9-
109
### Added
1110

11+
- feat: add verbose output support for watch task with `-v` flag
12+
- Shows informative messages during watch mode based on verbosity level
13+
- Captures and reports exit codes from npm/grunt watch commands
14+
- Displays clear error messages when watch mode exits with errors
15+
- Provides hint to use `-v` flag for verbose output in non-verbose mode
1216
- feat: add `mageforge:theme:tokens` command to generate Hyvä design tokens from design.tokens.json or hyva.config.json
1317
- feat: add `mageforge:hyva:compatibility:check` command to add a Hyvä compatibility checker
1418
- Scans Magento modules for Hyvä theme compatibility issues
@@ -26,8 +30,15 @@ All notable changes to this project will be documented in this file.
2630
- feat: add command alias `frontend:clean` for quick access
2731
- feat: add CI/CD tests for static:clean command in compatibility workflow
2832

33+
### Fixed
34+
35+
- fix: remove duplicate `--verbose` option from WatchCommand that conflicted with Symfony Console's built-in verbose option
36+
2937
### Changed
3038

39+
- refactor: improve build commands to show full output in verbose mode
40+
- Remove `--quiet` flag from npm/grunt build commands when using verbose mode
41+
- Allow better debugging of build issues during theme compilation
3142
- refactor: split complex executeCommand method into smaller, focused methods to reduce cyclomatic complexity
3243
- docs: update copilot-instructions.md with CI/CD integration guidelines for new commands
3344

src/Console/Command/Theme/WatchCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ protected function configure()
5959
protected function executeCommand(InputInterface $input, OutputInterface $output): int
6060
{
6161
$themeCode = $input->getArgument('themeCode');
62+
$isVerbose = $this->isVerbose($output);
6263

6364
if (empty($themeCode)) {
6465
$themeCode = $input->getOption('theme');
@@ -89,6 +90,6 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
8990
}
9091

9192
$builder = $this->builderPool->getBuilder($themePath);
92-
return $builder->watch($themePath, $this->io, $output, true) ? self::SUCCESS : self::FAILURE;
93+
return $builder->watch($themePath, $this->io, $output, $isVerbose) ? self::SUCCESS : self::FAILURE;
9394
}
9495
}

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: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ public function build(string $themePath, SymfonyStyle $io, OutputInterface $outp
4949
try {
5050
if ($isVerbose) {
5151
$io->text('Running grunt clean...');
52+
$this->shell->execute('node_modules/.bin/grunt clean');
53+
} else {
54+
$this->shell->execute('node_modules/.bin/grunt clean --quiet');
5255
}
53-
$this->shell->execute('node_modules/.bin/grunt clean --quiet');
5456

5557
if ($isVerbose) {
5658
$io->text('Running grunt less...');
59+
$this->shell->execute('node_modules/.bin/grunt less');
60+
} else {
61+
$this->shell->execute('node_modules/.bin/grunt less --quiet');
5762
}
58-
$this->shell->execute('node_modules/.bin/grunt less --quiet');
5963

6064
if ($isVerbose) {
6165
$io->success('Grunt tasks completed successfully.');
@@ -193,7 +197,20 @@ public function watch(string $themePath, SymfonyStyle $io, OutputInterface $outp
193197
}
194198

195199
try {
196-
passthru('node_modules/.bin/grunt watch');
200+
if ($isVerbose) {
201+
$io->text('Starting watch mode with verbose output...');
202+
} else {
203+
$io->text('Starting watch mode... (use -v for verbose output)');
204+
}
205+
206+
$exitCode = 0;
207+
passthru('node_modules/.bin/grunt watch', $exitCode);
208+
209+
// Check if the command failed
210+
if ($exitCode !== 0) {
211+
$io->error(sprintf('Watch mode exited with error code: %d', $exitCode));
212+
return false;
213+
}
197214
} catch (\Exception $e) {
198215
$io->error('Failed to start watch mode: ' . $e->getMessage());
199216
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)