-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPackageScriptsExtractor.php
More file actions
59 lines (48 loc) · 1.71 KB
/
Copy pathPackageScriptsExtractor.php
File metadata and controls
59 lines (48 loc) · 1.71 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
<?php
namespace ScriptsDev;
use Composer\IO\IOInterface;
use Composer\Package\CompletePackage;
use Composer\Package\PackageInterface;
class PackageScriptsExtractor
{
/**
* @var IOInterface
*/
private $io;
protected static $warningPrinted = false;
public function __construct(IOInterface $io)
{
$this->io = $io;
}
/**
* @param PackageInterface $package
* @return array
*/
public function extract(PackageInterface $package)
{
if ($package instanceof CompletePackage && isset($_SERVER['argv']) && in_array('--no-dev', $_SERVER['argv'], true)) {
return array();
}
$devScripts = array();
$config = json_decode(file_get_contents(getcwd() . '/composer.json'), true);
if (isset($config['scripts-dev']) && is_array($config['scripts-dev'])) {
if (!static::$warningPrinted) {
$this->io->writeError(
"<warning>You're using deprecated way to define development-only scripts.
Please, move commands under `scripts-dev` directive into `extra` field.
See https://github.com/neronmoon/scriptsdev/blob/master/README.md for more details.</warning>"
);
static::$warningPrinted = true;
}
$devScripts = array_merge_recursive($devScripts, $config['scripts-dev']);
}
$extra = $package->getExtra();
if (isset($extra['scripts-dev']) && is_array($extra['scripts-dev'])) {
$devScripts = array_merge_recursive($devScripts, $extra['scripts-dev']);
}
foreach ($devScripts as $event => &$listeners) {
$listeners = (array)$listeners;
}
return $devScripts;
}
}