-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPlugin.php
More file actions
39 lines (32 loc) · 1.2 KB
/
Copy pathPlugin.php
File metadata and controls
39 lines (32 loc) · 1.2 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
<?php
namespace ScriptsDev;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Package\CompletePackage;
use Composer\Plugin\PluginInterface;
class Plugin implements PluginInterface
{
public function activate(Composer $composer, IOInterface $io)
{
$package = $composer->getPackage();
if ($package instanceof CompletePackage && in_array('--no-dev', $_SERVER['argv'], true)) {
return;
}
$devScripts = array();
$config = json_decode(file_get_contents(getcwd() . '/composer.json'), true);
if (isset($config['scripts-dev']) && is_array($config['scripts-dev'])) {
$io->writeError("You're using deprecated way to define development-only scripts.
Please, move commands under `scripts-dev` directive into `extra` field.
See README.md for more details.");
$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;
}
$package->setScripts(array_merge_recursive($package->getScripts(), $devScripts));
}
}