]> iEval git - gruntmaster-page.git/blame - make_static.PL
Use main and aside
[gruntmaster-page.git] / make_static.PL
CommitLineData
8798626b
MG
1#!/usr/bin/perl
2use v5.14;
3use warnings;
4
5use CSS::Minifier::XS qw//;
6use JavaScript::Minifier::XS qw//;
7
3c9bcb47 8use IO::Compress::Gzip qw/gzip/;
8798626b
MG
9use File::Slurp qw/read_file write_file/;
10
11mkdir 'static';
12mkdir 'static/css';
13
3c9bcb47
MG
14sub gzip_file {
15 my ($file) = @_;
16 gzip $file => "$file.gz", -Level => 9, Minimal => 1;
17}
18
cf2b0139
MG
19sub 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;
3c9bcb47 27 gzip_file "static/css/$theme.css";
cf2b0139 28 }
8798626b
MG
29}
30
cf2b0139
MG
31sub 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 }
3c9bcb47 42 gzip_file 'static/js.js';
cf2b0139
MG
43}
44
45my $css_mtime = -M 'static/css/slate.css' // 0;
46for (<css/*>, <css/themes/*>) {
47 if (!$css_mtime || $css_mtime > -M) {
48 make_css;
49 last
50 }
51}
52
53my $js_mtime = -M 'static/js.js' // 0;
54for (<js/*>) {
55 if (!$js_mtime || $js_mtime > -M) {
56 make_js;
57 last
58 }
9cad7bdd 59}
This page took 0.026053 seconds and 4 git commands to generate.