77use Magento \Framework \Filesystem \Driver \File ;
88use Magento \Framework \Shell ;
99use OpenForgeProject \MageForge \Service \CacheCleaner ;
10+ use OpenForgeProject \MageForge \Service \GruntTaskRunner ;
1011use OpenForgeProject \MageForge \Service \NodePackageManager ;
1112use OpenForgeProject \MageForge \Service \StaticContentCleaner ;
1213use OpenForgeProject \MageForge \Service \StaticContentDeployer ;
@@ -26,7 +27,8 @@ public function __construct(
2627 private readonly StaticContentCleaner $ staticContentCleaner ,
2728 private readonly CacheCleaner $ cacheCleaner ,
2829 private readonly SymlinkCleaner $ symlinkCleaner ,
29- private readonly NodePackageManager $ nodePackageManager
30+ private readonly NodePackageManager $ nodePackageManager ,
31+ private readonly GruntTaskRunner $ gruntTaskRunner
3032 ) {
3133 }
3234
@@ -56,37 +58,7 @@ public function build(string $themeCode, string $themePath, SymfonyStyle $io, Ou
5658 if ($ this ->isVendorTheme ($ themePath )) {
5759 $ io ->warning ('Vendor theme detected. Skipping Grunt steps. ' );
5860 } elseif ($ this ->hasNodeSetup ()) {
59- // Check if Node/Grunt setup exists
60- if (!$ this ->autoRepair ($ themePath , $ io , $ output , $ isVerbose )) {
61- return false ;
62- }
63-
64- // Clean symlinks in web/css/ directory before build
65- if (!$ this ->symlinkCleaner ->cleanSymlinks ($ themePath , $ io , $ isVerbose )) {
66- return false ;
67- }
68-
69- // Run grunt tasks
70- try {
71- if ($ isVerbose ) {
72- $ io ->text ('Running grunt clean... ' );
73- $ this ->shell ->execute ('node_modules/.bin/grunt clean ' );
74- } else {
75- $ this ->shell ->execute ('node_modules/.bin/grunt clean --quiet ' );
76- }
77-
78- if ($ isVerbose ) {
79- $ io ->text ('Running grunt less... ' );
80- $ this ->shell ->execute ('node_modules/.bin/grunt less ' );
81- } else {
82- $ this ->shell ->execute ('node_modules/.bin/grunt less --quiet ' );
83- }
84-
85- if ($ isVerbose ) {
86- $ io ->success ('Grunt tasks completed successfully. ' );
87- }
88- } catch (\Exception $ e ) {
89- $ io ->error ('Failed to run grunt tasks: ' . $ e ->getMessage ());
61+ if (!$ this ->processNodeSetup ($ themePath , $ io , $ output , $ isVerbose )) {
9062 return false ;
9163 }
9264 } else {
@@ -108,6 +80,29 @@ public function build(string $themeCode, string $themePath, SymfonyStyle $io, Ou
10880 return true ;
10981 }
11082
83+ /**
84+ * Process Node.js and Grunt setup
85+ */
86+ private function processNodeSetup (
87+ string $ themePath ,
88+ SymfonyStyle $ io ,
89+ OutputInterface $ output ,
90+ bool $ isVerbose
91+ ): bool {
92+ // Check if Node/Grunt setup exists
93+ if (!$ this ->autoRepair ($ themePath , $ io , $ output , $ isVerbose )) {
94+ return false ;
95+ }
96+
97+ // Clean symlinks in web/css/ directory before build
98+ if (!$ this ->symlinkCleaner ->cleanSymlinks ($ themePath , $ io , $ isVerbose )) {
99+ return false ;
100+ }
101+
102+ // Run grunt tasks
103+ return $ this ->gruntTaskRunner ->runTasks ($ io , $ output , $ isVerbose );
104+ }
105+
111106 public function autoRepair (string $ themePath , SymfonyStyle $ io , OutputInterface $ output , bool $ isVerbose ): bool
112107 {
113108 $ rootPath = '. ' ;
0 commit comments