1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Recca0120\Terminal\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Filesystem\Filesystem; |
6
|
|
|
use Illuminate\Support\Collection; |
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use Webmozart\Glob\Glob; |
9
|
|
|
|
10
|
|
|
class Cleanup extends Command |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The console command name. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $name = 'cleanup'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'cleanup vendor folder'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* $files. |
28
|
|
|
* |
29
|
|
|
* @var Filesystem |
30
|
|
|
*/ |
31
|
|
|
protected $files; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* __construct. |
35
|
|
|
* |
36
|
|
|
* @param Filesystem $files |
37
|
1 |
|
*/ |
38
|
|
|
public function __construct(Filesystem $files) |
39
|
1 |
|
{ |
40
|
|
|
parent::__construct(); |
41
|
1 |
|
|
42
|
1 |
|
$this->files = $files; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Handle the command. |
47
|
|
|
* |
48
|
|
|
* @throws InvalidArgumentException |
49
|
1 |
|
*/ |
50
|
|
|
public function handle() |
51
|
1 |
|
{ |
52
|
1 |
|
set_time_limit(0); |
53
|
1 |
|
$root = function_exists('base_path') === true ? base_path() : getcwd(); |
54
|
|
|
$root = rtrim($root, '/').'/'; |
55
|
1 |
|
|
56
|
1 |
|
$docs = ['README*', 'CHANGELOG*', 'FAQ*', 'CONTRIBUTING*', 'HISTORY*', 'UPGRADING*', 'UPGRADE*', 'package*', 'demo', 'example', 'examples', 'doc', 'docs', 'readme*']; |
57
|
1 |
|
$tests = ['.travis.yml', '.scrutinizer.yml', 'phpunit.xml*', 'phpunit.php', 'test', 'Test', 'tests', 'Tests', 'travis']; |
58
|
|
|
$vcs = ['.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg']; |
59
|
1 |
|
$others = [ |
60
|
|
|
'vendor', |
61
|
|
|
'.babelrc', |
62
|
|
|
'.editorconfig', |
63
|
|
|
'.eslintrc.*', |
64
|
|
|
'.gitattributes', |
65
|
|
|
'.gitignore', |
66
|
|
|
'.nitpick.json', |
67
|
|
|
'.php_cs', |
68
|
|
|
'.scrutinizer.yml', |
69
|
|
|
'.styleci.yml', |
70
|
|
|
'.travis.yml', |
71
|
|
|
'appveyor.yml', |
72
|
|
|
'package.json', |
73
|
|
|
'phpcs.xml', |
74
|
|
|
'ruleset.xml', |
75
|
|
|
]; |
76
|
1 |
|
$common = [ |
77
|
|
|
'node_modules', |
78
|
|
|
]; |
79
|
1 |
|
|
80
|
1 |
|
(new Collection( |
81
|
1 |
|
Glob::glob($root.'{'.(new Collection(Glob::glob($root.'vendor/*/*'))) |
82
|
1 |
|
->map(function ($item) { |
83
|
1 |
|
return substr($item, strpos($item, 'vendor')); |
84
|
1 |
|
}) |
85
|
|
|
->implode(',').'}/**/{'.(implode(',', array_merge($vcs, $common, $others, $tests, $docs))).'}') |
86
|
1 |
|
)) |
87
|
1 |
|
->merge(Glob::glob($root.'{'.(implode(',', array_merge($vcs, $common))).'}')) |
88
|
1 |
|
->merge([ |
89
|
|
|
$root.'vendor/phpunit', |
90
|
1 |
|
]) |
91
|
1 |
|
->filter() |
92
|
1 |
|
->each(function ($item) { |
93
|
1 |
|
if ($this->files->isDirectory($item) === true) { |
94
|
1 |
|
$this->files->deleteDirectory($item); |
95
|
1 |
|
$this->info('delete directory: '.$item); |
96
|
1 |
|
} elseif ($this->files->isFile($item)) { |
97
|
1 |
|
$this->files->delete($item); |
98
|
|
|
$this->info('delete file: '.$item); |
99
|
1 |
|
} |
100
|
|
|
}); |
101
|
1 |
|
|
102
|
1 |
|
$this->line(''); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|