|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Del\Booty; |
|
4
|
|
|
|
|
5
|
|
|
use Composer\Autoload\ClassLoader; |
|
6
|
|
|
use Symfony\Component\Console\Command\Command; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
|
|
10
|
|
|
class BootyCommand extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var array */ |
|
13
|
|
|
private $packages; |
|
14
|
|
|
|
|
15
|
|
|
/** @var AssetManager $booty */ |
|
16
|
|
|
private $booty; |
|
17
|
|
|
|
|
18
|
|
|
/** @var ClassLoader $composer */ |
|
19
|
|
|
private $composer; |
|
20
|
|
|
|
|
21
|
|
|
/** @var string $destination */ |
|
22
|
|
|
private $destination = 'public/'; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct(string $name = null, array $packages, ClassLoader $composer) |
|
25
|
|
|
{ |
|
26
|
|
|
parent::__construct($name); |
|
27
|
|
|
$this->packages = $packages; |
|
28
|
|
|
$this->booty = new AssetManager(); |
|
29
|
|
|
$this->composer = $composer; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function configure() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::configure(); |
|
35
|
|
|
$this->setName('deploy'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param InputInterface $input |
|
40
|
|
|
* @param OutputInterface $output |
|
41
|
|
|
* @return int|void|null |
|
42
|
|
|
*/ |
|
43
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->booty->setDestinationFolder($this->destination); |
|
46
|
|
|
foreach ($this->packages as $package) { |
|
47
|
|
|
$moduleName = str_replace('Package', '', $package); |
|
48
|
|
|
$moduleName = end(explode('\\', $moduleName)); |
|
|
|
|
|
|
49
|
|
|
$file = realpath($this->composer->findFile($package)); |
|
50
|
|
|
$folder = dirname($file); |
|
51
|
|
|
$folder = substr($folder, -4) == '/src' ? substr($folder, 0, -4) : $folder; |
|
52
|
|
|
|
|
53
|
|
|
if (file_exists($folder . '/assets')) { |
|
54
|
|
|
$output->writeln('Adding assets from ' . $moduleName . ' module..'); |
|
55
|
|
|
$this->booty->addAssetsFolder($moduleName, $folder . '/assets'); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
$output->writeln('Deploying assets to ' . $this->destination); |
|
59
|
|
|
$this->booty->deployAssets(); |
|
60
|
|
|
} |
|
61
|
|
|
} |