forked from acquia/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlightning-subprofile
executable file
·70 lines (58 loc) · 2.07 KB
/
lightning-subprofile
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
#!/usr/bin/env php
<?php
if (empty($argv[1])) {
die("You must specify a lightning.extend.yml file. For example: lightning-subprofile ./docroot/sites/example.com/lightning.extend.yml\n");
}
// Get the full, absolute path to the extender file as a way to validate that
// it exists.
$extender = realpath($argv[1]);
if (empty($extender)) {
die($argv[1] . " does not exist.\n");
}
// Go upwards until we find the autoloader, then require it. This is so we can
// use Drupal's YAML parser.
$loop = TRUE;
while ($loop && ! is_file('./vendor/autoload.php')) {
$loop = chdir('..');
}
require_once './vendor/autoload.php';
$extender = file_get_contents($extender);
$extender = \Drupal\Component\Serialization\Yaml::decode($extender);
// Build the Drupal Console command line.
$command = 'lightning:subprofile --no-interaction';
$command .= ' --name="Lightning Extender"';
$command .= ' --machine-name=' . (@$argv[2] ?: 'lightning_extender');
if ($extender['modules']) {
$command .= ' --include=' . implode(',', $extender['modules']);
}
$exclude = [];
if ($extender['lightning_extensions']) {
// There's no easy way to determine the Drupal application root, so we can't
// automatically scan for components. So let's just use a hard-coded list.
$exclude = array_merge($exclude, array_diff(
[
'lightning_layout',
'lightning_media',
'lightning_preview',
'lightning_workflow',
],
$extender['lightning_extensions']
));
}
if ($extender['exclude_components']) {
$exclude = array_merge($exclude, $extender['exclude_components']);
}
if ($exclude) {
$command .= ' --exclude=' . implode(',', $exclude);
}
// If Drupal Console is installed, go ahead and use it to create the sub-profile
// now. Otherwise, ask the user to install it and give them the command to run.
if (is_file('./vendor/drupal/console/bin/drupal')) {
passthru('./vendor/drupal/console/bin/drupal ' . $command);
}
else {
echo <<<END
Drupal Console does not appear to be installed. Install it and run the following command to generate a Lightning subprofile:
/path/to/drupal-console $command
END;
}