4 require_once dirname(__FILE__) . '/../lib/Less/Autoloader.php';
5 Less_Autoloader::register();
7 // Create our environment
8 $env = array('compress' => false, 'relativeUrls' => false);
13 // Check for arguments
20 foreach ($argv as $key => $arg) {
21 if (preg_match('/^--?([a-z][0-9a-z-]*)(?:=([^\s]+))?$/i', $arg, $matches)) {
22 $option = $matches[1];
23 $value = isset($matches[2]) ? $matches[2] : false;
30 Usage: lessc [options] sources [destination]
32 -h, --help Print help (this message) and exit.
33 -s, --silent Suppress output of error messages.
34 -v, --version Print version number and exit.
35 -x, --compress Compress output by removing some whitespaces.
36 --include-path=PATHS Set include paths. Separated by `:'. Use `;' on Windows.
37 --strict-imports Force evaluation of imports.
38 -sm=on|off Turn on or off strict math, where in strict mode, math
39 --strict-math=on|off requires brackets. This option may default to on and then
40 be removed in the future.
41 -su=on|off Allow mixed units, e.g. 1px+1em or 1px*1px which have units
42 --strict-units=on|off that cannot be represented.
43 -ru, --relative-urls re-write relative urls to the base less file.
44 -rp, --rootpath=URL Set rootpath for url rewriting in relative imports and urls.
45 Works with or without the relative-urls option.
46 -w, --watch Watch input files for changes.
63 echo "lessc " . Less_Version::version . " (less.php)\n\n";
74 $env['compress'] = true;
79 $env['relativeUrls'] = true;
84 $env['strictUnits'] = ($value === 'on');
89 $env['strictMath'] = ($value === 'on');
94 $env['import_dirs'] = preg_split('#;|\:#', $value);
101 if (count($argv) > 1) {
102 $output = array_pop($argv);
110 if (!count($inputs)) {
111 echo("lessc: no input files\n");
117 echo("lessc: you must specify the output file if --watch is given\n");
123 echo("lessc: watching input files\n");
129 foreach ($inputs as $input) {
131 if (count($inputs) == 1) {
132 echo("lessc: during watching files is not possible to watch stdin\n");
140 if (filemtime($input) > $lastAction) {
147 $lastAction = time();
148 $parser = new Less_Parser($env);
149 foreach ($inputs as $input) {
151 $parser->parseFile($input, $rootpath);
153 catch (Exception $e) {
154 echo("lessc: " . $e->getMessage() . " \n");
155 continue; // Invalid processing
159 file_put_contents($output, $parser->getCss());
160 echo("lessc: output file recompiled\n");
167 $parser = new Less_Parser($env);
168 foreach ($inputs as $input) {
170 $content = file_get_contents('php://stdin');
171 $parser->parse($content);
175 $parser->parseFile($input);
177 catch (Exception $e) {
179 echo("lessc: " . ((string)$e) . " \n");
186 file_put_contents($output, $parser->getCss());
189 echo $parser->getCss();