forked from InfotelGLPI/openvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFilePlugin.php
142 lines (132 loc) · 2.94 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
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFilePlugin extends \Robo\Tasks
{
/**
* 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);
}
}