]> iEval git - gruntmaster-page.git/blob - make_static.PL
Collapse nav on mobile devices
[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 use JavaScript::Minifier::XS qw//;
7
8 use IO::Compress::Gzip qw/gzip/;
9 use File::Slurp qw/read_file write_file/;
10
11 mkdir 'static';
12 mkdir 'static/css';
13
14 sub gzip_file {
15 my ($file) = @_;
16 gzip $file => "$file.gz", -Level => 9, Minimal => 1;
17 }
18
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;
27 gzip_file "static/css/$theme.css";
28 }
29 }
30
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 }
42 gzip_file 'static/js.js';
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 }
59 }
This page took 0.05678 seconds and 4 git commands to generate.