Repository: barryvdh/composer-cleanup-plugin Branch: master Commit: d7bfbe026ac5 Files: 5 Total size: 14.2 KB Directory structure: gitextract_lijcdq0e/ ├── .gitignore ├── README.md ├── composer.json └── src/ ├── CleanupPlugin.php └── CleanupRules.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ /vendor /.idea composer.phar composer.lock .DS_Store ================================================ FILE: README.md ================================================ Composer Cleanup Plugin ======================= Remove tests & documentation from the vendor dir. Based on [laravel-vendor-cleanup](https://github.com/barryvdh/laravel-vendor-cleanup) but implemented as a Composer Plugin instead of a Laravel command. Usually disk size shouldn't be a problem, but when you have to use FTP to deploy or have very limited disk space, you can use this package to cut down the vendor directory by deleting files that aren't used in production (tests/docs etc). > **Note:** This package is abandoned. Packages should add files they want to exclude to .gitattributes ## Install Require this package in your composer.json: "barryvdh/composer-cleanup-plugin": "0.4.x" ## Usage This plugin will work automatically on any packages installed as `dist`. Therefore, if you are using it to build a package archive, simply run `composer install` with the `--prefer-dist` option. ## What does it do? For every installed or updated package in the default list, in general: 1. Remove documentation, such as README files, docs folders, etc. 2. Remove tests, PHPUnit configs, and other build/CI configuration. Some packages don't obey the general rules, and remove more/less files. Packages that do not have rules added are ignored. ## Adding rules Please submit a PR to [src/CleanupRules.php] to add more rules for packages. Make sure you test them first, sometimes tests dirs are classmapped and will error when deleted. [src/CleanupRules.php]: ./src/CleanupRules.php ================================================ FILE: composer.json ================================================ { "name": "barryvdh/composer-cleanup-plugin", "type": "composer-plugin", "description": "A composer cleanup plugin, to remove tests and documentation to save space", "license": "MIT", "authors": [ { "name": "Barry vd. Heuvel", "email": "barryvdh@gmail.com" } ], "require": { "composer-plugin-api": "^2.0" }, "require-dev": { "composer/composer": "^2.0" }, "autoload": { "psr-4": { "Barryvdh\\Composer\\": "src/" } }, "extra": { "branch-alias": { "dev-master": "0.3-dev" }, "class": "Barryvdh\\Composer\\CleanupPlugin" } } ================================================ FILE: src/CleanupPlugin.php ================================================ composer = $composer; $this->io = $io; $this->config = $composer->getConfig(); $this->filesystem = new Filesystem(); $this->rules = CleanupRules::getRules(); } /** * {@inheritDoc} */ public function deactivate(Composer $composer, IOInterface $io) { // } /** * {@inheritDoc} */ public function uninstall(Composer $composer, IOInterface $io) { // } /** * {@inheritDoc} */ public static function getSubscribedEvents() { return array( 'post-package-install' => 'onPostPackageInstall', 'post-package-update' => 'onPostPackageUpdate', /*ScriptEvents::POST_INSTALL_CMD => array( array('onPostInstallUpdateCmd', 0) ), ScriptEvents::POST_UPDATE_CMD => array( array('onPostInstallUpdateCmd', 0) ),*/ ); } /** * Function to run after a package has been installed */ public function onPostPackageInstall(PackageEvent $event) { /** @var \Composer\Package\CompletePackage $package */ $package = $event->getOperation()->getPackage(); $this->cleanPackage($package); } /** * Function to run after a package has been updated */ public function onPostPackageUpdate(PackageEvent $event) { /** @var \Composer\Package\CompletePackage $package */ $package = $event->getOperation()->getTargetPackage(); $this->cleanPackage($package); } /** * Function to run after a package has been updated * * @param CommandEvent $event */ public function onPostInstallUpdateCmd(CommandEvent $event) { /** @var \Composer\Repository\WritableRepositoryInterface $repository */ $repository = $this->composer->getRepositoryManager()->getLocalRepository(); /** @var \Composer\Package\CompletePackage $package */ foreach($repository->getPackages() as $package){ if ($package instanceof BasePackage) { $this->cleanPackage($package); } } } /** * Clean a package, based on its rules. * * @param BasePackage $package The package to clean * @return bool True if cleaned */ protected function cleanPackage(BasePackage $package) { // Only clean 'dist' packages if ($package->getInstallationSource() !== 'dist') { return false; } $vendorDir = $this->config->get('vendor-dir'); $targetDir = $package->getTargetDir(); $packageName = $package->getPrettyName(); $packageDir = $targetDir ? $packageName . '/' . $targetDir : $packageName ; $rules = isset($this->rules[$packageName]) ? $this->rules[$packageName] : null; if(!$rules){ return; } $dir = $this->filesystem->normalizePath(realpath($vendorDir . '/' . $packageDir)); if (!is_dir($dir)) { return false; } foreach((array) $rules as $part) { // Split patterns for single globs (should be max 260 chars) $patterns = explode(' ', trim($part)); foreach ($patterns as $pattern) { try { foreach (glob($dir.'/'.$pattern) as $file) { $this->filesystem->remove($file); } } catch (\Exception $e) { $this->io->write("Could not parse $packageDir ($pattern): ".$e->getMessage()); } } } return true; } } ================================================ FILE: src/CleanupRules.php ================================================ array($docs, $tests, 'fonts'), 'anahkiasen/former' => array($docs, $tests), 'anahkiasen/html-object' => array($docs, 'phpunit.xml* tests/*'), 'anahkiasen/rocketeer' => array($docs, $tests), 'anahkiasen/underscore-php' => array($docs, $tests), 'aws/aws-sdk-php' => array($docs, $tests), 'barryvdh/composer-cleanup-plugin' => array($docs, $tests), 'barryvdh/laravel-debugbar' => array($docs, $tests), 'barryvdh/laravel-ide-helper' => array($docs, $tests), 'bllim/datatables' => array($docs, $tests), 'cartalyst/sentry' => array($docs, $tests), 'classpreloader/classpreloader' => array($docs, $tests), 'd11wtq/boris' => array($docs, $tests), 'danielstjules/stringy' => array($docs, $tests), 'dflydev/markdown' => array($docs, $tests), 'dnoegel/php-xdg-base-dir' => array($docs, $tests), 'doctrine/annotations' => array($docs, $tests, 'bin'), 'doctrine/cache' => array($docs, $tests, 'bin'), 'doctrine/collections' => array($docs, $tests), 'doctrine/common' => array($docs, $tests, 'bin lib/vendor'), 'doctrine/dbal' => array($docs, $tests, 'bin build* docs2 lib/vendor'), 'doctrine/inflector' => array($docs, $tests), 'dompdf/dompdf' => array($docs, $tests, 'www'), 'filp/whoops' => array($docs, $tests), 'guzzle/guzzle' => array($docs, $tests), 'guzzlehttp/guzzle' => array($docs, $tests), 'guzzlehttp/oauth-subscriber' => array($docs, $tests), 'guzzlehttp/streams' => array($docs, $tests), 'imagine/imagine' => array($docs, $tests, 'lib/Imagine/Test'), 'intervention/image' => array($docs, $tests, 'public'), 'ircmaxell/password-compat' => array($docs, $tests), 'jakub-onderka/php-console-color' => array($docs, $tests, 'build.xml example.php'), 'jakub-onderka/php-console-highlighter' => array($docs, $tests, 'build.xml'), 'jasonlewis/basset' => array($docs, $tests), 'jeremeamia/SuperClosure' => array($docs, $tests, 'demo'), 'kriswallsmith/assetic' => array($docs, $tests), 'laravel/framework' => array($docs, $tests, 'build'), 'leafo/lessphp' => array($docs, $tests, 'Makefile package.sh'), 'league/flysystem' => array($docs, $tests), 'league/stack-robots' => array($docs, $tests), 'maximebf/debugbar' => array($docs, $tests, 'demo'), 'mccool/laravel-auto-presenter' => array($docs, $tests), 'mockery/mockery' => array($docs, $tests), 'monolog/monolog' => array($docs, $tests), 'mrclay/minify' => array($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'), 'mtdowling/cron-expression' => array($docs, $tests), 'mustache/mustache' => array($docs, $tests, 'bin'), 'nesbot/carbon' => array($docs, $tests), 'nikic/php-parser' => array($docs, $tests, 'test_old'), 'oyejorge/less.php' => array($docs, $tests), 'patchwork/utf8' => array($docs, $tests), 'phenx/php-font-lib' => array($docs, $tests. 'www'), 'phpdocumentor/reflection-docblock' => array($docs, $tests), 'phpoffice/phpexcel' => array($docs, $tests, 'Examples unitTests changelog.txt'), 'phpoffice/phpspreadsheet' => array($docs, $tests, 'samples'), 'phpseclib/phpseclib' => array($docs, $tests, 'build'), 'predis/predis' => array($docs, $tests, 'bin'), 'psr/log' => array($docs, $tests), 'psy/psysh' => array($docs, $tests), 'quickbooks/v3-php-sdk' => array($docs, $tests, 'docs docs/* src/XSD2PHP/test src/XSD2PHP/test/*'), 'rcrowe/twigbridge' => array($docs, $tests), 'simplepie/simplepie' => array($docs, $tests, 'build compatibility_test ROADMAP.md'), 'stack/builder' => array($docs, $tests), 'swiftmailer/swiftmailer' => array($docs, $tests, 'build* notes test-suite create_pear_package.php'), 'symfony/browser-kit' => array($docs, $tests), 'symfony/class-loader' => array($docs, $tests), 'symfony/console' => array($docs, $tests), 'symfony/css-selector' => array($docs, $tests), 'symfony/debug' => array($docs, $tests), 'symfony/dom-crawler' => array($docs, $tests), 'symfony/event-dispatcher' => array($docs, $tests), 'symfony/filesystem' => array($docs, $tests), 'symfony/finder' => array($docs, $tests), 'symfony/http-foundation' => array($docs, $tests), 'symfony/http-kernel' => array($docs, $tests), 'symfony/process' => array($docs, $tests), 'symfony/routing' => array($docs, $tests), 'symfony/security' => array($docs, $tests), 'symfony/security-core' => array($docs, $tests), 'symfony/translation' => array($docs, $tests), 'symfony/var-dumper' => array($docs, $tests), 'tijsverkoyen/css-to-inline-styles' => array($docs, $tests), 'twig/twig' => array($docs, $tests), 'venturecraft/revisionable' => array($docs, $tests), 'vlucas/phpdotenv' => array($docs, $tests), 'willdurand/geocoder' => array($docs, $tests), 'willdurand/geocoder' => array($docs, $tests), ); } }