|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Genesis\Commands\Assets; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Genesis\Commands; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Warning: This implementation is using NodeJs lessc - you need NodeJs with globally installed lessc. |
|
11
|
|
|
* @author Adam Bisek <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class Less extends Commands\Command |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
private $executable = 'lessc'; |
|
17
|
|
|
|
|
18
|
|
|
private $files = []; |
|
19
|
|
|
|
|
20
|
|
|
/** @var */ |
|
21
|
|
|
private $options; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Returns path to lessc executable. |
|
26
|
|
|
* @return string |
|
27
|
|
|
*/ |
|
28
|
1 |
|
public function getExecutable() |
|
29
|
|
|
{ |
|
30
|
1 |
|
return $this->executable; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Sets path to lessc executable. |
|
36
|
|
|
* @param string $executable |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function setExecutable($executable) |
|
39
|
|
|
{ |
|
40
|
1 |
|
$this->executable = $executable; |
|
41
|
1 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Returns files to compile. |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function getFiles() |
|
49
|
|
|
{ |
|
50
|
1 |
|
return $this->files; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Sets files to compile. |
|
56
|
|
|
* @param array $files |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function setFiles($files) |
|
59
|
|
|
{ |
|
60
|
1 |
|
$this->files = $files; |
|
61
|
1 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return array|NULL |
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function getOptions() |
|
68
|
|
|
{ |
|
69
|
1 |
|
return $this->options; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param array|NULL $options |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function setOptions($options) |
|
77
|
|
|
{ |
|
78
|
1 |
|
$this->options = $options; |
|
79
|
1 |
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
1 |
|
public function execute() |
|
83
|
|
|
{ |
|
84
|
1 |
|
if (count($this->files) === 0) { |
|
85
|
|
|
return; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
1 |
|
$opts = '--no-color --verbose '; |
|
89
|
1 |
|
if (isset($this->options['compress']) && $this->options['compress']) { |
|
90
|
|
|
$opts .= '--compress '; |
|
91
|
|
|
} |
|
92
|
1 |
|
if (isset($this->options['relativeUrls']) && $this->options['relativeUrls']) { |
|
93
|
|
|
$opts .= '--relative-urls '; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
1 |
|
foreach ($this->files as $source => $target) { |
|
97
|
1 |
|
$cmd = escapeshellarg($this->executable) . ' ' . $opts . escapeshellarg($source) . ' ' . escapeshellarg($target); |
|
98
|
1 |
|
$command = new Commands\Exec(); |
|
99
|
1 |
|
$command->setCommand($cmd); |
|
100
|
1 |
|
$result = $command->execute(); |
|
101
|
1 |
|
if ($result->getResult() !== 0) { |
|
102
|
|
|
$this->error(sprintf("LESS compilation of file '%s' failed.", $source)); |
|
103
|
|
|
} |
|
104
|
1 |
|
} |
|
105
|
1 |
|
} |
|
106
|
|
|
|
|
107
|
|
|
} |