-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRoboFile.php
More file actions
215 lines (182 loc) · 8.52 KB
/
RoboFile.php
File metadata and controls
215 lines (182 loc) · 8.52 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
use Symfony\Component\Yaml\Yaml;
class RoboFile extends \Robo\Tasks
{
private $projectProperties;
function __construct() {
$this->projectProperties = $this->getProjectProperties();
}
// Build.
function build() {
// Download Drupal.
$this->_exec('bin/drupal site:new drupalcore ' . $this->projectProperties['properties']['drupal.version']);
$this->taskRsync()
->fromPath('drupalcore/')
->toPath($this->projectProperties['properties']['root'])
->archive()
->verbose()
->compress()
->delete()
->progress()
->humanReadable()
->excludeVcs()
->exclude('autoload.php')
->exclude('composer.json')
->exclude('core')
->exclude('drush')
->exclude('example.gitignore')
->exclude('README.txt')
->exclude('LICENSE.txt')
->exclude('vendor')
->exclude('modules')
->exclude('themes')
->exclude('profiles')
->exclude('sites/default/files')
->run();
$this->_exec('rm -rf drupalcore');
// Config directory.
$this->_exec('rm -r ' . $this->escapeArg( __DIR__ . '/config'));
$this->_exec('mkdir ' . $this->escapeArg(__DIR__ . '/config'));
$this->_exec('mkdir ' . $this->escapeArg(__DIR__ . '/config/active'));
$this->_exec('mkdir ' . $this->escapeArg(__DIR__ . '/config/staging'));
$this->_exec('mkdir ' . $this->escapeArg(__DIR__ . '/config/sync'));
$this->_exec('mkdir -m 777 ' . $this->escapeArg(__DIR__ . '/web/sites/default/files'));
// Config files.
$this->_exec('chmod 755 ' . $this->escapeArg(__DIR__ . '/web/sites/default/'));
$this->_exec('chmod 755 ' . $this->escapeArg(__DIR__ . '/web/sites/default/services.yml'));
$this->_exec('chmod 755 ' . $this->escapeArg(__DIR__ . '/web/sites/default/settings.php'));
$this->_exec('rm ' . $this->escapeArg(__DIR__ . '/web/sites/default/services.yml'));
$this->_exec('rm ' . $this->escapeArg(__DIR__ . '/web/sites/default/settings.php'));
// Append config settings to settings.php and services.yml to manage file configuration.
$this->taskConcat([
__DIR__ . '/web/sites/default/default.services.yml',
__DIR__ . '/base_files/default.services.yml.dist',
])
->to(__DIR__ . '/web/sites/default/services.yml')
->run();
$this->taskConcat([
__DIR__ . '/web/sites/default/default.settings.php',
__DIR__ . '/base_files/default.settings.php.dist',
])
->to(__DIR__ . '/web/sites/default/settings.php')
->run();
$this->taskReplaceInFile(__DIR__ . '/web/sites/default/settings.php')
->from('%%SETTINGS_INSTALL_PROFILE%%')
->to($this->projectProperties['properties']['site.profile'])
->run();
// Drop db.
$dropString = 'mysqldump -u ' . $this->projectProperties['properties']['db.user.name'] . ' -p' . $this->projectProperties['properties']['db.user.pass'];
$dropString .= ' ' . $this->projectProperties['properties']['db.name'] . ' --no-data -h ' . $this->projectProperties['properties']['db.host'];
$dropString .= ' -P ' . $this->projectProperties['properties']['db.port'];
$dropString .=' | grep ^DROP | mysql -u ';
$dropString .= $this->projectProperties['properties']['db.user.name'] . ' -p' . $this->projectProperties['properties']['db.user.pass'];
$dropString .= ' -h ' . $this->projectProperties['properties']['db.host'];
$dropString .= ' -P ' . $this->projectProperties['properties']['db.port'];
$dropString .= ' --one-database ' . $this->projectProperties['properties']['db.name'];
$this->_exec($dropString);
// Install Drupal.
$this->_exec('bin/drupal site:install ' . $this->projectProperties['params'] . ' ' . $this->projectProperties['properties']['site.profile']);
// Update dependencies.
$this->taskComposerUpdate()->run();
// Contrib modules.
$this->installContribModules();
// Contrib themes.
$this->installContribThemes();
// Languages.
$this->enableLanguages();
// Custom modules.
$this->installCustomModules();
// Custom themes.
$this->installCustomThemes();
$this->say('Build complete');
}
private function getProjectProperties() {
// Parse the properties file.
$properties_file = @file_get_contents(__DIR__ . '/properties.yml');
if ($properties_file === FALSE) {
throw new \Robo\Exception\TaskException(__CLASS__, "Properties file does not exist");
}
$properties = Yaml::parse($properties_file);
$properties['root'] = __DIR__ . '/' . $properties['root'];
$properties['escaped_root_path'] = $this->escapeArg($properties['root']);
$arr_arguments = array(
'--langcode=' => $properties['site.langcode'],
'--db-type=' => $properties['db.type'],
'--db-host=' => $properties['db.host'],
'--db-name=' => $properties['db.name'],
'--db-user=' => $properties['db.user.name'],
'--db-pass=' => $properties['db.user.pass'],
'--db-prefix=' => $properties['db.prefix'],
'--db-port=' => $properties['db.port'],
'--site-name=' => $properties['site.name'],
'--site-mail=' => $properties['site.mail'],
'--account-name=' => $properties['site.account.name'],
'--account-mail=' => $properties['site.account.mail'],
'--account-pass=' => $properties['site.account.pass'],
'--env=' => $properties['env'],
'--root=' => $properties['root'],
);
$params_string = '';
foreach ($arr_arguments as $key => $value) {
$params_string .= $key . '"' . $value . '" ';
}
return array(
'properties' => $properties,
'params' => $params_string,
);
}
// Enable languages.
private function enableLanguages() {
if (isset($this->projectProperties['properties']['languages']) &&
count($this->projectProperties['properties']['languages']) !== 0) {
foreach ($this->projectProperties['properties']['languages'] as $language) {
$this->_exec('bin/drupal locale:language:add --root=' . $this->projectProperties['properties']['escaped_root_path'] . ' -e=' . $this->projectProperties['properties']['env'] . ' ' . $language)->stopOnFail();
}
}
}
// Install contrib modules.
private function installContribModules() {
if (isset($this->projectProperties['properties']['modules']['contrib']) &&
count($this->projectProperties['properties']['modules']['contrib']) !== 0) {
foreach ($this->projectProperties['properties']['modules']['contrib'] as $module) {
$this->_exec('bin/drupal module:install --root=' . $this->projectProperties['properties']['escaped_root_path'] . ' -e=' . $this->projectProperties['properties']['env'] . ' ' . $module)->stopOnFail();
}
}
}
// Install custom modules.
private function installCustomModules() {
if (isset($this->projectProperties['properties']['modules']['custom']) &&
count($this->projectProperties['properties']['modules']['custom']) !== 0) {
foreach ($this->projectProperties['properties']['modules']['custom'] as $module) {
$this->_exec('bin/drupal module:install --root=' . $this->projectProperties['properties']['escaped_root_path'] . ' -e=' . $this->projectProperties['properties']['env'] . ' --overwrite-config ' . $module)->stopOnFail();
}
}
}
// Install contrib themes.
private function installContribThemes() {
if (isset($this->projectProperties['properties']['themes']['contrib']) &&
count($this->projectProperties['properties']['themes']['contrib']) !== 0) {
foreach ($this->projectProperties['properties']['themes']['contrib'] as $theme) {
$this->_exec('bin/drupal theme:install --root=' . $this->projectProperties['properties']['escaped_root_path'] . ' -e=' . $this->projectProperties['properties']['env'] . ' ' . $theme)->stopOnFail();
}
}
}
// Install custom themes.
private function installCustomThemes() {
if (isset($this->projectProperties['properties']['themes']['custom']) &&
count($this->projectProperties['properties']['themes']['custom']) !== 0) {
foreach ($this->projectProperties['properties']['themes']['custom'] as $theme) {
$this->_exec('bin/drupal theme:install --root=' . $this->projectProperties['properties']['escaped_root_path'] . ' -e=' . $this->projectProperties['properties']['env'] . ' ' . $theme)->stopOnFail();
}
}
}
// See Symfony\Component\Console\Input.
private function escapeArg($string) {
return preg_match('{^[\w-]+$}', $string) ? $string : escapeshellarg($string);
}
}