]> iEval git - gruntmaster-page.git/blame_incremental - make_static.PL
Add final standings for 2015
[gruntmaster-page.git] / make_static.PL
... / ...
CommitLineData
1#!/usr/bin/perl
2use v5.14;
3use warnings;
4
5use CSS::Minifier::XS qw//;
6use CSS::SpriteMaker;
7use JavaScript::Minifier::XS qw//;
8
9use IO::Compress::Gzip qw/gzip/;
10use File::Slurp qw/read_file write_file/;
11
12mkdir 'static';
13mkdir 'static/css';
14
15sub make_sprite {
16 my $maker = Local::CSS::SpriteMaker->new(
17 css_class_prefix => 'logo-',
18 rc_override_classname => sub {
19 my ($name) = @_;
20 $name =~ s/-light/.logo-light/r;
21 }
22 );
23
24 $maker->make_sprite(
25 source_images => ['logos/'],
26 target_file => 'static/logos.png',
27 add_extra_padding => 10,
28 );
29
30 $maker->print_css(
31 filename => 'css/logos.css',
32 sprite_filename => '/static/logos.png',
33 );
34
35 system 'pngnq-s9', '-s1', 'static/logos.png';
36 system 'optipng', '-o7', '-zm1-9', 'static/logos-nq8.png';
37 rename 'static/logos-nq8.png', 'static/logos.png';
38}
39
40sub gzip_file {
41 my ($file) = @_;
42 gzip $file => "$file.gz", -Level => 9, Minimal => 1;
43}
44
45sub make_css {
46 my $common_css;
47 $common_css .= read_file $_ for <css/*.css>;
48 for (<css/themes/*>) {
49 my ($theme) = m,themes/(.*)\.css,;
50 my $css = read_file $_;
51 $css .= $common_css;
52 write_file "static/css/$theme.css", CSS::Minifier::XS::minify $css;
53 gzip_file "static/css/$theme.css";
54 }
55}
56
57sub make_js {
58 if (-f 'compiler.jar') {
59 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/*>;
60 my $js = read_file 'static/js.js';
61 write_file 'static/js.js', '//# sourceMappingURL=/static/js.map', "\n", $js;
62 system 'cp', '-rp', 'js', 'static/';
63 } else {
64 my $js;
65 $js .= read_file $_ for <js/*.js>;
66 write_file 'static/js.js', JavaScript::Minifier::XS::minify $js;
67 }
68 gzip_file 'static/js.js';
69}
70
71my $sprite_mtime = -M 'static/logos.png' // 0;
72for (<logos/*>) {
73 if (!$sprite_mtime || $sprite_mtime > -M) {
74 make_sprite;
75 last
76 }
77}
78
79my $css_mtime = -M 'static/css/slate.css' // 0;
80for (<css/*>, <css/themes/*>) {
81 if (!$css_mtime || $css_mtime > -M) {
82 make_css;
83 last
84 }
85}
86
87my $js_mtime = -M 'static/js.js' // 0;
88for (<js/*>) {
89 if (!$js_mtime || $js_mtime > -M) {
90 make_js;
91 last
92 }
93}
94
95package
96 Local::CSS::SpriteMaker;
97
98use parent qw/CSS::SpriteMaker/;
99
100sub _get_stylesheet_string {
101 my $self = shift;
102 my @ret = split "\n", $self->SUPER::_get_stylesheet_string(@_);
103 shift @ret;
104 @ret = sort @ret;
105 unshift @ret, <<EOF;
106a.logo {
107 background-image: url("/static/logos.png");
108 background-repeat: no-repeat;
109 display: inline-block;
110 vertical-align: middle;
111}
112EOF
113 join "\n", @ret;
114}
This page took 0.017333 seconds and 4 git commands to generate.