575daab136f51717dd3a921c2b88a87915e12710
[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 require_once 'HTML/Less.php';
36
37 foreach ($files as $src => $file){
38
39     if(!file_exists($src)){
40         echo "{$less} does not exist...\n";
41         continue;
42     }
43
44     try {
45         
46         $less = new HTML_Less();
47         
48         $less->setOptions(array(
49             'variables' => $file['variables'],
50             'sourceMap' => true,
51             'sourceMapWriteTo' => "{$file['baseDir']}/{$file['name']}.map",
52             'sourceMapURL' => "{$file['name']}.map",
53             'sourceMapRootpath' => $file['sourceMapRootpath'],
54             'sourceMapBasepath' => dirname(realpath($src))
55         ));
56         
57         $css = "{$file['baseDir']}/{$file['name']}";
58         
59         echo "Compiling - {$src} To {$css}\n";
60         
61         $less->compileFile($src, $css);
62         
63         $min = "{$file['baseDir']}/{$file['minify']}";
64         
65         $less = new HTML_Less();
66         
67         $less->setOptions(array(
68             'compress' => true,
69             'variables' => $file['variables'],
70             'sourceMap' => true,
71             'sourceMapWriteTo' => "{$file['baseDir']}/{$file['minify']}.map",
72             'sourceMapURL' => "{$file['minify']}.map"
73         ));
74         
75         echo "Minifing - {$src} To {$min}\n";
76         
77         $less->compileFile($src, $min);
78         
79     } catch (Exception $ex) {
80         echo "lessphp fatal error: {$ex->getMessage()}\n";
81     }
82     
83 }