-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathbuild.php
49 lines (49 loc) · 1.3 KB
/
build.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
$time = microtime(true);
$info = parse_ini_file('config.ini');
$mklen = 0;
$cl = '
/** '.$info['name'];
foreach($info as $key => $value){
if($key !== 'name' && $key !== 'file')
$mklen = max($mklen, strlen($key));
}
++$mklen;
foreach($info as $key => $value){
if($key !== 'name' && $key !== 'file')
$cl .= '
* @'.str_pad($key, $mklen).$value;
}
$cl .= '
*/
';
$name = $info['name'];
$output = $info['file'];
// -- simple build
$file = 'build/'.$name.'.js';
$filemin = preg_replace('/\.js$/', '.min.js', $file);
if(!function_exists('file_put_contents')){
function file_put_contents($file, $content){
$fp = fopen($file, 'wb');
fwrite($fp, $content);
fclose($fp);
}
}
$nl = "\n";
foreach($output as $key => $value)
$output[$key] = file_get_contents('src/javascript/'.$value.'.js');
$output = implode($nl, $output);
$output = ($cl=trim($cl)).$nl.$nl.$output;
if(file_exists($file))
unlink($file);
if(file_exists($filemin))
unlink($filemin);
file_put_contents($file, $output);
exec('java -jar yuicompressor-2.4.2.jar --nomunge '.$file.' -o '.$filemin);
$min = $cl.file_get_contents($filemin);
file_put_contents($filemin, $min);
ob_start('ob_gzhandler');
header('Content-Type: text/javascript');
header('X-Served-In: '.(microtime(true) - $time));
exit($min);
?>