Debian Codegraph @

tools/updt_embedded_rsc.pl

raw symbols SCIP
1 #!/usr/bin/env perl
2 #-----------------------------------------------------------------------------
3 #
4 # Script used to update javascript and css files embedded into pgbadger.
5 # It will replace all content after the __DATA__ in the right order with
6 # the files content stored into the resources/min/ directory.
7 #
8 # This script must be executed from the main source repository as follow:
9 # 
10 # This script must be executed from the main source repository as follow:
11 #  ./tools/updt_embedded_rsc.pl
12 #
13 # The fontawesome.css must also embedded the TrueType font, this is done
14 #-----------------------------------------------------------------------------
15 use strict;
16
17 my $RSC_DIR = 'resources';
18 my $PGBADGER_PROG = 'pgbadger';
19 my $DEST_TMP_FILE = 'pgbadger.new';
20
21 # Ordered resources files list
22 my @rsc_list = qw(jquery.jqplot.css jquery.js jquery.jqplot.js jqplot.pieRenderer.js jqplot.barRenderer.js jqplot.dateAxisRenderer.js jqplot.canvasTextRenderer.js jqplot.categoryAxisRenderer.js jqplot.canvasAxisTickRenderer.js jqplot.highlighter.js jqplot.highlighter.js jqplot.cursor.js jqplot.pointLabels.js bean.js underscore.js bootstrap.css fontawesome.css bootstrap.js pgbadger_slide.js pgbadger.css pgbadger.js);
23 my @min_rsc_list = ();
24
25 if (!-d $RSC_DIR) {
26 die "FATAL: can't find directory: $RSC_DIR.\n";
27 }
28
29 # Apply patch on jquery.jqplot.js to fix infinite loop
30 # May be removed with next jqplot release update
31 `patch -r - -s -N resources/jquery.jqplot.js -i resources/patch-jquery.jqplot.js`;
32
33 # Generate all minified resources files
34 mkdir "$RSC_DIR/min";
35 foreach my $f (@rsc_list) {
36 my $dest = $f;
37 $dest =~ s/\.(js|css)$/.min.$1/;
38 push(@min_rsc_list, $dest);
39 # minify resources files
40 `yui-compressor $RSC_DIR/$f -o $RSC_DIR/min/$dest`;
41 }
42
43 # Embedded fontawesome webfont into the CSS file as base64 data
44 print `base64 -w 0 $RSC_DIR/font/FontAwesome.otf > $RSC_DIR/font/FontAwesome.otf.b64`;
45 open(IN, "$RSC_DIR/font/FontAwesome.otf.b64") or die "FATAL: can't open file $RSC_DIR/font/FontAwesome.otf.b64, $!\n";
46 my $b64_font = <IN>;
47 close(IN);
48
49 # Update minimized fontawesome.css file
50 open(IN, "$RSC_DIR/min/fontawesome.min.css") or die "FATAL: can't open file $RSC_DIR/min/fontawesome.min.css\n";
51 my @content = <IN>;
52 close(IN);
53 open(OUT, ">$RSC_DIR/min/fontawesome.min.css") or die "FATAL: can't write to file $RSC_DIR/min/fontawesome.min.css\n";
54 foreach my $l (@content) {
55 $l =~ s|;src:url.* format.* format\('svg'\);|;src: url('data:font\/opentype;charset=utf-8;base64,$b64_font') format('truetype');|;
56 print OUT $l;
57 }
58 close(OUT);
59
60 if (!-e $PGBADGER_PROG) {
61 die "FATAL: can't find pgbadger script: $PGBADGER_PROG\n";
62 }
63
64 # Extract content of pgbadger script until __DATA__ is found
65 my $content = '';
66 open(IN, $PGBADGER_PROG) or die "FATAL: can't open file $PGBADGER_PROG, $!\n";
67 while (<IN>) {
68 last if (/^__DATA__$/);
69 $content .= $_;
70 }
71 close(IN);
72
73 # Write script base to destination file
74 open(OUT, ">$DEST_TMP_FILE") or die "FATAL: can't write to file $DEST_TMP_FILE, $!\n";
75 print OUT $content;
76 print OUT "__DATA__\n";
77
78 # Append each minified resources file
79 foreach my $f (@min_rsc_list) {
80 print OUT "\nWRFILE: $f\n\n";
81 open(IN, "$RSC_DIR/min/$f") or die "FATAL: can't open file $RSC_DIR/min/$f, $!\n";
82 my @tmp = <IN>;
83 close(IN);
84 print OUT @tmp;
85 }
86 close(OUT);
87
88 # Clobber original pgbadger file.
89 rename($DEST_TMP_FILE, $PGBADGER_PROG) or die "FATAL: can't rename $DEST_TMP_FILE into $PGBADGER_PROG\n";
90
91 exit 0;