forked from pluginsGLPI/formcreator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoboFilePlugin.php
193 lines (174 loc) · 4.44 KB
/
RoboFilePlugin.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFilePlugin extends \Robo\Tasks
{
protected $csignore = ['/vendor/', '/node_modules/', '/lib/'];
protected $csfiles = ['./'];
/**
* Minify all
*
* @return void
*/
public function minify() {
$this->minifyCSS()
->minifyJS();
}
/**
* Minify CSS stylesheets
*
* @return void
*/
public function minifyCSS() {
$css_dir = __DIR__ . '/css';
if (is_dir($css_dir)) {
foreach (glob("$css_dir/*.css") as $css_file) {
if (!$this->endsWith($css_file, 'min.css')) {
$this->taskMinify($css_file)
->to(str_replace('.css', '.min.css', $css_file))
->type('css')
->run();
}
}
}
return $this;
}
/**
* Minify JavaScript files stylesheets
*
* @return void
*/
public function minifyJS() {
$js_dir = __DIR__ . '/js';
if (is_dir($js_dir)) {
foreach (glob("$js_dir/*.js") as $js_file) {
if (!$this->endsWith($js_file, 'min.js')) {
$this->taskMinify($js_file)
->to(str_replace('.js', '.min.js', $js_file))
->type('js')
->run();
}
}
}
return $this;
}
/**
* Extract translatable strings
*
* @return void
*/
public function localesExtract() {
$this->_exec('tools/extract_template.sh');
return $this;
}
/**
* Push locales to transifex
*
* @return void
*/
public function localesPush() {
$this->_exec('tx push -s');
return $this;
}
/**
* Pull locales from transifex.
*
* @param integer $percent Completeness percentage
*
* @return void
*/
public function localesPull($percent = 70) {
$this->_exec('tx pull -a --minimum-perc=' .$percent);
return $this;
}
/**
* Build MO files
*
* @return void
*/
public function localesMo() {
$this->_exec('./tools/release --compile-mo');
return $this;
}
/**
* Extract and send locales
*
* @return void
*/
public function localesSend() {
$this->localesExtract()
->localesPush();
return $this;
}
/**
* Retrieve locales and generate mo files
*
* @param integer $percent Completeness percentage
*
* @return void
*/
public function localesGenerate($percent = 70) {
$this->localesPull($percent)
->localesMo();
return $this;
}
/**
* Checks if a string ends with another string
*
* @param string $haystack Full string
* @param string $needle Ends string
*
* @return boolean
* @see http://stackoverflow.com/a/834355
*/
private function endsWith($haystack, $needle) {
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
/**
* Code sniffer.
*
* Run the PHP Codesniffer on a file or directory.
*
* @param string $file A file or directory to analyze.
* @param array $options Options:
* @option $autofix Whether to run the automatic fixer or not.
* @option $strict Show warnings as well as errors.
* Default is to show only errors.
*
* @return void
*/
public function codeCs(
$file = null,
$options = [
'autofix' => false,
'strict' => false,
]
) {
if ($file === null) {
$file = implode(' ', $this->csfiles);
}
$csignore = '';
if (count($this->csignore)) {
$csignore .= '--ignore=';
$csignore .= implode(',', $this->csignore);
}
$strict = $options['strict'] ? '' : '-n';
$result = $this->taskExec("./vendor/bin/phpcs $csignore --standard=vendor/glpi-project/coding-standard/GlpiStandard/ {$strict} {$file}")->run();
if (!$result->wasSuccessful()) {
if (!$options['autofix'] && !$options['no-interaction']) {
$options['autofix'] = $this->confirm('Would you like to run phpcbf to fix the reported errors?');
}
if ($options['autofix']) {
$result = $this->taskExec("./vendor/bin/phpcbf $csignore --standard=vendor/glpi-project/coding-standard/GlpiStandard/ {$file}")->run();
}
}
return $result;
}
}