|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; |
|
4
|
|
|
|
|
5
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\ComposerJsonFixes; |
|
6
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Updates the composer requirements to reflect the new version and package names |
|
10
|
|
|
* in the composer file of your module |
|
11
|
|
|
*/ |
|
12
|
|
|
class AddVendorExposeDataToComposer extends Task |
|
13
|
|
|
{ |
|
14
|
|
|
protected $taskStep = 's50'; |
|
15
|
|
|
|
|
16
|
|
|
protected $toExpose = [ |
|
17
|
|
|
'javascript', |
|
18
|
|
|
'images', |
|
19
|
|
|
'img', |
|
20
|
|
|
'css', |
|
21
|
|
|
'fonts', |
|
22
|
|
|
'js', |
|
23
|
|
|
'client/javascript', |
|
24
|
|
|
'client/images', |
|
25
|
|
|
'client/img', |
|
26
|
|
|
'client/css', |
|
27
|
|
|
'client/fonts', |
|
28
|
|
|
'client/js', |
|
29
|
|
|
]; |
|
30
|
|
|
|
|
31
|
|
|
public function getTitle() |
|
32
|
|
|
{ |
|
33
|
|
|
return 'Adds vendor expose data to composer'; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getDescription() |
|
37
|
|
|
{ |
|
38
|
|
|
return ' |
|
39
|
|
|
By default we expose all the client related files (images, css and javascript)'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function runActualTask($params = []): ?string |
|
43
|
|
|
{ |
|
44
|
|
|
$expose = []; |
|
45
|
|
|
foreach ($this->mu()->getExistingModuleDirLocations() as $moduleDir) { |
|
|
|
|
|
|
46
|
|
|
foreach ($this->toExpose as $folder) { |
|
47
|
|
|
if (file_exists($moduleDir . '/' . $folder)) { |
|
48
|
|
|
if ($this->mu()->getIsModuleUpgrade()) { |
|
|
|
|
|
|
49
|
|
|
//expose "javascript" |
|
50
|
|
|
$expose[] = $folder; |
|
51
|
|
|
} else { |
|
52
|
|
|
//expose "app/javascript" |
|
53
|
|
|
$expose[] = basename($moduleDir) . '/' . $folder; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
if (count($expose)) { |
|
59
|
|
|
$command = |
|
60
|
|
|
'if(!isset($data["extra"]["expose"])) { ' |
|
61
|
|
|
. ' $data["extra"]["expose"] = ["' . implode('", "', $expose) . '"]; ' |
|
62
|
|
|
. '}'; |
|
63
|
|
|
ComposerJsonFixes::inst($this->mu())->UpdateJSONViaCommandLine( |
|
64
|
|
|
$this->mu()->getGitRootDir(), |
|
|
|
|
|
|
65
|
|
|
$command, |
|
66
|
|
|
'exposing: ' . implode(', ', $expose) |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
$this->setCommitMessage('API: exposing folders' . implode(',', $expose)); |
|
70
|
|
|
} |
|
71
|
|
|
return null; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
protected function hasCommitAndPush() |
|
75
|
|
|
{ |
|
76
|
|
|
return true; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|