Skip to content

Commit 39a4490

Browse files
committed
Refactor
1 parent 56e15aa commit 39a4490

File tree

5 files changed

+87
-99
lines changed

5 files changed

+87
-99
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"name": "barryvdh/laravel-vendor-cleanup",
3-
"description": "",
3+
"description": "A vendor cleanup package, to remove tests and documentation to save space",
4+
"keywords": ["laravel", "vendor", "cleanup"],
5+
"license": "MIT",
46
"authors": [
57
{
68
"name": "Barry vd. Heuvel",

readme.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,23 @@ Note: If you switch from prefer-source (the default composer setting for non-sta
3232
vendor dir and re-download all packages, without the .git history (and greatly reducing filesize).
3333
This will also prevent questions about changed files, because packages with .git history are checked for changes.
3434

35+
When distributing
3536

36-
You can add your own command, when you publish the config file, and add the commands.
37-
Make sure you use single quotes around $TARGET, because that will be replaced by the real value inside the function
37+
You can add your own rules, when you publish the config file.
3838

3939
'commands' => array(
40-
'cd $TARGET/name/package && rm -rf CHANGELOG* phpunit.xml* tests docs',
40+
'name/package' => 'CHANGELOG* phpunit.xml* tests docs',
4141
),
4242

43+
This wil look for `CHANGELOG* phpunit.xml* tests docs` in vendor/name/package and delete them. So this is the same as running:
44+
`cd /path/to/vendor/name/package && rm -rf CHANGELOG* phpunit.xml* tests docs`
45+
4346
If the package is commonly used, please make a PR to add the command to src/Barryvdh/VendorCleanup/VendorCleanupCommand.php
4447

4548
Most of the cleanup commands are based on the SensioDistributionBundle build script;
4649
https://github.com/sensio/SensioDistributionBundle/blob/master/Resources/bin/build.sh
4750

51+
52+
### License
53+
54+
The Laravel Vendor Cleanup Command is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

src/Barryvdh/VendorCleanup/VendorCleanupCommand.php

Lines changed: 59 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
<?php namespace Barryvdh\VendorCleanup;
1+
<?php
2+
/**
3+
* Laravel Vendor Cleanup
4+
*
5+
* @author Barry vd. Heuvel <barryvdh@gmail.com>
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;
212

313
use Illuminate\Console\Command;
414
use Symfony\Component\Console\Input\InputOption;
@@ -22,6 +32,45 @@ class VendorCleanupCommand extends Command
2232
*/
2333
protected $description = 'Cleanup vendor directory.';
2434

35+
protected $rules = array(
36+
'doctrine/annotations' => 'bin tests ',
37+
'doctrine/cache' => 'bin tests',
38+
'doctrine/collections' => 'tests',
39+
'doctrine/common' => 'README* UPGRADE* phpunit.xml* build* tests bin lib/vendor',
40+
'doctrine/dbal' => 'bin build* docs docs2 tests lib/vendor',
41+
'doctrine/inflector' => 'phpunit.xml* README* tests',
42+
'doctrine/collections' => 'tests',
43+
'filp/whoops' => 'README.md phpunit.xml* tests examples',
44+
'ircmaxell/password-compat' => 'README.md test',
45+
'laravel/framework' => 'readme.md phpunit.xml* build tests',
46+
'monolog/monolog' => 'README.markdown phpunit.xml* tests doc',
47+
'nikic/php-parser' => 'README.md CHANGELOG* phpunit.xml* doc test test_old',
48+
'patchwork/utf8' => 'README.md tests',
49+
'predis/predis' => 'README.md CHANGELOG* phpunit.xml* examples tests bin FAQ CONTRIBUTING*',
50+
'swiftmailer/swiftmailer' => 'CHANGES README* build* doc docs notes test-suite tests create_pear_package.php package*',
51+
'symfony/browser-kit/Symfony/Component/BrowserKit' => 'CHANGELOG* README* Tests',
52+
'symfony/console/Symfony/Component/Console' => 'CHANGELOG* README* Tests',
53+
'symfony/css-selector/Symfony/Component/CssSelector' => 'CHANGELOG* README* Tests',
54+
'symfony/debug/Symfony/Component/Debug' => 'CHANGELOG* README* Tests',
55+
'symfony/dom-crawler/Symfony/Component/DomCrawler' => 'CHANGELOG* README* Tests',
56+
'symfony/event-dispatcher/Symfony/Component/EventDispatcher' => 'CHANGELOG* README* Tests',
57+
'symfony/filesystem/Symfony/Component/Filesystem' => 'CHANGELOG* README* Tests',
58+
'symfony/finder/Symfony/Component/Finder' => 'CHANGELOG* README* Tests',
59+
'symfony/http-foundation/Symfony/Component/HttpFoundation' => 'CHANGELOG* README* Tests',
60+
'symfony/http-kernel/Symfony/Component/HttpKernel' => 'CHANGELOG* README* Tests',
61+
'symfony/process/Symfony/Component/Process' => 'CHANGELOG* README* Tests',
62+
'symfony/routing/Symfony/Component/Routing' => 'CHANGELOG* README* Tests',
63+
'symfony/translation/Symfony/Component/Translation' => 'CHANGELOG* README* Tests',
64+
'anahkiasen/former' => 'README* CHANGELOG* CONTRIBUTING* phpunit.xml* tests',
65+
'anahkiasen/html-object' => 'README* CHANGELOG* phpunit.xml* examples tests',
66+
'anahkiasen/underscore-php' => 'README* CHANGELOG* phpunit.xml* tests',
67+
'intervention/image' => 'README* phpunit.xml* public tests',
68+
'jasonlewis/basset' => 'README* phpunit.xml* tests/Basset',
69+
'leafo/lessphp' => 'README* docs tests Makefile package.sh',
70+
'kriswallsmith/assetic' => 'CHANGELOG* phpunit.xml* tests docs',
71+
'mrclay/minify' => 'HISTORY* MIN.txt UPGRADING* README* min_extras min_unit_tests min/builder min/config* min/quick-test* min/utils.php min/groupsConfig.php min/index.php',
72+
);
73+
2574

2675
/**
2776
* Execute the console command.
@@ -30,97 +79,17 @@ class VendorCleanupCommand extends Command
3079
*/
3180
public function fire()
3281
{
33-
$TARGET = realpath($this->argument('dir'));
34-
$this->info("Cleaning dir: $TARGET");
35-
36-
// doctrine
37-
exec("cd $TARGET/doctrine/annotations && rm -rf bin tests ");
38-
exec("cd $TARGET/doctrine/cache && rm -rf bin tests");
39-
exec("cd $TARGET/doctrine/collections && rm -rf tests");
40-
exec("cd $TARGET/doctrine/common && rm -rf README* UPGRADE* phpunit.xml* build* tests bin lib/vendor");
41-
exec("cd $TARGET/doctrine/dbal && rm -rf bin build* docs docs2 tests lib/vendor");
42-
exec("cd $TARGET/doctrine/inflector && rm -rf phpunit.xml* README* tests");
43-
exec("cd $TARGET/doctrine/collections && rm -rf tests");
44-
45-
// filp
46-
exec("cd $TARGET/filp/whoops && rm -rf README.md phpunit.xml* tests examples");
47-
48-
// ircmaxell
49-
exec("cd $TARGET/ircmaxell/password-compat && rm -rf README.md test");
50-
51-
// laravel
52-
exec("cd $TARGET/laravel/framework && rm -rf readme.md phpunit.xml* build tests");
53-
54-
// monolog
55-
exec("cd $TARGET/monolog/monolog && rm -rf README.markdown phpunit.xml* tests doc");
56-
57-
// nikic
58-
exec("cd $TARGET/nikic/php-parser && rm -rf README.md CHANGELOG* phpunit.xml* doc test test_old");
59-
60-
// patchwork
61-
exec("cd $TARGET/patchwork/utf8 && rm -rf README.md tests");
62-
63-
// predis
64-
exec("cd $TARGET/predis/predis && rm -rf README.md CHANGELOG* phpunit.xml* examples tests bin FAQ CONTRIBUTING*");
65-
66-
// swiftmailer
67-
exec("cd $TARGET/swiftmailer/swiftmailer && rm -rf CHANGES README* build* doc docs notes test-suite tests create_pear_package.php package*" );
68-
69-
// symfony
70-
exec("cd $TARGET/symfony/browser-kit/Symfony/Component/BrowserKit && rm -rf CHANGELOG* README* Tests" );
71-
exec("cd $TARGET/symfony/console/Symfony/Component/Console && rm -rf CHANGELOG* README* Tests" );
72-
exec("cd $TARGET/symfony/css-selector/Symfony/Component/CssSelector && rm -rf CHANGELOG* README* Tests" );
73-
exec("cd $TARGET/symfony/debug/Symfony/Component/Debug && rm -rf CHANGELOG* README* Tests" );
74-
exec("cd $TARGET/symfony/dom-crawler/Symfony/Component/DomCrawler && rm -rf CHANGELOG* README* Tests" );
75-
exec("cd $TARGET/symfony/event-dispatcher/Symfony/Component/EventDispatcher && rm -rf CHANGELOG* README* Tests" );
76-
exec("cd $TARGET/symfony/filesystem/Symfony/Component/Filesystem && rm -rf CHANGELOG* README* Tests" );
77-
exec("cd $TARGET/symfony/finder/Symfony/Component/Finder && rm -rf CHANGELOG* README* Tests" );
78-
exec("cd $TARGET/symfony/http-foundation/Symfony/Component/HttpFoundation && rm -rf CHANGELOG* README* Tests" );
79-
exec("cd $TARGET/symfony/http-kernel/Symfony/Component/HttpKernel && rm -rf CHANGELOG* README* Tests" );
80-
exec("cd $TARGET/symfony/process/Symfony/Component/Process && rm -rf CHANGELOG* README* Tests" );
81-
exec("cd $TARGET/symfony/routing/Symfony/Component/Routing && rm -rf CHANGELOG* README* Tests" );
82-
exec("cd $TARGET/symfony/translation/Symfony/Component/Translation && rm -rf CHANGELOG* README* Tests" );
83-
84-
// anahkiasen
85-
if(file_exists("$TARGET/anahkiasen/former")){
86-
exec("cd $TARGET/anahkiasen/former && rm -rf README* CHANGELOG* CONTRIBUTING* phpunit.xml* tests");
87-
}
88-
if(file_exists("$TARGET/anahkiasen/html-object")){
89-
exec("cd $TARGET/anahkiasen/html-object && rm -rf README* CHANGELOG* phpunit.xml* examples tests");
90-
}
91-
if(file_exists("$TARGET/anahkiasen/underscore-php")){
92-
exec("cd $TARGET/anahkiasen/underscore-php && rm -rf README* CHANGELOG* phpunit.xml* tests");
93-
}
94-
95-
// intervention
96-
if(file_exists("$TARGET/intervention/image")){
97-
exec("cd $TARGET/intervention/image && rm -rf README* phpunit.xml* public tests");
98-
}
99-
100-
# jasonlewis
101-
if(file_exists("$TARGET/jasonlewis/basset")){
102-
exec("cd $TARGET/jasonlewis/basset && rm -rf README* phpunit.xml* tests/Basset");
103-
}
104-
105-
// leafo
106-
if(file_exists("$TARGET/leafo/lessphp")){
107-
exec("cd $TARGET/leafo/lessphp && rm -rf README* docs tests Makefile package.sh");
108-
}
109-
110-
// kriswallsmith
111-
if(file_exists("$TARGET/kriswallsmith/assetic")){
112-
exec("cd $TARGET/kriswallsmith/assetic && rm -rf CHANGELOG* phpunit.xml* tests docs");
113-
}
114-
115-
// mrclay
116-
if(file_exists("$TARGET/mrclay/minify")){
117-
exec("cd $TARGET/mrclay/minify && rm -rf HISTORY* MIN.txt UPGRADING* README* min_extras min_unit_tests min/builder min/config* min/quick-test* min/utils.php min/groupsConfig.php min/index.php");
118-
}
82+
$vendorDir = realpath($this->argument('dir'));
83+
$this->info("Cleaning dir: $vendorDir");
11984

85+
$rules = $this->rules;
86+
$rules += \Config::get('laravel-vendor-cleanup::rules');
12087

121-
foreach(\Config::get('laravel-vendor-cleanup::commands', array()) as $command){
122-
$command = str_replace('$TARGET', $TARGET, $command);
123-
exec($command);
88+
foreach($rules as $packageDir => $rule){
89+
$TARGET = $vendorDir . '/' . $packageDir;
90+
if($packageDir && $rule && file_exists($TARGET)){
91+
exec("cd $TARGET && rm -rf $rule");
92+
}
12493
}
12594
}
12695

src/Barryvdh/VendorCleanup/VendorCleanupServiceProvider.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
<?php namespace Barryvdh\VendorCleanup;
1+
<?php
2+
/**
3+
* Laravel Vendor Cleanup
4+
*
5+
* @author Barry vd. Heuvel <barryvdh@gmail.com>
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;
212

313
use Illuminate\Support\ServiceProvider;
414

src/config/config.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
/*
1717
|--------------------------------------------------------------------------
18-
| Commands
18+
| Rules
1919
|--------------------------------------------------------------------------
2020
|
21-
| Additional commands, to do your own cleanups
21+
| Additional rules, to do your own cleanups
2222
|
2323
*/
2424

25-
'commands' => array(
26-
//'cd $TARGET/name/package && rm -rf CHANGELOG* phpunit.xml* tests docs',
25+
'rules' => array(
26+
'name/package' => 'README.md tests/*',
2727
),
2828

2929

0 commit comments

Comments
 (0)