]> iEval git - gruntmaster-page.git/blob - make_static.PL
Merge branch 'master' into newmc
[gruntmaster-page.git] / make_static.PL
1 #!/usr/bin/perl
2 use v5.14;
3 use warnings;
4
5 use CSS::Minifier::XS qw//;
6 use CSS::SpriteMaker;
7 use JavaScript::Minifier::XS qw//;
8
9 use File::Slurp qw/read_file write_file/;
10
11 mkdir 'static';
12 mkdir 'static/css';
13
14 sub 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 );
22
23 $maker->make_sprite(
24 source_images => ['logos/'],
25 target_file => 'static/logos.png',
26 add_extra_padding => 10,
27 );
28
29 $maker->print_css(
30 filename => 'css/logos.css',
31 sprite_filename => 'https://static.mindcoding.ro/static/logos.png',
32 );
33
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';
37 }
38
39 sub 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 }
48 }
49
50 sub 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
63 my $css_mtime = -M 'static/css/slate.css' // 0;
64 for (<css/*>, <css/themes/*>) {
65 if (!$css_mtime || $css_mtime > -M) {
66 make_css;
67 last
68 }
69 }
70
71 my $js_mtime = -M 'static/js.js' // 0;
72 for (<js/*>) {
73 if (!$js_mtime || $js_mtime > -M) {
74 make_js;
75 last
76 }
77 }
78
79 my $sprite_mtime = -M 'static/logos.png' // 0;
80 for (<logos/*>) {
81 if (!$sprite_mtime || $sprite_mtime > -M) {
82 make_sprite;
83 last
84 }
85 }
86
87 package
88 Local::CSS::SpriteMaker;
89
90 use parent qw/CSS::SpriteMaker/;
91
92 sub _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;
98 a.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 }
104 EOF
105 join "\n", @ret;
106 }
This page took 0.059449 seconds and 4 git commands to generate.