-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFullCheckProject.php
More file actions
85 lines (73 loc) · 1.81 KB
/
Copy pathFullCheckProject.php
File metadata and controls
85 lines (73 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* @author Donii Sergii <s.donii@infomir.com>
*/
namespace Smac\Check;
require __DIR__.'/vendor/autoload.php';
use Symfony\Component\Process\Process;
/**
* Class FullCheckProject
* Run all scripts from composer.json.
*/
class FullCheckProject
{
/**
* Scripts list from composer.json.
*
* @var array
*/
private $scripts = [];
private $ignore = ['php FullCheckProject.php'];
/**
* Path to composer.json.
*
* @var string
*/
private $file;
/**
* FullCheckProject constructor.
*
*
* @param string $file
*
* @throws \Exception
*/
public function __construct($file = null)
{
$file = $file ?: __DIR__.'/composer.json';
$config = \json_decode(
\file_get_contents($file),
true
);
$this->file = $file;
if (!isset($config['scripts'])) {
throw new \Exception('Composer scripts is empty');
}
$this->scripts = $config['scripts'];
}
/**
* Run check.
*
* @throws \Symfony\Component\Process\Exception\RuntimeException
* @throws \Exception
*/
public function run()
{
$path = \dirname($this->file);
foreach ($this->scripts as $script) {
if (\in_array($script, $this->ignore ?? [], false)) {
continue;
}
$command = "cd {$path}; {$script}";
/** @var Process $process */
$process = new Process($command);
$process->run();
if (0 !== (int) $process->wait()) {
echo $process->getOutput();
throw new \Exception("Script $command run with error. Check it first");
}
echo $process->getOutput();
}
}
}
(new FullCheckProject())->run();