-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclosure_compiler.php
76 lines (53 loc) · 2.09 KB
/
closure_compiler.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
class Closure_compiler
{
public static function minify_js()
{
// config variables
$scripts = Config::get('closure-compiler::closure-compiler.minify_scripts');
$script_path = Config::get('closure-compiler::closure-compiler.script_path');
$script_output_file = Config::get('closure-compiler::closure-compiler.script_output_file');
$java_binary_path_overrides = Config::get('closure-compiler::closure-compiler.java_binary_path_overrides');
// by default don't compile the javascript
$compile = false;
// ensure that the scripts array is indeed an array
if(!is_array($scripts))
$scripts = array($scripts);
$scripts_to_minify = '';
// does the output file exist? if so, check the timestamp, if not minify the scripts
if(file_exists($script_output_file))
{
$min_script_timestamp = filemtime($script_output_file);
}
else
{
$min_script_timestamp = 0;
$compile = true;
}
// loop through the scripts and see if any of them have been updated since our output file has
foreach($scripts as $script)
{
if(file_exists($script_path . $script))
{
if(filemtime($script_path . $script) > $min_script_timestamp) $compile = TRUE;
if(!empty($scripts_to_minify)) $scripts_to_minify .= ' ';
$scripts_to_minify .= '--js=' . $script_path . $script;
}
}
// compile scripts
if($compile)
{
$java = 'java';
// find java binary
foreach($java_binary_path_overrides as $java_bin_path)
{
if(file_exists($java_bin_path)) $java = $java_bin_path;
}
// generate command line
$jar = '-jar ' . __DIR__ . '/vendor/compiler.jar';
$out_script = '--js_output_file=' . $script_output_file;
// red team, go!
exec("$java $jar $scripts_to_minify $out_script");
}
}
};