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