Skip to content

Commit fb42271

Browse files
committed
Recursively search for LESS imports and check each of their mtimes against the output CSS file
1 parent 8890647 commit fb42271

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

start.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,40 @@
44

55
$config = Config::get('less');
66

7-
$compile = function($input_file, $output_file)
7+
$imports = function($file) use (&$imports)
8+
{
9+
$paths = array();
10+
11+
preg_match_all('/@import\s+"(?P<imports>[^";]+)"/ism', File::get($file), $matches);
12+
foreach ($matches['imports'] as $import)
13+
{
14+
$path = dirname($file) . '/' . $import;
15+
if (File::exists($path) || File::exists($path .= '.less'))
16+
{
17+
$paths[] = $path;
18+
$paths = array_merge($paths, $imports($path));
19+
}
20+
}
21+
22+
return $paths;
23+
};
24+
25+
$compile = function($input_file, $output_file) use ($imports)
826
{
927
try
1028
{
11-
lessc::ccompile($input_file, $output_file);
29+
$latest = File::modified($input_file);
30+
foreach ($imports($input_file) as $import)
31+
{
32+
$import_modified = File::modified($import);
33+
$latest = $import_modified > $latest ? $import_modified : $latest;
34+
}
35+
36+
if (! File::exists($output_file) || $latest > File::modified($output_file))
37+
{
38+
$cache = lessc::cexecute($input_file);
39+
File::put($output_file, $cache['compiled']);
40+
}
1241
}
1342
catch (Exception $ex)
1443
{
@@ -42,6 +71,6 @@
4271
$less = new lessc();
4372
foreach ($config['snippets'] as $snippet => $css)
4473
{
45-
file_put_contents($css, $less->parse($snippet));
74+
File::put($css, $less->parse($snippet));
4675
}
4776
}

0 commit comments

Comments
 (0)