-
Notifications
You must be signed in to change notification settings - Fork 530
/
plessc
executable file
·70 lines (59 loc) · 1.69 KB
/
plessc
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
#!/usr/bin/php -q
<?php
//
// command line utility to compile less to stdout
// leaf corcoran <leafo.net>
require './lessc.inc.php';
array_shift($argv);
// read less code from argument or from std in if there is no argument
if (false !== ($loc = array_search("-r", $argv))) {
unset($argv[$loc]);
$c = array_shift($argv);
if (!$c) {
while (!feof(STDIN)) {
$c .= fread(STDIN, 8192);
}
}
} else if (false !== ($loc = array_search("-w", $argv))) {
unset($argv[$loc]);
// see if we are sending notifications
$notif = array_search("-n", $argv);
if ($notif) unset($argv[$notif]);
if (!is_file($in = array_shift($argv)) ||
null == $out = array_shift($argv))
{
exit("Fatal Error: plessc -w infile outfile\n");
}
$fail_time = 0;
echo "Watching ".$in.($notif ? ' with notifications' : '').", press Ctrl + c to exit.\n";
while (1) {
if (!is_file($out) || (filemtime($in) > filemtime($out) && $fail_time != filemtime($in))) {
// try to compile it
try {
$l = new lessc($in);
$c = $l->parse();
echo "Writing updated file: ".$out."\n";
if (!file_put_contents($out, $c))
exit('Fatal Error: Failed to write file '.$out."\n");
} catch (exception $ex) {
echo "\nFatal Error:\n".str_repeat('=', 20)."\n".$ex->getMessage()."\n\n";
$fail_time = filemtime($in);
if ($notif) {
`notify-send -u critical "compile failed" "{$ex->getMessage()}"`;
}
}
}
sleep(1);
}
} else {
if (!is_file($fname = array_shift($argv)))
exit('Fatal Error: failed to find file: '.$fname."\n");
$c = file_get_contents($fname);
}
$l = new lessc();
try {
echo $l->parse($c);
} catch (exception $ex) {
echo "Fatal Error:\n".str_repeat('=', 20)."\n".$ex->getMessage()."\n";
}
?>