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