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