This repository has been archived by the owner on Jun 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFile.php
179 lines (156 loc) · 4.55 KB
/
RoboFile.php
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
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks implements \Psr\Log\LoggerAwareInterface {
use \Psr\Log\LoggerAwareTrait;
/**
* Directory used for test.
*/
const RD8_TEST_DIR = '../tests/rd8';
/**
* Template project dir.
*/
const RD8_TPL_TEST_DIR = 'test-project';
/**
* Robo-Drupal8 root.
*
* @var string
*/
protected $rd8Root;
/**
* Bin RD8
*
* @var string
*/
protected $bin;
/**
* This hook will fire for all commands in this command file.
*
* @hook init
*/
public function initialize() {
$this->rd8Root = __DIR__;
$this->bin = $this->rd8Root . '/vendor/bin';
}
/**
* Create a new project via symlink from current checkout of robo-drupal8.
*
* Local RD8 will be symlinked to project.
*
* @option project-dir The directory in which the test project will be
* created.
*/
public function createFromSymlink($options = ['project-dir' => self::RD8_TEST_DIR]) {
$test_project_dir = $this->rd8Root . "/" . $options['project-dir'];
$this->prepareTestProjectDir($test_project_dir);
// Clone directory test.
$this->taskFilesystemStack()
->mkdir($test_project_dir)
->mirror($this->rd8Root . "/" . self::RD8_TPL_TEST_DIR, $test_project_dir)
->run();
// Replace in composer.json test the relative path to absolute.
$this->taskReplaceInFile($test_project_dir . "/composer.json")
->from("../robo-drupal8")
->to($this->rd8Root)
->run();
// Run composer install.
$this->taskExecStack()
->dir($test_project_dir)
->exec("rm -rf $test_project_dir/vendor")
->exec("composer install --prefer-dist")
->run();
// Re-install library for secure use symlink.
//$this->taskExecStack()
// ->dir($test_project_dir)
// ->exec("rm -rf $test_project_dir/vendor/lucacracco")
// ->exec("composer install")
// ->run();
}
/**
* Create a new project using `drupal-composer/drupal-project:8.x-dev'.
*
* @option project-dir The directory in which the test project will be
* created.
*/
public function createWithDrupalComposerProject($options = ['project-dir' => self::RD8_TEST_DIR]) {
$test_project_dir = $this->rd8Root . "/" . $options['project-dir'];
$this->prepareTestProjectDir($test_project_dir);
$this->yell("Creating project with drupal-composer/drupal-project:8.x-dev.");
// Create project test.
$this->taskExecStack()
->dir($test_project_dir)
->exec("COMPOSER_PROCESS_TIMEOUT=2000 composer create-project drupal-composer/drupal-project:8.x-dev " . self::RD8_TEST_DIR . " --no-interaction")
->run();
// Add required.
$this->taskExecStack()
->dir($test_project_dir)
->exec("composer require lucacracco/robo-drupal8:2.x")
->run();
}
/**
* Fixes RD8 internal code via PHPCBF.
*
* @command fix-code
*/
public function fixCode() {
$command = "'{$this->bin}/phpcbf'";
$task = $this->taskExecStack()
->dir($this->rd8Root)
->exec($command);
$result = $task->run();
return $result->getExitCode();
}
/**
* Sniffs RD8 internal code via PHPCS.
*
* @command sniff-code
*/
public function sniffCode() {
$task = $this->taskExecStack()
->dir($this->rd8Root)
->exec("{$this->bin}/phpcs")
->exec("composer validate");
$result = $task->run();
return $result->getExitCode();
}
/**
* @param array $options
*/
protected function createTestApp($options = [
'project-type' => 'standalone',
'project-dir' => self::RD8_TEST_DIR,
]) {
switch ($options['project-type']) {
case 'standalone':
$this->createWithDrupalComposerProject($options);
break;
case 'symlink':
$this->createFromSymlink($options);
break;
}
}
/**
* Delete Dir before init project test.
*
* @param $test_project_dir
*
* @throws \Exception
*/
protected function prepareTestProjectDir($test_project_dir) {
if (file_exists($test_project_dir)) {
$this->logger->warning("This will destroy the $test_project_dir directory!");
$continue = $this->confirm("Continue?");
if (!$continue) {
$this->say("Please run <comment>sudo rm -rf $test_project_dir</comment>");
throw new \Exception("$test_project_dir already exists.");
}
$this->taskFilesystemStack()
->chmod($test_project_dir, 0775, 0000, TRUE)
->taskDeleteDir($test_project_dir)
->run();
}
}
}