buildSDK/dependancy_bootstrap.txt
[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     $isLatest = true;
52     
53     foreach(scandir($dir) as $f) {
54                 
55         if (!strlen($f) || $f[0] == '.') {
56             continue;
57         }
58
59         $less = "{$dir}{$f}";
60         
61         if(filemtime($less) > filemtime($css)){
62             $isLatest = false;
63             break;
64         }
65     }
66     
67     if($isLatest){
68         echo "{$css} already up-to-date \n";
69         unset($files[$src]);
70     }
71     
72 }
73
74 require_once 'HTML/Less.php';
75
76 foreach ($files as $src => $file){
77
78     if(!file_exists($src)){
79         echo "{$less} does not exist...\n";
80         continue;
81     }
82     
83     try {
84         
85         $less = new HTML_Less();
86         
87         $less->setOptions(array(
88             'variables' => $file['variables'],
89             'sourceMap' => true,
90             'sourceMapWriteTo' => "{$file['baseDir']}/{$file['name']}.map",
91             'sourceMapURL' => "{$file['name']}.map",
92             'sourceMapRootpath' => $file['sourceMapRootpath'],
93             'sourceMapBasepath' => dirname(realpath($src))
94         ));
95         
96         $css = "{$file['baseDir']}/{$file['name']}";
97         
98         echo "Compiling - {$src} To {$css}\n";
99         
100         $less->compileFile($src, $css);
101         
102         $min = "{$file['baseDir']}/{$file['minify']}";
103         
104         $less = new HTML_Less();
105         
106         $less->setOptions(array(
107             'compress' => true,
108             'variables' => $file['variables'],
109             'sourceMap' => true,
110             'sourceMapWriteTo' => "{$file['baseDir']}/{$file['minify']}.map",
111             'sourceMapURL' => "{$file['minify']}.map",
112             'sourceMapRootpath' => $file['sourceMapRootpath'],
113             'sourceMapBasepath' => dirname(realpath($src))
114         ));
115         
116         echo "Minifing - {$src} To {$min}\n";
117         
118         $less->compileFile($src, $min);
119         
120     } catch (Exception $ex) {
121         echo "lessphp fatal error: {$ex->getMessage()}\n";
122     }
123 }