buildSDK/less-bootstrap-compiler.php
[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     $variable = "{$rootDir}/roojs1/less/bootstrap/variables.less";
44     
45 }
46         
47 require_once 'HTML/Less.php';
48
49 foreach ($files as $src => $file){
50
51     if(!file_exists($src)){
52         echo "{$less} does not exist...\n";
53         continue;
54     }
55     
56     try {
57         
58         $less = new HTML_Less();
59         
60         $less->setOptions(array(
61             'variables' => $file['variables'],
62             'sourceMap' => true,
63             'sourceMapWriteTo' => "{$file['baseDir']}/{$file['name']}.map",
64             'sourceMapURL' => "{$file['name']}.map",
65             'sourceMapRootpath' => $file['sourceMapRootpath'],
66             'sourceMapBasepath' => dirname(realpath($src))
67         ));
68         
69         $css = "{$file['baseDir']}/{$file['name']}";
70         
71         echo "Compiling - {$src} To {$css}\n";
72         
73         $less->compileFile($src, $css);
74         
75         $min = "{$file['baseDir']}/{$file['minify']}";
76         
77         $less = new HTML_Less();
78         
79         $less->setOptions(array(
80             'compress' => true,
81             'variables' => $file['variables'],
82             'sourceMap' => true,
83             'sourceMapWriteTo' => "{$file['baseDir']}/{$file['minify']}.map",
84             'sourceMapURL' => "{$file['minify']}.map",
85             'sourceMapRootpath' => $file['sourceMapRootpath'],
86             'sourceMapBasepath' => dirname(realpath($src))
87         ));
88         
89         echo "Minifing - {$src} To {$min}\n";
90         
91         $less->compileFile($src, $min);
92         
93     } catch (Exception $ex) {
94         echo "lessphp fatal error: {$ex->getMessage()}\n";
95     }
96     
97 }