|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Zikula package. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright Zikula - https://ziku.la/ |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Command\Command; |
|
15
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
20
|
|
|
use Symfony\Component\Finder\Finder; |
|
21
|
|
|
use Symfony\Component\Finder\SplFileInfo as SfSplFileInfo; |
|
22
|
|
|
|
|
23
|
|
|
class PurgeVendorsCommand extends Command |
|
24
|
|
|
{ |
|
25
|
|
|
protected function configure() |
|
26
|
|
|
{ |
|
27
|
|
|
$this |
|
28
|
|
|
->setName('build:purge_vendors') |
|
29
|
|
|
->setDescription('Purges tests from vendors') |
|
30
|
|
|
->addUsage('my/package/path/vendor') |
|
31
|
|
|
->addArgument('vendor-dir', InputArgument::REQUIRED, 'Vendors dir, e.g. src/vendor'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
35
|
|
|
{ |
|
36
|
|
|
$dir = $input->getArgument('vendor-dir'); |
|
37
|
|
|
$progress = new ProgressBar($output, 4); |
|
38
|
|
|
$progress->start(); |
|
39
|
|
|
|
|
40
|
|
|
self::cleanVendors($dir, $progress); |
|
41
|
|
|
|
|
42
|
|
|
return 0; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public static function cleanVendors($dir, ProgressBar $progress) |
|
46
|
|
|
{ |
|
47
|
|
|
$filesystem = new Filesystem(); |
|
48
|
|
|
|
|
49
|
|
|
$finder = new Finder(); |
|
50
|
|
|
$finder->in($dir) |
|
51
|
|
|
->directories() |
|
52
|
|
|
->path('.git') |
|
53
|
|
|
->path('tests') |
|
54
|
|
|
->path('Tests') |
|
55
|
|
|
->ignoreDotFiles(false) |
|
56
|
|
|
->ignoreVCS(false); |
|
57
|
|
|
$progress->advance(); |
|
58
|
|
|
|
|
59
|
|
|
$paths = []; |
|
60
|
|
|
/** @var SfSplFileInfo $file */ |
|
61
|
|
|
foreach ($finder as $file) { |
|
62
|
|
|
$paths[] = $file->getRealPath(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$paths = array_unique($paths); |
|
66
|
|
|
rsort($paths); |
|
67
|
|
|
|
|
68
|
|
|
$progress->advance(); |
|
69
|
|
|
$filesystem->chmod($paths, 0777, 0000, true); |
|
70
|
|
|
$progress->advance(); |
|
71
|
|
|
$filesystem->remove($paths); |
|
72
|
|
|
$progress->advance(); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|