]>
Commit | Line | Data |
---|---|---|
8798626b MG |
1 | #!/usr/bin/perl |
2 | use v5.14; | |
3 | use warnings; | |
4 | ||
5 | use CSS::Minifier::XS qw//; | |
6 | use JavaScript::Minifier::XS qw//; | |
7 | ||
3c9bcb47 | 8 | use IO::Compress::Gzip qw/gzip/; |
8798626b MG |
9 | use File::Slurp qw/read_file write_file/; |
10 | ||
11 | mkdir 'static'; | |
12 | mkdir 'static/css'; | |
13 | ||
3c9bcb47 MG |
14 | sub gzip_file { |
15 | my ($file) = @_; | |
16 | gzip $file => "$file.gz", -Level => 9, Minimal => 1; | |
17 | } | |
18 | ||
cf2b0139 MG |
19 | sub make_css { |
20 | my $common_css; | |
21 | $common_css .= read_file $_ for <css/*.css>; | |
22 | for (<css/themes/*>) { | |
23 | my ($theme) = m,themes/(.*)\.css,; | |
24 | my $css = read_file $_; | |
25 | $css .= $common_css; | |
26 | write_file "static/css/$theme.css", CSS::Minifier::XS::minify $css; | |
3c9bcb47 | 27 | gzip_file "static/css/$theme.css"; |
cf2b0139 | 28 | } |
8798626b MG |
29 | } |
30 | ||
cf2b0139 MG |
31 | sub make_js { |
32 | if (-f 'compiler.jar') { | |
33 | system java => -jar => 'compiler.jar', qw,-O SIMPLE --create_source_map static/js.map --js_output_file static/js.js --language_in ECMASCRIPT5_STRICT --source_map_location_mapping js/|/static/js/,, <js/*>; | |
34 | my $js = read_file 'static/js.js'; | |
35 | write_file 'static/js.js', '//# sourceMappingURL=/static/js.map', "\n", $js; | |
36 | system 'cp', '-rp', 'js', 'static/'; | |
37 | } else { | |
38 | my $js; | |
39 | $js .= read_file $_ for <js/*.js>; | |
40 | write_file 'static/js.js', JavaScript::Minifier::XS::minify $js; | |
41 | } | |
3c9bcb47 | 42 | gzip_file 'static/js.js'; |
cf2b0139 MG |
43 | } |
44 | ||
45 | my $css_mtime = -M 'static/css/slate.css' // 0; | |
46 | for (<css/*>, <css/themes/*>) { | |
47 | if (!$css_mtime || $css_mtime > -M) { | |
48 | make_css; | |
49 | last | |
50 | } | |
51 | } | |
52 | ||
53 | my $js_mtime = -M 'static/js.js' // 0; | |
54 | for (<js/*>) { | |
55 | if (!$js_mtime || $js_mtime > -M) { | |
56 | make_js; | |
57 | last | |
58 | } | |
9cad7bdd | 59 | } |