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