CleanCommand.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. /**
  3. * @package Grav\Console\Cli
  4. *
  5. * @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Console\Cli;
  9. use Grav\Common\Filesystem\Folder;
  10. use Symfony\Component\Console\Command\Command;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. use Symfony\Component\Console\Formatter\OutputFormatterStyle;
  14. class CleanCommand extends Command
  15. {
  16. /* @var InputInterface $output */
  17. protected $input;
  18. /* @var OutputInterface $output */
  19. protected $output;
  20. /** @var array */
  21. protected $paths_to_remove = [
  22. 'codeception.yml',
  23. 'tests/',
  24. 'user/plugins/admin/vendor/bacon/bacon-qr-code/tests',
  25. 'user/plugins/admin/vendor/bacon/bacon-qr-code/.gitignore',
  26. 'user/plugins/admin/vendor/bacon/bacon-qr-code/.travis.yml',
  27. 'user/plugins/admin/vendor/bacon/bacon-qr-code/composer.json',
  28. 'user/plugins/admin/vendor/robthree/twofactorauth/demo',
  29. 'user/plugins/admin/vendor/robthree/twofactorauth/.vs',
  30. 'user/plugins/admin/vendor/robthree/twofactorauth/tests',
  31. 'user/plugins/admin/vendor/robthree/twofactorauth/.gitignore',
  32. 'user/plugins/admin/vendor/robthree/twofactorauth/.travis.yml',
  33. 'user/plugins/admin/vendor/robthree/twofactorauth/composer.json',
  34. 'user/plugins/admin/vendor/robthree/twofactorauth/composer.lock',
  35. 'user/plugins/admin/vendor/robthree/twofactorauth/logo.png',
  36. 'user/plugins/admin/vendor/robthree/twofactorauth/multifactorauthforeveryone.png',
  37. 'user/plugins/admin/vendor/robthree/twofactorauth/TwoFactorAuth.phpproj',
  38. 'user/plugins/admin/vendor/robthree/twofactorauth/TwoFactorAuth.sin',
  39. 'user/plugins/admin/vendor/zendframework/zendxml/tests',
  40. 'user/plugins/admin/vendor/zendframework/zendxml/.gitignore',
  41. 'user/plugins/admin/vendor/zendframework/zendxml/.travis.yml',
  42. 'user/plugins/admin/vendor/zendframework/zendxml/composer.json',
  43. 'user/plugins/email/vendor/swiftmailer/swiftmailer/.travis.yml',
  44. 'user/plugins/email/vendor/swiftmailer/swiftmailer/build.xml',
  45. 'user/plugins/email/vendor/swiftmailer/swiftmailer/composer.json',
  46. 'user/plugins/email/vendor/swiftmailer/swiftmailer/create_pear_package.php',
  47. 'user/plugins/email/vendor/swiftmailer/swiftmailer/package.xml.tpl',
  48. 'user/plugins/email/vendor/swiftmailer/swiftmailer/.gitattributes',
  49. 'user/plugins/email/vendor/swiftmailer/swiftmailer/.gitignore',
  50. 'user/plugins/email/vendor/swiftmailer/swiftmailer/README.git',
  51. 'user/plugins/email/vendor/swiftmailer/swiftmailer/tests',
  52. 'user/plugins/email/vendor/swiftmailer/swiftmailer/test-suite',
  53. 'user/plugins/email/vendor/swiftmailer/swiftmailer/notes',
  54. 'user/plugins/email/vendor/swiftmailer/swiftmailer/doc',
  55. 'user/themes/antimatter/.sass-cache',
  56. 'vendor/antoligy/dom-string-iterators/composer.json',
  57. 'vendor/doctrine/cache/.travis.yml',
  58. 'vendor/doctrine/cache/build.properties',
  59. 'vendor/doctrine/cache/build.xml',
  60. 'vendor/doctrine/cache/composer.json',
  61. 'vendor/doctrine/cache/phpunit.xml.dist',
  62. 'vendor/doctrine/cache/.coveralls.yml',
  63. 'vendor/doctrine/cache/.gitignore',
  64. 'vendor/doctrine/cache/.git',
  65. 'vendor/doctrine/cache/tests',
  66. 'vendor/doctrine/collections/composer.json',
  67. 'vendor/doctrine/collections/phpunit.xml.dist',
  68. 'vendor/doctrine/collections/tests',
  69. 'vendor/donatj/phpuseragentparser/.git',
  70. 'vendor/donatj/phpuseragentparser/.gitignore',
  71. 'vendor/donatj/phpuseragentparser/.editorconfig',
  72. 'vendor/donatj/phpuseragentparser/.travis.yml',
  73. 'vendor/donatj/phpuseragentparser/composer.json',
  74. 'vendor/donatj/phpuseragentparser/phpunit.xml.dist',
  75. 'vendor/donatj/phpuseragentparser/Tests',
  76. 'vendor/donatj/phpuseragentparser/Tools',
  77. 'vendor/dragonmantank/cron-expression/.editorconfig',
  78. 'vendor/dragonmantank/cron-expression/composer.json',
  79. 'vendor/dragonmantank/cron-expression/tests',
  80. 'vendor/erusev/parsedown/composer.json',
  81. 'vendor/erusev/parsedown/phpunit.xml.dist',
  82. 'vendor/erusev/parsedown/.travis.yml',
  83. 'vendor/erusev/parsedown/.git',
  84. 'vendor/erusev/parsedown/test',
  85. 'vendor/erusev/parsedown-extra/composer.json',
  86. 'vendor/erusev/parsedown-extra/phpunit.xml.dist',
  87. 'vendor/erusev/parsedown-extra/.travis.yml',
  88. 'vendor/erusev/parsedown-extra/.git',
  89. 'vendor/erusev/parsedown-extra/test',
  90. 'vendor/filp/whoops/composer.json',
  91. 'vendor/filp/whoops/docs',
  92. 'vendor/filp/whoops/examples',
  93. 'vendor/filp/whoops/tests',
  94. 'vendor/filp/whoops/.git',
  95. 'vendor/filp/whoops/.gitignore',
  96. 'vendor/filp/whoops/.scrutinizer.yml',
  97. 'vendor/filp/whoops/.travis.yml',
  98. 'vendor/filp/whoops/phpunit.xml.dist',
  99. 'vendor/gregwar/image/Gregwar/Image/composer.json',
  100. 'vendor/gregwar/image/Gregwar/Image/phpunit.xml',
  101. 'vendor/gregwar/image/Gregwar/Image/phpunit.xml.dist',
  102. 'vendor/gregwar/image/Gregwar/Image/Makefile',
  103. 'vendor/gregwar/image/Gregwar/Image/.editorconfig',
  104. 'vendor/gregwar/image/Gregwar/Image/.php_cs',
  105. 'vendor/gregwar/image/Gregwar/Image/.styleci.yml',
  106. 'vendor/gregwar/image/Gregwar/Image/.travis.yml',
  107. 'vendor/gregwar/image/Gregwar/Image/.gitignore',
  108. 'vendor/gregwar/image/Gregwar/Image/.git',
  109. 'vendor/gregwar/image/Gregwar/Image/doc',
  110. 'vendor/gregwar/image/Gregwar/Image/demo',
  111. 'vendor/gregwar/image/Gregwar/Image/tests',
  112. 'vendor/gregwar/cache/Gregwar/Cache/composer.json',
  113. 'vendor/gregwar/cache/Gregwar/Cache/phpunit.xml',
  114. 'vendor/gregwar/cache/Gregwar/Cache/.travis.yml',
  115. 'vendor/gregwar/cache/Gregwar/Cache/.gitignore',
  116. 'vendor/gregwar/cache/Gregwar/Cache/.git',
  117. 'vendor/gregwar/cache/Gregwar/Cache/demo',
  118. 'vendor/gregwar/cache/Gregwar/Cache/tests',
  119. 'vendor/guzzlehttp/psr7/composer.json',
  120. 'vendor/guzzlehttp/psr7/.editorconfig',
  121. 'vendor/kodus/psr7-server/composer.json',
  122. 'vendor/ircmaxell/password-compat/composer.json',
  123. 'vendor/ircmaxell/password-compat/phpunit.xml.dist',
  124. 'vendor/ircmaxell/password-compat/version-test.php',
  125. 'vendor/ircmaxell/password-compat/.travis.yml',
  126. 'vendor/ircmaxell/password-compat/test',
  127. 'vendor/league/climate/composer.json',
  128. 'vendor/league/climate/CODE_OF_CONDUCT.md',
  129. 'vendor/matthiasmullie/minify/bin',
  130. 'vendor/matthiasmullie/minify/composer.json',
  131. 'vendor/matthiasmullie/minify/docker-compose.yml',
  132. 'vendor/matthiasmullie/minify/Dockerfile',
  133. 'vendor/matthiasmullie/minify/CONTRIBUTING.md',
  134. 'vendor/matthiasmullie/path-converter/composer.json',
  135. 'vendor/maximebf/debugbar/bower.json',
  136. 'vendor/maximebf/debugbar/composer.json',
  137. 'vendor/maximebf/debugbar/.bowerrc',
  138. 'vendor/maximebf/debugbar/src/DebugBar/Resources/vendor',
  139. 'vendor/maximebf/debugbar/demo',
  140. 'vendor/maximebf/debugbar/docs',
  141. 'vendor/maximebf/debugbar/tests',
  142. 'vendor/maximebf/debugbar/phpunit.xml.dist',
  143. 'vendor/miljar/php-exif/.coveralls.yml',
  144. 'vendor/miljar/php-exif/.gitignore',
  145. 'vendor/miljar/php-exif/.travis.yml',
  146. 'vendor/miljar/php-exif/composer.json',
  147. 'vendor/miljar/php-exif/composer.lock',
  148. 'vendor/miljar/php-exif/phpunit.xml.dist',
  149. 'vendor/miljar/php-exif/Resources',
  150. 'vendor/miljar/php-exif/tests',
  151. 'vendor/monolog/monolog/composer.json',
  152. 'vendor/monolog/monolog/doc',
  153. 'vendor/monolog/monolog/phpunit.xml.dist',
  154. 'vendor/monolog/monolog/.php_cs',
  155. 'vendor/monolog/monolog/tests',
  156. 'vendor/nyholm/psr7/composer.json',
  157. 'vendor/nyholm/psr7/phpstan.neon.dist',
  158. 'vendor/phive/twig-extensions-deferred/.gitignore',
  159. 'vendor/phive/twig-extensions-deferred/.travis.yml',
  160. 'vendor/phive/twig-extensions-deferred/composer.json',
  161. 'vendor/phive/twig-extensions-deferred/phpunit.xml.dist',
  162. 'vendor/phive/twig-extensions-deferred/tests',
  163. 'vendor/php-http/message-factory/composer.json',
  164. 'vendor/php-http/message-factory/puli.json',
  165. 'vendor/pimple/pimple/.gitignore',
  166. 'vendor/pimple/pimple/.travis.yml',
  167. 'vendor/pimple/pimple/composer.json',
  168. 'vendor/pimple/pimple/ext',
  169. 'vendor/pimple/pimple/phpunit.xml.dist',
  170. 'vendor/pimple/pimple/src/Pimple/Tests',
  171. 'vendor/psr/container/composer.json',
  172. 'vendor/psr/container/.gitignore',
  173. 'vendor/psr/http-factory/.gitignore',
  174. 'vendor/psr/http-factory/.pullapprove.yml',
  175. 'vendor/psr/http-factory/composer.json',
  176. 'vendor/psr/http-message/composer.json',
  177. 'vendor/psr/http-server-handler/composer.json',
  178. 'vendor/psr/http-server-middleware/composer.json',
  179. 'vendor/psr/simple-cache/.editorconfig',
  180. 'vendor/psr/simple-cache/composer.json',
  181. 'vendor/psr/log/composer.json',
  182. 'vendor/psr/log/.gitignore',
  183. 'vendor/ralouphie/getallheaders/.gitignore',
  184. 'vendor/ralouphie/getallheaders/.travis.yml',
  185. 'vendor/ralouphie/getallheaders/composer.json',
  186. 'vendor/ralouphie/getallheaders/phpunit.xml',
  187. 'vendor/ralouphie/getallheaders/tests/',
  188. 'vendor/rockettheme/toolbox/.git',
  189. 'vendor/rockettheme/toolbox/.gitignore',
  190. 'vendor/rockettheme/toolbox/.scrutinizer.yml',
  191. 'vendor/rockettheme/toolbox/.travis.yml',
  192. 'vendor/rockettheme/toolbox/composer.json',
  193. 'vendor/rockettheme/toolbox/phpunit.xml',
  194. 'vendor/seld/cli-prompt/composer.json',
  195. 'vendor/seld/cli-prompt/.gitignore',
  196. 'vendor/symfony/console/composer.json',
  197. 'vendor/symfony/console/phpunit.xml.dist',
  198. 'vendor/symfony/console/.gitignore',
  199. 'vendor/symfony/console/.git',
  200. 'vendor/symfony/console/Tester',
  201. 'vendor/symfony/console/Tests',
  202. 'vendor/symfony/debug/.gitignore',
  203. 'vendor/symfony/debug/.git',
  204. 'vendor/symfony/debug/phpunit.xml.dist',
  205. 'vendor/symfony/debug/composer.json',
  206. 'vendor/symfony/debug/Tests',
  207. 'vendor/symfony/debug/Resources',
  208. 'vendor/symfony/event-dispatcher/.git',
  209. 'vendor/symfony/event-dispatcher/.gitignore',
  210. 'vendor/symfony/event-dispatcher/composer.json',
  211. 'vendor/symfony/event-dispatcher/phpunit.xml.dist',
  212. 'vendor/symfony/event-dispatcher/Tests',
  213. 'vendor/symfony/polyfill-ctype/composer.json',
  214. 'vendor/symfony/polyfill-iconv/.git',
  215. 'vendor/symfony/polyfill-iconv/.gitignore',
  216. 'vendor/symfony/polyfill-iconv/composer.json',
  217. 'vendor/symfony/polyfill-mbstring/.git',
  218. 'vendor/symfony/polyfill-mbstring/.gitignore',
  219. 'vendor/symfony/polyfill-mbstring/composer.json',
  220. 'vendor/symfony/polyfill-php72/composer.json',
  221. 'vendor/symfony/polyfill-php73/composer.json',
  222. 'vendor/symfony/process/.gitignore',
  223. 'vendor/symfony/process/composer.json',
  224. 'vendor/symfony/process/phpunit.xml.dist',
  225. 'vendor/symfony/process/Tests',
  226. 'vendor/symfony/var-dumper/.git',
  227. 'vendor/symfony/var-dumper/.gitignore',
  228. 'vendor/symfony/var-dumper/composer.json',
  229. 'vendor/symfony/var-dumper/phpunit.xml.dist',
  230. 'vendor/symfony/var-dumper/Test',
  231. 'vendor/symfony/var-dumper/Tests',
  232. 'vendor/symfony/yaml/composer.json',
  233. 'vendor/symfony/yaml/phpunit.xml.dist',
  234. 'vendor/symfony/yaml/.gitignore',
  235. 'vendor/symfony/yaml/.git',
  236. 'vendor/symfony/yaml/Tests',
  237. 'vendor/twig/twig/.editorconfig',
  238. 'vendor/twig/twig/.php_cs.dist',
  239. 'vendor/twig/twig/.travis.yml',
  240. 'vendor/twig/twig/.gitignore',
  241. 'vendor/twig/twig/.git',
  242. 'vendor/twig/twig/composer.json',
  243. 'vendor/twig/twig/phpunit.xml.dist',
  244. 'vendor/twig/twig/doc',
  245. 'vendor/twig/twig/ext',
  246. 'vendor/twig/twig/test',
  247. 'vendor/willdurand/negotiation/.gitignore',
  248. 'vendor/willdurand/negotiation/.travis.yml',
  249. 'vendor/willdurand/negotiation/appveyor.yml',
  250. 'vendor/willdurand/negotiation/composer.json',
  251. 'vendor/willdurand/negotiation/phpunit.xml.dist',
  252. 'vendor/willdurand/negotiation/tests',
  253. 'user/config/security.yaml',
  254. 'cache/compiled/',
  255. ];
  256. protected function configure()
  257. {
  258. $this
  259. ->setName('clean')
  260. ->setDescription('Handles cleaning chores for Grav distribution')
  261. ->setHelp('The <info>clean</info> clean extraneous folders and data');
  262. }
  263. /**
  264. * @param InputInterface $input
  265. * @param OutputInterface $output
  266. */
  267. protected function execute(InputInterface $input, OutputInterface $output)
  268. {
  269. $this->setupConsole($input, $output);
  270. $this->cleanPaths();
  271. }
  272. private function cleanPaths()
  273. {
  274. $this->output->writeln('');
  275. $this->output->writeln('<red>DELETING</red>');
  276. $anything = false;
  277. foreach ($this->paths_to_remove as $path) {
  278. $path = ROOT_DIR . $path;
  279. if (is_dir($path) && @Folder::delete($path)) {
  280. $anything = true;
  281. $this->output->writeln('<red>dir: </red>' . $path);
  282. } elseif (is_file($path) && @unlink($path)) {
  283. $anything = true;
  284. $this->output->writeln('<red>file: </red>' . $path);
  285. }
  286. }
  287. if (!$anything) {
  288. $this->output->writeln('');
  289. $this->output->writeln('<green>Nothing to clean...</green>');
  290. }
  291. }
  292. /**
  293. * Set colors style definition for the formatter.
  294. *
  295. * @param InputInterface $input
  296. * @param OutputInterface $output
  297. */
  298. public function setupConsole(InputInterface $input, OutputInterface $output)
  299. {
  300. $this->input = $input;
  301. $this->output = $output;
  302. $this->output->getFormatter()->setStyle('normal', new OutputFormatterStyle('white'));
  303. $this->output->getFormatter()->setStyle('yellow', new OutputFormatterStyle('yellow', null, ['bold']));
  304. $this->output->getFormatter()->setStyle('red', new OutputFormatterStyle('red', null, ['bold']));
  305. $this->output->getFormatter()->setStyle('cyan', new OutputFormatterStyle('cyan', null, ['bold']));
  306. $this->output->getFormatter()->setStyle('green', new OutputFormatterStyle('green', null, ['bold']));
  307. $this->output->getFormatter()->setStyle('magenta', new OutputFormatterStyle('magenta', null, ['bold']));
  308. $this->output->getFormatter()->setStyle('white', new OutputFormatterStyle('white', null, ['bold']));
  309. }
  310. }