]> iEval git - gruntmaster-page.git/blob - make_static.PL
44ef19e253ea28cde50b7f92d0643477f8d62f2a
[gruntmaster-page.git] / make_static.PL
1 #!/usr/bin/perl
2 use v5.14;
3 use warnings;
4
5 use CSS::Minifier::XS qw//;
6
7 use Digest::SHA qw/sha256_base64/;
8 use IO::Compress::Gzip qw/gzip/;
9 use File::Slurp qw/read_file write_file edit_file_lines/;
10
11 mkdir 'static';
12 mkdir 'static/css';
13 mkdir 'static/js';
14
15 sub gzip_file {
16 my ($file) = @_;
17 gzip $file => "$file.gz", -Level => 9, Minimal => 1;
18 }
19
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;
28 gzip_file "static/css/$theme.css";
29 }
30 }
31
32 sub make_js {
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 ECMASCRIPT5_STRICT --source_map_location_mapping js/|/static/js/,, <js/*>;
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';
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 }
54 }
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'
This page took 0.044673 seconds and 3 git commands to generate.