]> iEval git - gruntmaster-page.git/blame_incremental - make_static.PL
Upgrade to ECMAScript 6
[gruntmaster-page.git] / make_static.PL
... / ...
CommitLineData
1#!/usr/bin/perl
2use v5.14;
3use warnings;
4
5use CSS::Minifier::XS qw//;
6
7use Digest::SHA qw/sha256_base64/;
8use IO::Compress::Gzip qw/gzip/;
9use File::Slurp qw/read_file write_file edit_file_lines/;
10
11mkdir 'static';
12mkdir 'static/css';
13mkdir 'static/js';
14
15sub gzip_file {
16 my ($file) = @_;
17 gzip $file => "$file.gz", -Level => 9, Minimal => 1;
18}
19
20sub 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
32sub 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 ECMASCRIPT6_STRICT --language_out 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
40my $css_mtime = -M 'static/css/slate.css' // 0;
41for (<css/*>, <css/themes/*>) {
42 if (!$css_mtime || $css_mtime > -M) {
43 make_css;
44 last
45 }
46}
47
48my $js_mtime = -M 'static/js.js' // 0;
49for (<js/*>) {
50 if (!$js_mtime || $js_mtime > -M) {
51 make_js;
52 last
53 }
54}
55
56edit_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.021808 seconds and 4 git commands to generate.