fix attribute
[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' =>  ""
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/functions';\n@import '../bootstrap/variables';"
36     ),
37     
38     // this is a test to see if we can get this theme to build..
39     // note our classic roojs-bootstrap will need a rebuild as well as it uses different variables.
40     "sb-admin-2.scss" => array(
41         "scssDir" => "{$rootDir}/roojs1/scss/startbootstrap-sb-admin-2",
42         'baseDir' => "{$rootDir}/roojs1/css-bootstrap4",
43         'name' => 'sb-admin-2.css',
44         'minify' => 'sb-admin-2.min.css',
45         'sourceMapRootpath' => '../scss/startbootstrap-sb-admin-2/',
46         'variables' =>  ""
47     ),
48     
49      
50 );
51 require_once 'System.php';
52 $sassc = System::which("sassc");
53 if (empty($sassc)) {
54     die("INSTALL sassc");
55 }
56 foreach($files as $file => $f) {
57     
58     $tmpFile = tempnam("/tmp/", "scss");
59     file_put_contents($tmpFile, "{$f['variables']}\n@import \"{$file}\";\n");
60     echo file_get_contents($tmpFile);
61     
62     
63     
64     $cmd = "{$sassc}  --sourcemap=auto -I {$f['scssDir']} $tmpFile {$f['baseDir']}/{$f['name']}";
65     echo "$cmd\n";
66     echo `$cmd`;
67     $cmd = "{$sassc} --style=compressed --sourcemap=auto -I {$f['scssDir']} $tmpFile {$f['baseDir']}/{$f['minify']}";
68     echo "$cmd\n";
69     echo `$cmd`;
70 }
71 exit;
72
73
74
75 /*
76 foreach ($files as $src => $file){
77     
78     $css = "{$file['baseDir']}/{$file['name']}";
79     
80     if(!file_exists($css)){
81         continue;
82     }
83     
84     $dir = "{$file['baseDir']}/{$file['sourceMapRootpath']}";
85     
86     $variable = "{$dir}variables.less";
87     
88     if(file_exists($variable) && filemtime("{$dir}variables.less") > filemtime($css)){
89         continue;
90     }
91     
92     $isLatest = true;
93     
94     foreach(scandir($dir) as $f) {
95                 
96         if (!strlen($f) || $f[0] == '.') {
97             continue;
98         }
99
100         $less = "{$dir}{$f}";
101         
102         if(filemtime($less) > filemtime($css)){
103             $isLatest = false;
104             break;
105         }
106     }
107     
108     if($isLatest){
109         echo "{$css} already up-to-date \n";
110         unset($files[$src]);
111     }
112     
113 }
114 */
115 require_once 'HTML/Scss.php';
116
117 foreach ($files as $src => $file){
118     
119     if(!file_exists($file['scssDir'].'/'. $src)){
120         echo "{$file['scssDir']}/{$src} does not exist...\n";
121         continue;
122     }
123     
124     try {
125         
126         $scss = new HTML_Scss();
127          
128         $scss->setSourceMap(HTML_Scss::SOURCE_MAP_FILE);
129         $scss->setSourceMapOptions(array(
130                 'sourceRoot' => $file['sourceMapRootpath'],
131         
132                 // an optional name of the generated code that this source map is associated with.
133                 'sourceMapFilename' => "{$file['baseDir']}/{$file['name']}.map",
134         
135                 // url of the map
136                 'sourceMapURL' => "{$file['name']}.map",
137         
138                 // absolute path to a file to write the map to
139                 'sourceMapWriteTo' => "{$file['baseDir']}/{$file['name']}.map",
140         
141                 // output source contents?
142                 'outputSourceFiles' => false,
143         
144                 // this is added to the file path.
145                 'sourceMapRootpath' =>  '../',
146         
147                 // this is removed from the filepath.
148                 'sourceMapBasepath' => $rootDir .'/roojs1/scss'
149             
150         ));
151        
152    
153         $css = "{$file['baseDir']}/{$file['name']}";
154         
155         echo "Compiling - {$src} To {$css}\n";
156         
157         $scss->setImportPaths($file['scssDir']);
158         $scss->setFormatter('Expanded');
159         
160         file_put_contents($css, $scss->compile("{$file['variables']}\n@import \"{$src}\";"));
161         
162         
163         $min = "{$file['baseDir']}/{$file['minify']}";
164         
165          
166         
167         echo "Minifing - {$src} To {$min}\n";
168         
169         $scss->setFormatter('Crunched');
170         
171         file_put_contents($min,  $scss->compile("{$file['variables']}\n@import \"{$src}\";")  );
172     } catch (Exception $ex) {
173         echo "scss fatal error: {$ex->getMessage()}\n";
174     }
175 }