4a7d0007ef49fbc481e51355046c40ff490e7541
[roojs1] / buildSDK / less-bootstrap-compiler.php
1 <?php
2
3 $cwd = getcwd();
4
5 if (array_pop(explode('/', $cwd)) !== 'roojs1') {
6     echo "this should be run in roojs1 directory...\n";
7     exit;
8 }
9
10 ini_set('include_path', 
11     dirname(__FILE__) . '/../:' .
12     dirname(__FILE__) . '/../../pear:' .
13     ini_get('include_path')
14 );
15
16 $rootDir = dirname(__FILE__) . '/../..';
17
18 $files = array(
19     "{$rootDir}/roojs1/less/bootstrap/bootstrap.less" => array(
20         'baseDir' => "{$rootDir}/roojs1/css-bootstrap",
21         'name' => 'bootstrap.css',
22         'minify' => 'bootstrap.min.css',
23         'sourceMapRootpath' => '../less/bootstrap/',
24         'variables' => array("@import 'variables.less';")
25     ),
26     "{$rootDir}/roojs1/less/roojs-bootstrap/roojs-bootstrap.less" => array(
27         'baseDir' => "{$rootDir}/roojs1/css-bootstrap",
28         'name' => 'roojs-bootstrap-debug.css',
29         'minify' => 'roojs-bootstrap.css',
30         'sourceMapRootpath' => '../less/roojs-bootstrap/',
31         'variables' => array("@import '../bootstrap/variables.less';")
32     )
33 );
34
35 foreach ($files as $src => $file){
36     
37     $css = "{$file['baseDir']}/{$file['name']}";
38     
39     if(!file_exists($css)){
40         continue;
41     }
42     
43     $dir = "{$file['baseDir']}/{$file['sourceMapRootpath']}";
44     
45     $variable = "{$dir}variables.less";
46     
47     if(file_exists($variable) && filemtime("{$dir}variables.less") > filemtime($css)){
48         continue;
49     }
50     
51     foreach(scandir($dir) as $f) {
52                 
53         if (!strlen($f) || $f[0] == '.') {
54             continue;
55         }
56
57         $less = "{$dir}/{$f}";
58         
59         if(filemtime($less) > filemtime($css)){
60             continue;
61         }
62         
63         echo "{$css} already up-to-date \n";
64         unset($files[$src]);
65         break;
66
67     }
68     
69 }
70
71 require_once 'HTML/Less.php';
72
73 foreach ($files as $src => $file){
74
75     if(!file_exists($src)){
76         echo "{$less} does not exist...\n";
77         continue;
78     }
79     
80     try {
81         
82         $less = new HTML_Less();
83         
84         $less->setOptions(array(
85             'variables' => $file['variables'],
86             'sourceMap' => true,
87             'sourceMapWriteTo' => "{$file['baseDir']}/{$file['name']}.map",
88             'sourceMapURL' => "{$file['name']}.map",
89             'sourceMapRootpath' => $file['sourceMapRootpath'],
90             'sourceMapBasepath' => dirname(realpath($src))
91         ));
92         
93         $css = "{$file['baseDir']}/{$file['name']}";
94         
95         echo "Compiling - {$src} To {$css}\n";
96         
97         $less->compileFile($src, $css);
98         
99         $min = "{$file['baseDir']}/{$file['minify']}";
100         
101         $less = new HTML_Less();
102         
103         $less->setOptions(array(
104             'compress' => true,
105             'variables' => $file['variables'],
106             'sourceMap' => true,
107             'sourceMapWriteTo' => "{$file['baseDir']}/{$file['minify']}.map",
108             'sourceMapURL' => "{$file['minify']}.map",
109             'sourceMapRootpath' => $file['sourceMapRootpath'],
110             'sourceMapBasepath' => dirname(realpath($src))
111         ));
112         
113         echo "Minifing - {$src} To {$min}\n";
114         
115         $less->compileFile($src, $min);
116         
117     } catch (Exception $ex) {
118         echo "lessphp fatal error: {$ex->getMessage()}\n";
119     }
120     
121 }