@@ -108,11 +108,107 @@ protected function execute(InputInterface $input, OutputInterface $output): int
108108
109109 $ io ->success ('Npm install completed successfully. ' );
110110
111- return Command::SUCCESS ;
111+
112+ // build
113+ $ themeCodes = $ input ->getArgument ('themeCodes ' );
114+ $ isVerbose = $ output ->getVerbosity () >= OutputInterface::VERBOSITY_VERBOSE ;
115+
116+ if (empty ($ themeCodes )) {
117+ $ themes = $ this ->themeList ->getAllThemes ();
118+ $ options = array_map (fn ($ theme ) => $ theme ->getCode (), $ themes );
119+
120+
121+ $ themeCodesPrompt = new MultiSelectPrompt (
122+ label: 'Select themes to build ' ,
123+ options: $ options ,
124+ scroll: 10 ,
125+ hint: 'Arrow keys to navigate, Space to select, Enter to confirm '
126+ );
127+
128+ $ themeCodes = $ themeCodesPrompt ->prompt ();
129+ }
130+
131+ return $ this ->processBuildThemes ($ themeCodes , $ io , $ output , $ isVerbose );
132+
112133 } catch (\Exception $ e ) {
113134 $ io ->error ($ e ->getMessage ());
114135 return Command::FAILURE ;
115136 }
116137 }
117138
139+ private function processBuildThemes (
140+ array $ themeCodes ,
141+ SymfonyStyle $ io ,
142+ OutputInterface $ output ,
143+ bool $ isVerbose
144+ ): int {
145+ $ startTime = microtime (true );
146+ $ successList = [];
147+
148+ if ($ isVerbose ) {
149+ $ io ->title (sprintf ('Building %d theme(s) ' , count ($ themeCodes )));
150+ }
151+
152+ foreach ($ themeCodes as $ themeCode ) {
153+ if (!$ this ->processTheme ($ themeCode , $ io , $ output , $ isVerbose , $ successList )) {
154+ continue ;
155+ }
156+ }
157+
158+ $ this ->displayBuildSummary ($ io , $ successList , microtime (true ) - $ startTime );
159+
160+ return Command::SUCCESS ;
161+ }
162+
163+ private function processTheme (
164+ string $ themeCode ,
165+ SymfonyStyle $ io ,
166+ OutputInterface $ output ,
167+ bool $ isVerbose ,
168+ array &$ successList
169+ ): bool {
170+ // Get theme path
171+ $ themePath = $ this ->themePath ->getPath ($ themeCode );
172+ if ($ themePath === null ) {
173+ $ io ->error ("Theme $ themeCode is not installed. " );
174+ return false ;
175+ }
176+
177+ // Find appropriate builder
178+ $ builder = $ this ->builderPool ->getBuilder ($ themePath );
179+ if ($ builder === null ) {
180+ $ io ->error ("No suitable builder found for theme $ themeCode. " );
181+ return false ;
182+ }
183+
184+ if ($ isVerbose ) {
185+ $ io ->section (sprintf ("Building theme %s using %s builder " , $ themeCode , $ builder ->getName ()));
186+ }
187+
188+ // Build the theme
189+ if (!$ builder ->build ($ themePath , $ io , $ output , $ isVerbose )) {
190+ $ io ->error ("Failed to build theme $ themeCode. " );
191+ return false ;
192+ }
193+
194+ $ successList [] = sprintf ("%s: Built successfully using %s builder " , $ themeCode , $ builder ->getName ());
195+ return true ;
196+ }
197+
198+ private function displayBuildSummary (SymfonyStyle $ io , array $ successList , float $ duration ): void
199+ {
200+ if (empty ($ successList )) {
201+ $ io ->warning ('No themes were built successfully. ' );
202+ return ;
203+ }
204+
205+ $ io ->success (sprintf (
206+ "Build process completed in %.2f seconds with the following results: " ,
207+ $ duration
208+ ));
209+
210+ foreach ($ successList as $ success ) {
211+ $ io ->writeln ("✓ $ success " );
212+ }
213+ }
118214}
0 commit comments