]> iEval git - gruntmaster-page.git/blame_incremental - make_static.PL
Add a function for making a DOM element from HTML
[gruntmaster-page.git] / make_static.PL
... / ...
CommitLineData
1#!/usr/bin/perl
2use v5.14;
3use warnings;
4
5use CSS::Minifier::XS qw//;
6use JavaScript::Minifier::XS qw//;
7
8use Digest::SHA qw/sha256_base64/;
9use IO::Compress::Gzip qw/gzip/;
10use File::Slurp qw/read_file write_file edit_file_lines/;
11
12mkdir 'static';
13mkdir 'static/css';
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 if (-f 'compiler.jar') {
34 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/*>;
35 my $js = read_file 'static/js.js';
36 write_file 'static/js.js', '//# sourceMappingURL=/static/js.map', "\n", $js;
37 system 'cp', '-rp', 'js', 'static/';
38 } else {
39 my $js;
40 $js .= read_file $_ for <js/*.js>;
41 write_file 'static/js.js', JavaScript::Minifier::XS::minify $js;
42 }
43 gzip_file 'static/js.js';
44}
45
46my $css_mtime = -M 'static/css/slate.css' // 0;
47for (<css/*>, <css/themes/*>) {
48 if (!$css_mtime || $css_mtime > -M) {
49 make_css;
50 last
51 }
52}
53
54my $js_mtime = -M 'static/js.js' // 0;
55for (<js/*>) {
56 if (!$js_mtime || $js_mtime > -M) {
57 make_js;
58 last
59 }
60}
61
62edit_file_lines {
63 my ($file) = m,(static.*\.(?:css|js)),;
64 return unless $file;
65 my $hash = sha256_base64 scalar read_file $file;
66 s/integrity=".*"/integrity="sha256-$hash="/;
67} 'tmpl/skel.en'
This page took 0.022755 seconds and 4 git commands to generate.