Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 113 lines (98 sloc) 2.487 kB
#!/usr/bin/php -q
<?php
//
// command line utility to compile less to stdout
// leaf corcoran <leafo.net>
require './lessc.inc.php';
$colors = array (
'color' => array(
'black' => 30,
'red' => 31,
'green' => 32,
'brown' => 33,
'blue' => 34,
'purple' => 35,
'cyan' => 36,
'grey' => 37,
'yellow' => 33
),
'style' => array(
'normal' => 0,
'bold' => 1,
'light' => 1,
'underscore' => 4,
'underline' => 4,
'blink' => 5,
'inverse' => 6,
'hidden' => 8,
'concealed' => 8
),
'background' => array(
'black' => 40,
'red' => 41,
'green' => 42,
'brown' => 43,
'yellow' => 43,
'blue' => 44,
'purple' => 45,
'cyan' => 46,
'grey' => 47
)
);
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("\033[31m\033[1mFatal Error:\033[0m 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);
$pi = pathinfo($fname);
$importDir = $pi['dirname'].'/';
}
error_reporting(E_ALL);
$l = new lessc();
if ($importDir) $l->importDir = $importDir;
try {
echo $l->parse($c);
} catch (exception $ex) {
echo "Fatal Error:\n".str_repeat('=', 20)."\n".$ex->getMessage()."\n";
}
?>
Jump to Line
Something went wrong with that request. Please try again.