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