d1227f52e3285cc290bc24eaefcaed90afa19c5c
[roojs1] / buildSDK / scss-bootstrap.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     "bootstrap.scss" => array(
21         "scssDir" => "{$rootDir}/roojs1/scss/bootstrap",
22         'baseDir' => "{$rootDir}/roojs1/css-bootstrap4",
23         'name' => 'bootstrap.css',
24         'minify' => 'bootstrap.min.css',
25         'sourceMapRootpath' => '../scss/bootstrap/',
26     //    'variables' => array("@import 'variables.less';")
27     ),
28     /*
29     "{$rootDir}/roojs1/less/roojs-bootstrap/roojs-bootstrap.less" => array(
30         'baseDir' => "{$rootDir}/roojs1/css-bootstrap",
31         'name' => 'roojs-bootstrap-debug.css',
32         'minify' => 'roojs-bootstrap.css',
33         'sourceMapRootpath' => '../less/roojs-bootstrap/',
34         'variables' => array("@import '../bootstrap/variables.less';")
35     )
36     */
37 );
38 /*
39 foreach ($files as $src => $file){
40     
41     $css = "{$file['baseDir']}/{$file['name']}";
42     
43     if(!file_exists($css)){
44         continue;
45     }
46     
47     $dir = "{$file['baseDir']}/{$file['sourceMapRootpath']}";
48     
49     $variable = "{$dir}variables.less";
50     
51     if(file_exists($variable) && filemtime("{$dir}variables.less") > filemtime($css)){
52         continue;
53     }
54     
55     $isLatest = true;
56     
57     foreach(scandir($dir) as $f) {
58                 
59         if (!strlen($f) || $f[0] == '.') {
60             continue;
61         }
62
63         $less = "{$dir}{$f}";
64         
65         if(filemtime($less) > filemtime($css)){
66             $isLatest = false;
67             break;
68         }
69     }
70     
71     if($isLatest){
72         echo "{$css} already up-to-date \n";
73         unset($files[$src]);
74     }
75     
76 }
77 */
78 require_once 'HTML/Scss.php';
79
80 foreach ($files as $src => $file){
81     
82     if(!file_exists($file['scssDir'].'/'. $src)){
83         echo "{$file['scssDir']}/{$src} does not exist...\n";
84         continue;
85     }
86     
87     try {
88         
89         $scss = new HTML_Scss();
90          
91         $scss->setSourceMap(HTML_Scss::SOURCE_MAP_FILE);
92         $scss->setSourceMapOptions(array(
93                 'sourceRoot' => $file['sourceMapRootpath'],
94         
95                 // an optional name of the generated code that this source map is associated with.
96                 'sourceMapFilename' => "{$file['baseDir']}/{$file['name']}.map",
97         
98                 // url of the map
99                 'sourceMapURL' => "{$file['name']}.map",
100         
101                 // absolute path to a file to write the map to
102                 'sourceMapWriteTo' => "{$file['baseDir']}/{$file['name']}.map",
103         
104                 // output source contents?
105                 'outputSourceFiles' => false,
106         
107                 // base path for filename normalization
108                 'sourceMapRootpath' => '',
109         
110                 // base path for filename normalization
111                 'sourceMapBasepath' => ''
112             
113         ));
114        
115    
116         $css = "{$file['baseDir']}/{$file['name']}";
117         
118         echo "Compiling - {$src} To {$css}\n";
119         
120         $scss->setImportPaths($file['scssDir']);
121         $scss->setFormater('Compact');
122         
123         file_put_contents($scss->compile("@import \"{$src}\";"), $css);
124         
125         
126         $min = "{$file['baseDir']}/{$file['minify']}";
127         
128         $less = new HTML_Less();
129         
130         $less->setOptions(array(
131             'compress' => true,
132             'variables' => $file['variables'],
133             'sourceMap' => true,
134             'sourceMapWriteTo' => "{$file['baseDir']}/{$file['minify']}.map",
135             'sourceMapURL' => "{$file['minify']}.map",
136             'sourceMapRootpath' => $file['sourceMapRootpath'],
137             'sourceMapBasepath' => dirname(realpath($src))
138         ));
139         
140         echo "Minifing - {$src} To {$min}\n";
141         
142         $scss->setFormater('Crunched');
143         
144         file_put_contents($scss->compile("@import \"{$src}\";"), $min);
145     } catch (Exception $ex) {
146         echo "scss fatal error: {$ex->getMessage()}\n";
147     }
148 }