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