diff --git a/README.md b/README.md index 8f15933..a4516b8 100644 --- a/README.md +++ b/README.md @@ -184,3 +184,10 @@ $ tail server.php $ tail server.php --line 5 ``` ![Tail Command](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/tail-command.png) + + +### Cleanup +```bash +$ cleanup +``` +![Cleanup Command](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/cleanup-command.png) diff --git a/screenshots/cleanup-command.png b/screenshots/cleanup-command.png new file mode 100644 index 0000000..dfcd664 Binary files /dev/null and b/screenshots/cleanup-command.png differ diff --git a/src/Console/Commands/Cleanup.php b/src/Console/Commands/Cleanup.php new file mode 100644 index 0000000..17c5fcd --- /dev/null +++ b/src/Console/Commands/Cleanup.php @@ -0,0 +1,154 @@ +laravel) === false) { + $root = $this->laravel->basePath(); + } else { + $root = getcwd(); + } + + $vendorDir = realpath($root.'/vendor'); + $rules = static::getRules(); + foreach ($rules as $packageDir => $rules) { + $packageDir = $vendorDir.'/'.$packageDir; + if ($filesystem->isDirectory($packageDir) === false) { + continue; + } + + foreach ((array) $rules as $part) { + $patterns = explode(' ', trim($part)); + foreach ($patterns as $pattern) { + foreach ($filesystem->glob($packageDir.'/'.$pattern) as $file) { + $this->info('cleanup: '.$file); + try { + if ($filesystem->isDirectory($file) === true) { + $filesystem->deleteDirectory($file, true); + } else { + $filesystem->delete($file); + } + } catch (Exception $e) { + $this->error($e->getMessage()); + } + } + } + } + } + } + + public static function getRules() + { + // Default patterns for common files + $docs = 'README* CHANGELOG* FAQ* CONTRIBUTING* HISTORY* UPGRADING* UPGRADE* package* demo example examples doc docs readme*'; + $tests = '.travis.yml .scrutinizer.yml phpunit.xml* phpunit.php test tests Tests travis'; + + return [ + // Symfony components + 'symfony/browser-kit' => [$docs, $tests], + 'symfony/class-loader' => [$docs, $tests], + 'symfony/console' => [$docs, $tests], + 'symfony/css-selector' => [$docs, $tests], + 'symfony/debug' => [$docs, $tests], + 'symfony/dom-crawler' => [$docs, $tests], + 'symfony/event-dispatcher' => [$docs, $tests], + 'symfony/filesystem' => [$docs, $tests], + 'symfony/finder' => [$docs, $tests], + 'symfony/http-foundation' => [$docs, $tests], + 'symfony/http-kernel' => [$docs, $tests], + 'symfony/process' => [$docs, $tests], + 'symfony/routing' => [$docs, $tests], + 'symfony/security' => [$docs, $tests], + 'symfony/security-core' => [$docs, $tests], + 'symfony/translation' => [$docs, $tests], + 'symfony/var-dumper' => [$docs, $tests], + // Default Laravel 4 install + 'classpreloader/classpreloader' => [$docs, $tests], + 'd11wtq/boris' => [$docs, $tests], + 'filp/whoops' => [$docs, $tests], + 'ircmaxell/password-compat' => [$docs, $tests], + 'jeremeamia/SuperClosure' => [$docs, $tests, 'demo'], + 'laravel/framework' => [$docs, $tests, 'build'], + 'monolog/monolog' => [$docs, $tests], + 'nesbot/carbon' => [$docs, $tests], + 'nikic/php-parser' => [$docs, $tests, 'test_old'], + 'patchwork/utf8' => [$docs, $tests], + 'phpseclib/phpseclib' => [$docs, $tests, 'build'], + 'predis/predis' => [$docs, $tests, 'bin'], + 'psr/log' => [$docs, $tests], + 'stack/builder' => [$docs, $tests], + 'swiftmailer/swiftmailer' => [$docs, $tests, 'build* notes test-suite create_pear_package.php'], + // Common packages + 'anahkiasen/former' => [$docs, $tests], + 'anahkiasen/html-object' => [$docs, 'phpunit.xml* tests/*'], + 'anahkiasen/underscore-php' => [$docs, $tests], + 'anahkiasen/rocketeer' => [$docs, $tests], + 'barryvdh/composer-cleanup-plugin' => [$docs, $tests], + 'barryvdh/laravel-debugbar' => [$docs, $tests], + 'barryvdh/laravel-ide-helper' => [$docs, $tests], + 'bllim/datatables' => [$docs, $tests], + 'cartalyst/sentry' => [$docs, $tests], + 'dflydev/markdown' => [$docs, $tests], + 'doctrine/annotations' => [$docs, $tests, 'bin'], + 'doctrine/cache' => [$docs, $tests, 'bin'], + 'doctrine/collections' => [$docs, $tests], + 'doctrine/common' => [$docs, $tests, 'bin lib/vendor'], + 'doctrine/dbal' => [$docs, $tests, 'bin build* docs2 lib/vendor'], + 'doctrine/inflector' => [$docs, $tests], + 'dompdf/dompdf' => [$docs, $tests, 'www'], + 'guzzle/guzzle' => [$docs, $tests], + 'guzzlehttp/guzzle' => [$docs, $tests], + 'guzzlehttp/oauth-subscriber' => [$docs, $tests], + 'guzzlehttp/streams' => [$docs, $tests], + 'imagine/imagine' => [$docs, $tests, 'lib/Imagine/Test'], + 'intervention/image' => [$docs, $tests, 'public'], + 'jasonlewis/basset' => [$docs, $tests], + 'kriswallsmith/assetic' => [$docs, $tests], + 'leafo/lessphp' => [$docs, $tests, 'Makefile package.sh'], + 'league/stack-robots' => [$docs, $tests], + 'maximebf/debugbar' => [$docs, $tests, 'demo'], + 'mccool/laravel-auto-presenter' => [$docs, $tests], + 'mockery/mockery' => [$docs, $tests], + 'mrclay/minify' => [$docs, $tests, 'MIN.txt min_extras min_unit_tests min/builder min/config* min/quick-test* min/utils.php min/groupsConfig.php min/index.php'], + 'mustache/mustache' => [$docs, $tests, 'bin'], + 'oyejorge/less.php' => [$docs, $tests], + 'phenx/php-font-lib' => [$docs, $tests.'www'], + 'phpdocumentor/reflection-docblock' => [$docs, $tests], + 'phpoffice/phpexcel' => [$docs, $tests, 'Examples unitTests changelog.txt'], + 'rcrowe/twigbridge' => [$docs, $tests], + 'simplepie/simplepie' => [$docs, $tests, 'build compatibility_test ROADMAP.md'], + 'tijsverkoyen/css-to-inline-styles' => [$docs, $tests], + 'twig/twig' => [$docs, $tests], + 'venturecraft/revisionable' => [$docs, $tests], + 'willdurand/geocoder' => [$docs, $tests], + ]; + } +} diff --git a/src/Console/Kernel.php b/src/Console/Kernel.php index 16d7ff7..2a4d71b 100644 --- a/src/Console/Kernel.php +++ b/src/Console/Kernel.php @@ -14,6 +14,7 @@ class Kernel extends ConsoleKernel protected $commands = [ Commands\Artisan::class, Commands\ArtisanTinker::class, + Commands\Cleanup::class, Commands\Find::class, Commands\Mysql::class, Commands\Tail::class,