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