33namespace AgeekDev \VaporIgnore \Commands ;
44
55use AgeekDev \VaporIgnore \Manifest ;
6+ use AgeekDev \VaporIgnore \Path ;
67use AgeekDev \VaporIgnore \Vendor ;
78use Illuminate \Filesystem \Filesystem ;
89use Illuminate \Support \Str ;
910use Laravel \VaporCli \Helpers ;
10- use Laravel \VaporCli \Path ;
1111use Symfony \Component \Finder \Exception \DirectoryNotFoundException ;
1212use Symfony \Component \Finder \Finder ;
1313
1414class CleanIgnoredFilesCommand extends Command
1515{
1616 protected Filesystem $ files ;
1717
18+ protected int $ totalFiles = 0 ;
19+
20+ protected int $ totalDirectories = 0 ;
21+
22+ protected int $ totalFileSize = 0 ;
23+
1824 /**
1925 * Configure the command options.
2026 */
@@ -46,6 +52,9 @@ public function handle(): void
4652 $ this ->removeOtherFiles ();
4753 $ this ->removeUserIgnoredFiles ();
4854 $ this ->removeVaporIgnoreYml ();
55+
56+ Helpers::step ('<comment>Total Removed Files Size:</comment> ' .round ($ this ->totalFileSize / 1024 , 2 ).'kb ' );
57+
4958 }
5059
5160 /**
@@ -68,6 +77,8 @@ protected function removeReadmeFiles(): void
6877 protected function removeChangeLogFiles (): void
6978 {
7079 if (Manifest::isIgnoredVendor (Vendor::CHANGE_LOG )) {
80+ Helpers::step ('<options=bold>Removing CHANGELOG files</> ' );
81+
7182 $ this ->removeFiles ([
7283 'CHANGELOG.md ' ,
7384 'changelog.htm ' ,
@@ -81,7 +92,7 @@ protected function removeChangeLogFiles(): void
8192 protected function removeContributingFiles (): void
8293 {
8394 if (Manifest::isIgnoredVendor (Vendor::CONTRIBUTING )) {
84- Helpers::step ('<options=bold>Removing UPGRADE files</> ' );
95+ Helpers::step ('<options=bold>Removing CONTRIBUTING files</> ' );
8596
8697 $ this ->removeFiles ([
8798 'CONTRIBUTING.md ' ,
@@ -96,7 +107,7 @@ protected function removeContributingFiles(): void
96107 protected function removeUpgradeFiles (): void
97108 {
98109 if (Manifest::isIgnoredVendor (Vendor::UPGRADE )) {
99- Helpers::step ('<options=bold>Removing Upgrade files</> ' );
110+ Helpers::step ('<options=bold>Removing UPGRADE files</> ' );
100111
101112 $ this ->removeFiles ([
102113 'UPGRADING.md ' ,
@@ -111,7 +122,7 @@ protected function removeUpgradeFiles(): void
111122 protected function removeSecurityMdFiles (): void
112123 {
113124 if (Manifest::isIgnoredVendor (Vendor::SECURITY )) {
114- Helpers::step ('<options=bold>Removing security .md files</> ' );
125+ Helpers::step ('<options=bold>Removing SECURITY .md files</> ' );
115126
116127 $ this ->removeFiles ([
117128 'SECURITY.md ' ,
@@ -125,7 +136,7 @@ protected function removeSecurityMdFiles(): void
125136 protected function removeTestDirectories (): void
126137 {
127138 if (Manifest::isIgnoredVendor (Vendor::TEST )) {
128- Helpers::step ('<options=bold>Removing Test</> ' );
139+ Helpers::step ('<options=bold>Removing Test Folders </> ' );
129140
130141 $ this ->removeFiles ([
131142 'phpunit.xml.dist ' ,
@@ -137,6 +148,9 @@ protected function removeTestDirectories(): void
137148 ->in (Path::vendor ().'/*/*/ ' );
138149
139150 foreach ($ finder as $ file ) {
151+ Helpers::step ('<comment>Removing Ignored Directory:</comment> ' .str_replace (Path::current ().'/ ' , '' , $ file ->getRealPath ()));
152+ $ this ->totalFileSize += $ file ->getSize ();
153+ $ this ->totalFiles ++;
140154 $ this ->files ->deleteDirectory ($ file ->getRealPath (), true );
141155 }
142156 }
@@ -148,7 +162,7 @@ protected function removeTestDirectories(): void
148162 protected function removeLicenseFiles (): void
149163 {
150164 if (Manifest::isIgnoredVendor (Vendor::LICENSE )) {
151- Helpers::step ('<options=bold>Removing License Files</> ' );
165+ Helpers::step ('<options=bold>Removing LICENSE Files</> ' );
152166
153167 $ this ->removeFiles ([
154168 'LICENSE ' ,
@@ -166,7 +180,7 @@ protected function removeLicenseFiles(): void
166180 protected function removeLaravelIdeaDirectory (): void
167181 {
168182 if (Manifest::isIgnoredVendor (Vendor::LARAVEL_IDEA )) {
169- Helpers::step ('<options=bold>Removing Laravel Idea Folder</> ' );
183+ Helpers::step ('<options=bold>Removing Laravel IDEA Folder</> ' );
170184
171185 $ this ->removeDirectory (Path::vendor ().'/_laravel_idea ' );
172186 }
@@ -178,14 +192,21 @@ protected function removeLaravelIdeaDirectory(): void
178192 protected function removeDotGithubDirectories (): void
179193 {
180194 if (Manifest::isIgnoredVendor (Vendor::DOT_GITHUB )) {
181- Helpers::step ('<options=bold>Removing .github Folders From Vendor </> ' );
195+ Helpers::step ('<options=bold>Removing .github Folders</> ' );
182196
183197 $ finder = (new Finder ())
184198 ->ignoreDotFiles (false )
185199 ->directories ()->name ('.github ' )
186200 ->in (Path::vendor ().'/*/*/ ' );
187201
202+ if ($ finder ->count () === 0 ) {
203+ Helpers::step ('<comment>Not Found Ignored Directory:</comment> .github/ ' );
204+ }
205+
188206 foreach ($ finder as $ file ) {
207+ Helpers::step ('<comment>Removing Ignored Directory:</comment> ' .str_replace (Path::current ().'/ ' , '' , $ file ->getRealPath ()));
208+ $ this ->totalFileSize += $ file ->getSize ();
209+ $ this ->totalDirectories ++;
189210 $ this ->files ->deleteDirectory ($ file ->getRealPath (), true );
190211 }
191212 }
@@ -211,7 +232,7 @@ protected function removeOtherFiles(): void
211232 protected function removeDotFiles (): void
212233 {
213234 if (Manifest::isIgnoredVendor (Vendor::DOT_FILES )) {
214- Helpers::step ('<options=bold>Removing Dot Files From Vendor </> ' );
235+ Helpers::step ('<options=bold>Removing Dot Files</> ' );
215236
216237 $ this ->removeFiles ([
217238 '.editorconfig ' ,
@@ -227,16 +248,29 @@ protected function removeDotFiles(): void
227248 */
228249 protected function removeFiles ($ files , $ ignoreDotFiles = true ): void
229250 {
251+ $ isEmpty = true ;
252+
230253 foreach ($ files as $ item ) {
231254 $ finder = (new Finder ())
232255 ->files ()->name ($ item )
233256 ->ignoreDotFiles ($ ignoreDotFiles )
234257 ->in (Path::vendor ().'/*/*/ ' );
235258
259+ if ($ finder ->count () > 0 ) {
260+ $ isEmpty = false ;
261+ }
262+
236263 foreach ($ finder as $ file ) {
264+ $ this ->totalFileSize += $ file ->getSize ();
265+ $ this ->totalFiles ++;
266+ Helpers::step ('<comment>Removing Ignored File:</comment> ' .str_replace (Path::current ().'/ ' , '' , $ file ->getRealPath ()));
237267 $ this ->files ->delete ($ file ->getRealPath ());
238268 }
239269 }
270+
271+ if ($ isEmpty ) {
272+ Helpers::step ('<comment>Not Found Ignored File:</comment> ' .implode (', ' , $ files ));
273+ }
240274 }
241275
242276 /**
@@ -245,6 +279,9 @@ protected function removeFiles($files, $ignoreDotFiles = true): void
245279 protected function removeDirectory ($ directory ): void
246280 {
247281 if ($ this ->files ->isDirectory ($ directory )) {
282+ Helpers::step ('<comment>Removing Ignored Directory: </comment> ' .$ directory .'/ ' );
283+ $ this ->totalFileSize += $ this ->files ->size ($ directory );
284+ $ this ->totalDirectories ++;
248285 $ this ->files ->deleteDirectory ($ directory , true );
249286 }
250287 }
@@ -260,15 +297,20 @@ protected function removeUserIgnoredFiles(): void
260297 return ;
261298 }
262299
300+ Helpers::step ('<options=bold>Removing User Ignored Files</> ' );
301+
263302 $ notFoundDirectories = [];
264303
265304 foreach ($ ignoredFiles as $ pattern ) {
266305 [$ directory , $ filePattern ] = $ this ->parsePattern ($ pattern );
267306
268307 if ($ this ->files ->exists ($ directory .'/ ' .$ filePattern ) && $ this ->files ->isDirectory ($ directory .'/ ' .$ filePattern )) {
269308 Helpers::step ('<comment>Removing Ignored Directory:</comment> ' .$ filePattern .'/ ' );
270-
309+ $ fileSize = $ this -> files -> size ( $ directory . ' / ' . $ filePattern );
271310 $ this ->files ->deleteDirectory ($ directory .'/ ' .$ filePattern );
311+
312+ $ this ->totalFileSize += $ fileSize ;
313+ $ this ->totalDirectories ++;
272314 } else {
273315 try {
274316 $ files = (new Finder ())
@@ -279,8 +321,11 @@ protected function removeUserIgnoredFiles(): void
279321
280322 foreach ($ files as $ file ) {
281323 Helpers::step ('<comment>Removing Ignored File:</comment> ' .str_replace (Path::current ().'/ ' , '' , $ file ->getRealPath ()));
282-
324+ $ fileSize = $ this -> files -> size ( $ file -> getRealPath ());
283325 $ this ->files ->delete ($ file ->getRealPath ());
326+
327+ $ this ->totalFileSize += $ fileSize ;
328+ $ this ->totalFiles ++;
284329 }
285330 } catch (DirectoryNotFoundException ) {
286331 $ notFoundDirectories [] = $ directory .'/ ' .$ filePattern ;
0 commit comments