├── src ├── config │ ├── .gitkeep │ └── config.php └── Barryvdh │ └── VendorCleanup │ ├── VendorCleanupServiceProvider.php │ └── VendorCleanupCommand.php ├── .gitignore ├── composer.json └── readme.md /src/config/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "barryvdh/laravel-vendor-cleanup", 3 | "description": "A vendor cleanup package, to remove tests and documentation to save space", 4 | "keywords": ["laravel", "vendor", "cleanup"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Barry vd. Heuvel", 9 | "email": "barryvdh@gmail.com" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=5.3.0", 14 | "illuminate/support": "4.x", 15 | "illuminate/console": "4.x", 16 | "illuminate/filesystem": "4.x", 17 | "symfony/finder": "~2.3" 18 | }, 19 | "autoload": { 20 | "psr-0": { 21 | "Barryvdh\\VendorCleanup": "src/" 22 | } 23 | }, 24 | "minimum-stability": "dev" 25 | } -------------------------------------------------------------------------------- /src/Barryvdh/VendorCleanup/VendorCleanupServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) 7 | * @license http://www.opensource.org/licenses/mit-license.php MIT 8 | * @link https://github.com/barryvdh/laravel-vendor-cleanup 9 | */ 10 | 11 | namespace Barryvdh\VendorCleanup; 12 | 13 | use Illuminate\Support\ServiceProvider; 14 | 15 | class VendorCleanupServiceProvider extends ServiceProvider { 16 | 17 | /** 18 | * Indicates if loading of the provider is deferred. 19 | * 20 | * @var bool 21 | */ 22 | protected $defer = true; 23 | 24 | /** 25 | * Bootstrap the application events. 26 | * 27 | * @return void 28 | */ 29 | public function boot() 30 | { 31 | $this->package('barryvdh/laravel-vendor-cleanup'); 32 | } 33 | 34 | /** 35 | * Register the service provider. 36 | * 37 | * @return void 38 | */ 39 | public function register() 40 | { 41 | $this->app['command.vendor-cleanup'] = $this->app->share(function($app) 42 | { 43 | return new VendorCleanupCommand; 44 | }); 45 | $this->commands('command.vendor-cleanup'); 46 | } 47 | 48 | /** 49 | * Get the services provided by the provider. 50 | * 51 | * @return array 52 | */ 53 | public function provides() 54 | { 55 | return array('command.vendor-cleanup'); 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## Laravel Vendor Cleanup Command 2 | 3 | ### Remove tests & documentation from the vendor dir 4 | 5 | ### Stand-alone Composer plugin: https://github.com/barryvdh/composer-cleanup-plugin 6 | 7 | #### Don't use this when you hava ssh access, just use composer and don't worry about size! 8 | #### If possible at all, just create a distribution script or use git to deploy! 9 | 10 | Require this package in your composer.json: 11 | 12 | "barryvdh/laravel-vendor-cleanup": "1.*" 13 | 14 | And add the ServiceProvider to the providers array in app/config/app.php 15 | 16 | 'Barryvdh\VendorCleanup\VendorCleanupServiceProvider', 17 | 18 | You can now remove all the docs/tests/examples/build scripts throught artisan 19 | 20 | php artisan vendor-cleanup 21 | 22 | You should change your composer file to use the `dist` version, without the .git history. 23 | You can configure your composer.json to do this, and cleanup after updating: 24 | 25 | "scripts":{ 26 | "post-install-cmd": [ 27 | "php artisan vendor-cleanup", 28 | "php artisan optimize" 29 | ], 30 | "post-update-cmd":[ 31 | "php artisan vendor-cleanup", 32 | "php artisan optimize" 33 | ] 34 | }, 35 | "config": { 36 | "preferred-install": "dist" 37 | }, 38 | 39 | Note: If you switch from prefer-source (the default composer setting for non-stable packages), you should delete your 40 | vendor dir and re-download all packages, without the .git history (and greatly reducing filesize). 41 | This will also prevent questions about changed files, because packages with .git history are checked for changes. 42 | 43 | When distributing 44 | 45 | You can add your own rules, when you publish the config file. 46 | 47 | 'commands' => array( 48 | 'name/package' => 'CHANGELOG* phpunit.xml* tests docs', 49 | ), 50 | 51 | This will look for files matching `CHANGELOG*` or `phpunit.xml*` or `tests` or `docs` in vendor/name/package and delete them. 52 | 53 | If the package is commonly used, please make a PR to add the command to src/Barryvdh/VendorCleanup/VendorCleanupCommand.php 54 | 55 | Most of the cleanup commands are based on the SensioDistributionBundle build script; 56 | https://github.com/sensio/SensioDistributionBundle/blob/master/Resources/bin/build.sh 57 | 58 | 59 | ### License 60 | 61 | The Laravel Vendor Cleanup Command is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) 62 | -------------------------------------------------------------------------------- /src/Barryvdh/VendorCleanup/VendorCleanupCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) 7 | * @license http://www.opensource.org/licenses/mit-license.php MIT 8 | * @link https://github.com/barryvdh/laravel-vendor-cleanup 9 | */ 10 | 11 | namespace Barryvdh\VendorCleanup; 12 | 13 | use Illuminate\Console\Command; 14 | use Symfony\Component\Console\Input\InputOption; 15 | use Symfony\Component\Console\Input\InputArgument; 16 | use Symfony\Component\Finder\Finder; 17 | use Illuminate\Filesystem\Filesystem; 18 | use Illuminate\Support\Facades\Config; 19 | 20 | class VendorCleanupCommand extends Command 21 | { 22 | 23 | /** 24 | * The console command name. 25 | * 26 | * @var string 27 | */ 28 | protected $name = 'vendor-cleanup'; 29 | 30 | /** 31 | * The console command description. 32 | * 33 | * @var string 34 | */ 35 | protected $description = 'Cleanup vendor directory.'; 36 | 37 | 38 | /** 39 | * Execute the console command. 40 | * 41 | * @return void 42 | */ 43 | public function fire() 44 | { 45 | $vendorDir = realpath($this->argument('dir')); 46 | $this->info("Cleaning dir: $vendorDir"); 47 | 48 | $rules = Config::get('laravel-vendor-cleanup::rules'); 49 | 50 | $filesystem = new Filesystem(); 51 | 52 | foreach($rules as $packageDir => $rule){ 53 | if(!file_exists($vendorDir . '/' . $packageDir)){ 54 | continue; 55 | } 56 | $patterns = explode(' ', $rule); 57 | foreach($patterns as $pattern){ 58 | try{ 59 | $finder = new Finder(); 60 | $finder->name($pattern)->in( $vendorDir . '/' . $packageDir); 61 | 62 | // we can't directly iterate over $finder if it lists dirs we're deleting 63 | $files = iterator_to_array($finder); 64 | 65 | /** @var \SplFileInfo $file */ 66 | foreach($files as $file){ 67 | if($file->isDir()){ 68 | $filesystem->deleteDirectory($file); 69 | }elseif($file->isFile()){ 70 | $filesystem->delete($file); 71 | } 72 | } 73 | }catch(\Exception $e){ 74 | $this->error("Could not parse $packageDir ($pattern): ".$e->getMessage()); 75 | } 76 | } 77 | } 78 | } 79 | 80 | 81 | /** 82 | * Get the console command arguments. 83 | * 84 | * @return array 85 | */ 86 | protected function getArguments() 87 | { 88 | return array( 89 | array('dir', InputArgument::OPTIONAL, 'The path to vendor (absolute path)', Config::get('laravel-vendor-cleanup::dir', base_path() . '/vendor')), 90 | ); 91 | } 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/config/config.php: -------------------------------------------------------------------------------- 1 | base_path() . '/vendor', 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Rules 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Additional rules, to do your own cleanups 24 | | 25 | */ 26 | 'rules' => array( 27 | // Symfony components 28 | 'symfony/browser-kit/Symfony/Component/BrowserKit' => "{$standard}", 29 | 'symfony/class-loader/Symfony/Component/ClassLoader' => "{$standard}", 30 | 'symfony/console/Symfony/Component/Console' => "{$standard}", 31 | 'symfony/css-selector/Symfony/Component/CssSelector' => "{$standard}", 32 | 'symfony/debug/Symfony/Component/Debug' => "{$standard}", 33 | 'symfony/dom-crawler/Symfony/Component/DomCrawler' => "{$standard}", 34 | 'symfony/event-dispatcher/Symfony/Component/EventDispatcher' => "{$standard}", 35 | 'symfony/filesystem/Symfony/Component/Filesystem' => "{$standard}", 36 | 'symfony/finder/Symfony/Component/Finder' => "{$standard}", 37 | 'symfony/http-foundation/Symfony/Component/HttpFoundation' => "{$standard}", 38 | 'symfony/http-kernel/Symfony/Component/HttpKernel' => "{$standard}", 39 | 'symfony/process/Symfony/Component/Process' => "{$standard}", 40 | 'symfony/routing/Symfony/Component/Routing' => "{$standard}", 41 | 'symfony/security/Symfony/Component/Security' => "{$standard}", 42 | 'symfony/security-core/Symfony/Component/Security/Core' => "{$standard}", 43 | 'symfony/translation/Symfony/Component/Translation' => "{$standard}", 44 | 'symfony/polyfill-mbstring' => "{$standard}", 45 | 'symfony/var-dumper' => "{$standard}", 46 | 'symfony/yaml' => "{$standard}", 47 | 48 | // Default Laravel 4 install 49 | 'd11wtq/boris' => "{$standard}", 50 | 'filp/whoops' => "{$standard}", 51 | 'ircmaxell/password-compat' => "{$standard}", 52 | 'jeremeamia/SuperClosure' => "{$standard}", 53 | 'laravel/framework' => "{$standard} build", 54 | 'monolog/monolog' => "{$standard}", 55 | 'nesbot/carbon' => "{$standard}", 56 | 'nikic/php-parser' => "{$standard} test_old", 57 | 'patchwork/utf8' => "{$standard}", 58 | 'phpseclib/phpseclib' => "{$standard}", 59 | 'predis/predis' => "{$standard} bin", 60 | 'stack/builder' => "{$standard}", 61 | 'swiftmailer/swiftmailer' => "{$standard} build* notes test-suite create_pear_package.php", 62 | 63 | // Common packages 64 | 'anahkiasen/former' => "{$standard}", 65 | 'anahkiasen/html-object' => "{$docs} phpunit.xml* tests/*", 66 | 'anahkiasen/underscore-php' => "{$standard}", 67 | 'anahkiasen/rocketeer' => "{$standard}", 68 | 'barryvdh/laravel-debugbar' => "{$standard}", 69 | 'bllim/datatables' => "{$standard}", 70 | 'cartalyst/sentry' => "{$standard}", 71 | 'dflydev/markdown' => "{$standard}", 72 | 'doctrine/annotations' => "{$standard} bin", 73 | 'doctrine/cache' => "{$standard} bin", 74 | 'doctrine/collections' => "{$standard}", 75 | 'doctrine/common' => "{$standard} bin lib/vendor", 76 | 'doctrine/dbal' => "{$standard} bin build* docs2 lib/vendor", 77 | 'doctrine/inflector' => "{$standard}", 78 | 'dompdf/dompdf' => "{$standard} www", 79 | 'guzzle/guzzle' => "{$standard}", 80 | 'guzzlehttp/guzzle' => "{$standard}", 81 | 'guzzlehttp/oauth-subscriber' => "{$standard}", 82 | 'guzzlehttp/streams' => "{$standard}", 83 | 'imagine/imagine' => "{$standard} lib/Imagine/Test", 84 | 'intervention/image' => "{$standard} public", 85 | 'jasonlewis/basset' => "{$standard}", 86 | 'jeremeamia/SuperClosure' => "{$standard} demo", 87 | 'kriswallsmith/assetic' => "{$standard}", 88 | 'leafo/lessphp' => "{$standard} Makefile package.sh", 89 | 'league/stack-robots' => "{$standard}", 90 | 'maximebf/debugbar' => "{$standard} demo", 91 | 'mockery/mockery' => "{$standard}", 92 | 'mrclay/minify' => "{$standard} MIN.txt min_extras min_unit_tests min/builder min/config* min/quick-test* min/utils.php min/groupsConfig.php min/index.php", 93 | 'mustache/mustache' => "{$standard} bin", 94 | 'oyejorge/less.php' => "{$standard}", 95 | 'phenx/php-font-lib' => "{$standard} www", 96 | 'phpdocumentor/reflection-docblock' => "{$standard}", 97 | 'phpoffice/phpexcel' => "{$standard} Examples unitTests changelog.txt", 98 | 'rcrowe/twigbridge' => "{$standard}", 99 | 'tijsverkoyen/css-to-inline-styles' => "{$standard}", 100 | 'twig/twig' => "{$standard}", 101 | 'venturecraft/revisionable' => "{$standard}", 102 | 'willdurand/geocoder' => "{$standard}", 103 | 104 | //AWS SDK 105 | 'aws/aws-sdk-php' => "{$standard}", 106 | 'aws/aws-sdk-php-laravel' => "{$standard}", 107 | 108 | // PHPUnit Testing Framework 109 | 'phpunit/php-code-coverage' => "{$standard}", 110 | 'phpunit/php-file-iterator' => "{$standard}", 111 | 'phpunit/php-text-template' => "{$standard}", 112 | 'phpunit/php-timer' => "{$standard}", 113 | 'phpunit/php-token-stream' => "{$standard}", 114 | 'phpunit/phpunit' => "{$standard}", 115 | 'phpunit/phpunit-mock-objects' => "{$standard}", 116 | 117 | // Project specific packages 118 | 119 | ) 120 | ); 121 | --------------------------------------------------------------------------------