|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Thruster\Tool\ProjectGenerator\Console\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
use Symfony\Component\Process\Process; |
|
10
|
|
|
use Thruster\Tool\ProjectGenerator\Console\PackagistAdder; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class EnableCICommand |
|
14
|
|
|
* |
|
15
|
|
|
* @package Thruster\Tool\ProjectGenerator\Console\Command |
|
16
|
|
|
* @author Aurimas Niekis <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class EnableCICommand extends Command |
|
19
|
|
|
{ |
|
20
|
|
|
protected function configure() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->setName('enable:ci') |
|
23
|
|
|
->addOption( |
|
24
|
|
|
'organisation', |
|
25
|
|
|
'o', |
|
26
|
|
|
InputOption::VALUE_OPTIONAL, |
|
27
|
|
|
'GitHub Organisation Name', |
|
28
|
|
|
'ThrusterIO' |
|
29
|
|
|
); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
33
|
|
|
{ |
|
34
|
|
|
$workDir = getcwd(); |
|
35
|
|
|
|
|
36
|
|
|
if (false === file_exists($workDir . '/composer.json')) { |
|
37
|
|
|
$output->writeln('<error>Not a project directory (composer.json is missing)</error>'); |
|
38
|
|
|
|
|
39
|
|
|
return 1; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$composerJson = json_decode(file_get_contents($workDir . '/composer.json'), true); |
|
43
|
|
|
|
|
44
|
|
|
[$vendor, $name] = explode('/', $composerJson['name']); |
|
45
|
|
|
$organisation = $input->getOption('organisation'); |
|
46
|
|
|
|
|
47
|
|
|
$output->write('<info>Enabling Travis on </info>'); |
|
48
|
|
|
$output->writeln('<comment>' . $organisation . '/' . $name . '</comment>'); |
|
49
|
|
|
|
|
50
|
|
|
$this->exec(['travis', 'enable']); |
|
51
|
|
|
|
|
52
|
|
|
$packagistAdder = new PackagistAdder(); |
|
53
|
|
|
|
|
54
|
|
|
return $packagistAdder->execute($output); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function exec(array $args) |
|
58
|
|
|
{ |
|
59
|
|
|
$process = new Process($args); |
|
60
|
|
|
$process->start(); |
|
61
|
|
|
|
|
62
|
|
|
$process->wait(function ($type, $buffer) { |
|
63
|
|
|
echo $buffer; |
|
64
|
|
|
}); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|