Skip to content

Commit 2e9e3ec

Browse files
Copilotdermatz
andcommitted
#add-hyva-token-command - Use Shell service for better security and consistency
Co-authored-by: dermatz <6103201+dermatz@users.noreply.github.com>
1 parent f2b5a5f commit 2e9e3ec

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

src/Console/Command/Theme/TokensCommand.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Laravel\Prompts\SelectPrompt;
88
use Magento\Framework\Console\Cli;
99
use Magento\Framework\Filesystem\Driver\File;
10+
use Magento\Framework\Shell;
1011
use OpenForgeProject\MageForge\Console\Command\AbstractCommand;
1112
use OpenForgeProject\MageForge\Model\ThemeList;
1213
use OpenForgeProject\MageForge\Model\ThemePath;
@@ -25,12 +26,14 @@ class TokensCommand extends AbstractCommand
2526
* @param ThemePath $themePath
2627
* @param BuilderPool $builderPool
2728
* @param File $fileDriver
29+
* @param Shell $shell
2830
*/
2931
public function __construct(
3032
private readonly ThemeList $themeList,
3133
private readonly ThemePath $themePath,
3234
private readonly BuilderPool $builderPool,
3335
private readonly File $fileDriver,
36+
private readonly Shell $shell,
3437
) {
3538
parent::__construct();
3639
}
@@ -114,28 +117,15 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
114117
try {
115118
if ($isVerbose) {
116119
$this->io->text('Running npx hyva-tokens...');
117-
passthru('npx hyva-tokens', $returnCode);
118-
} else {
119-
exec('npx hyva-tokens 2>&1', $commandOutput, $returnCode);
120-
121-
if ($returnCode === 0) {
122-
$this->io->success('Hyvä design tokens generated successfully.');
123-
} else {
124-
$this->io->error('Failed to generate Hyvä design tokens.');
125-
if (!empty($commandOutput)) {
126-
$this->io->writeln($commandOutput);
127-
}
128-
}
129120
}
130-
121+
122+
$this->shell->execute('npx hyva-tokens');
123+
131124
chdir($currentDir);
132125

133-
if ($returnCode !== 0) {
134-
return Cli::RETURN_FAILURE;
135-
}
136-
126+
$this->io->success('Hyvä design tokens generated successfully.');
127+
137128
if ($isVerbose) {
138-
$this->io->success('Hyvä design tokens generated successfully.');
139129
$this->io->newLine();
140130
$this->io->text('The generated file can be found at:');
141131
$this->io->text($tailwindPath . '/generated/hyva-tokens.css');

0 commit comments

Comments
 (0)