]> iEval git - gruntmaster-page.git/blame - make_static.PL
Merge branch 'master' into newmc
[gruntmaster-page.git] / make_static.PL
CommitLineData
8798626b
MG
1#!/usr/bin/perl
2use v5.14;
3use warnings;
4
5use CSS::Minifier::XS qw//;
6eb2623e 6use CSS::SpriteMaker;
8798626b
MG
7use JavaScript::Minifier::XS qw//;
8
3c9bcb47 9use IO::Compress::Gzip qw/gzip/;
8798626b
MG
10use File::Slurp qw/read_file write_file/;
11
12mkdir 'static';
13mkdir 'static/css';
14
69d77267
MG
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 );
6eb2623e 23
69d77267
MG
24 $maker->make_sprite(
25 source_images => ['logos/'],
26 target_file => 'static/logos.png',
27 add_extra_padding => 10,
28 );
6eb2623e 29
69d77267
MG
30 $maker->print_css(
31 filename => 'css/logos.css',
0f623f3d 32 sprite_filename => '/static/logos.png',
69d77267 33 );
6eb2623e 34
0e8866c3
MG
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';
69d77267 38}
c9dee865 39
3c9bcb47
MG
40sub gzip_file {
41 my ($file) = @_;
42 gzip $file => "$file.gz", -Level => 9, Minimal => 1;
43}
44
cf2b0139
MG
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;
3c9bcb47 53 gzip_file "static/css/$theme.css";
cf2b0139 54 }
8798626b
MG
55}
56
cf2b0139
MG
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 }
3c9bcb47 68 gzip_file 'static/js.js';
cf2b0139
MG
69}
70
71my $css_mtime = -M 'static/css/slate.css' // 0;
72for (<css/*>, <css/themes/*>) {
73 if (!$css_mtime || $css_mtime > -M) {
74 make_css;
75 last
76 }
77}
78
79my $js_mtime = -M 'static/js.js' // 0;
80for (<js/*>) {
81 if (!$js_mtime || $js_mtime > -M) {
82 make_js;
83 last
84 }
9cad7bdd 85}
69d77267
MG
86
87my $sprite_mtime = -M 'static/logos.png' // 0;
3d9a4393 88for (<logos/*>) {
69d77267
MG
89 if (!$sprite_mtime || $sprite_mtime > -M) {
90 make_sprite;
91 last
92 }
9cad7bdd 93}
6eb2623e
MG
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 {
0f623f3d 107 background-image: url("/static/logos.png");
6eb2623e
MG
108 background-repeat: no-repeat;
109 display: inline-block;
110 vertical-align: middle;
111}
112EOF
113 join "\n", @ret;
114}
This page took 0.033696 seconds and 4 git commands to generate.