-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoboFile.php
More file actions
295 lines (248 loc) · 6.39 KB
/
RoboFile.php
File metadata and controls
295 lines (248 loc) · 6.39 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?php
use Robo\Tasks;
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends Tasks
{
/**
* @var string Production environment
*/
const ENV_PROD = 'prod';
/**
* @var string Development environment
*/
const ENV_DEV = 'dev';
/**
* @var string Node modules binary directory
*/
protected $npmBin = 'node_modules/.bin';
/**
* @var string Composer Packages binary directory
*/
protected $composerBin = 'vendor/bin';
/**
* @var string Symfony binary file
*/
protected $symfonyBin = 'bin/console';
/**
* @var string Source code directory
*/
protected $srcDir = 'src';
/**
* @var string Tests directory
*/
protected $testsDir = 'tests';
/**
* @var string Build directory for QA reports
*/
protected $buildDir = 'build';
/**
* First install command
*
* @param string $env
* @return bool
*/
public function setupInstall($env = self::ENV_DEV)
{
$task = $this->taskComposerInstall();
if (self::ENV_PROD === $env) {
$task->noDev()->optimizeAutoloader();
putenv('SYMFONY_ENV=prod');
}
$result = $task->run();
if (!$result->wasSuccessful()) {
$this->say('Aborting installation due to some errors');
return false;
}
$this->taskNpmInstall()->run();
$this->databaseInstall();
$this->cacheClear($env);
}
/**
* Run server with hot reload
*
* @param string $env
* @return bool
*/
public function setupRun($env = self::ENV_DEV)
{
if ($env !== self::ENV_DEV) {
return;
}
$this->taskExec("$this->symfonyBin server:run 0.0.0.0:8100")->background()->run();
$this->taskExec("npm run serve")->run();
}
/**
* Clears Symfony cache
*
* @param string $env
*/
public function cacheClear($env = self::ENV_DEV)
{
$task = $this->taskExec("$this->symfonyBin cache:clear")->options(['ansi' => null, 'no-warmup' => null]);
if (self::ENV_PROD === $env) {
$task->option('no-debug')->option('env', 'prod');
}
$task->run();
}
/**
* Reloads the database
*/
public function databaseInstall($env = self::ENV_DEV)
{
if ($env !== self::ENV_DEV) {
return;
}
$this->taskExec("$this->symfonyBin doctrine:database:drop")->option('quiet')->option('force')->run();
$this->taskExec("$this->symfonyBin doctrine:database:create")->option('quiet')->run();
$this->taskExec("$this->symfonyBin doctrine:schema:update")->option('force')->run();
$this->taskExec("$this->symfonyBin hautelook:fixtures:load")->option('quiet')->run();
}
/**
* Runs QA tools
*
* @param bool $parallel
*/
public function qaBuild($parallel = false)
{
$this->qaClean();
$this->qaPrepare();
$tasks = [
$this->qaPdepend(false),
$this->qaPhpmd(false),
$this->qaPhpcpd(false),
$this->qaPhploc(false),
$this->qaPhpcs(false)
];
$tasks[] = $this
->taskExec("$this->npmBin/eslint")
->arg($this->srcDir)
->option('--color');
if (false === $parallel) {
foreach ($tasks as $task) {
$task->run();
}
return;
}
$stack = $this->taskParallelExec();
foreach ($tasks as $task) {
$stack->process($task);
}
$stack->run();
}
/**
* Cleans QA reports directory
*/
public function qaClean()
{
$this
->taskExec("rm -Rf $this->buildDir")
->run();
}
/**
* Creates QA reports directory scaffolding
*/
public function qaPrepare()
{
$this
->taskExec("mkdir -p $this->buildDir/logs")
->taskExec("mkdir -p $this->buildDir/pdepend")
->taskExec("mkdir -p $this->buildDir/phploc")
->run();
}
/**
* Runs pdepend
*
* @param bool $run
*
* @return $this|\Robo\Result
*/
public function qaPdepend($run = true)
{
$task = $this
->taskExec("$this->composerBin/pdepend")
->option("--jdepend-xml=$this->buildDir/logs/jdepend.xml")
->option("--jdepend-chart=$this->buildDir/pdepend/dependencies.svg")
->option("--overview-pyramid=$this->buildDir/pdepend/overview-pyramid.svg")
->arg($this->srcDir);
if ($run) {
return $task->run();
}
return $task;
}
/**
* Runs phpmd
*
* @param bool $run
* @return $this|\Robo\Result
*/
public function qaPhpmd($run = true)
{
$task = $this
->taskExec("$this->composerBin/phpmd")
->arg($this->srcDir)
->arg('text')
->arg("phpmd.xml");
if ($run) {
return $task->run();
}
return $task;
}
/**
* Runs phpcpd
*
* @param bool $run
* @return $this|\Robo\Result
*/
public function qaPhpcpd($run = true)
{
$task = $this
->taskExec("$this->composerBin/phpcpd")
->arg($this->srcDir);
if ($run) {
return $task->run();
}
return $task;
}
/**
* Runs phploc
*
* @param bool $run
* @return $this|\Robo\Result
*/
public function qaPhploc($run = true)
{
$task = $this
->taskExec("$this->composerBin/phploc")
->option("--count-tests")
->arg($this->srcDir)
->arg($this->testsDir);
if ($run) {
return $task->run();
}
return $task;
}
/**
* Runs phpcs
*
* @param bool $run
* @return $this|\Robo\Result
*/
public function qaPhpcs($run = true)
{
$task = $this
->taskExec("$this->composerBin/phpcs")
->arg($this->srcDir)
->arg($this->testsDir)
->option('--standard=PSR2')
->option('--extensions=php')
->option('--ignore=autoload.php');
if ($run) {
return $task->run();
}
return $task;
}
}