summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--README3
-rw-r--r--data/script.js (renamed from static/f/script.js)0
-rwxr-xr-xutil/jsgen.pl24
-rwxr-xr-xutil/vndb.pl12
5 files changed, 40 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 2baf1a87..e2a730fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
/data/config.pl
/data/log/
+/static/f/script.js
/static/s/*/style.css
/static/s/*/boxbg.png
/static/cv/
diff --git a/README b/README
index 0ea41d8c..e62f0e06 100644
--- a/README
+++ b/README
@@ -52,6 +52,9 @@ Requirements
Image::Magick
CSS::Minifier::XS (optional, minimizes CSS output)
+ util/jsgen.pl
+ JavaScript::Minifier::XS (optional, minimizes JS output)
+
Contact
diff --git a/static/f/script.js b/data/script.js
index 07ad9866..07ad9866 100644
--- a/static/f/script.js
+++ b/data/script.js
diff --git a/util/jsgen.pl b/util/jsgen.pl
new file mode 100755
index 00000000..d21f56c7
--- /dev/null
+++ b/util/jsgen.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Cwd 'abs_path';
+eval { require JavaScript::Minifier::XS; };
+
+our($ROOT, %O);
+BEGIN { ($ROOT = abs_path $0) =~ s{/util/jsgen\.pl$}{}; }
+
+
+sub jsgen {
+ # JavaScript::Minifier::XS doesn't correctly handle perl's unicode,
+ # so just do everything in raw bytes instead.
+ open my $JS, '<', "$ROOT/data/script.js" or die $!;
+ my $js = join '', <$JS>;
+ close $JS;
+ open my $NEWJS, '>', "$ROOT/static/f/script.js" or die $!;
+ print $NEWJS $JavaScript::Minifier::XS::VERSION ? JavaScript::Minifier::XS::minify($js) : $js;
+ close $NEWJS;
+}
+
+jsgen;
+
diff --git a/util/vndb.pl b/util/vndb.pl
index ed74a92f..609d47a8 100755
--- a/util/vndb.pl
+++ b/util/vndb.pl
@@ -28,6 +28,10 @@ our(%O, %S);
$S{skins} = readskins();
+# automatically regenerate script.js when required and possible
+checkjs();
+
+
# load lang.dat
VNDB::L10N::loadfile();
@@ -113,3 +117,11 @@ sub readskins {
return \%skins;
}
+
+sub checkjs {
+ my $script = "$ROOT/static/f/script.js";
+ system "$ROOT/util/jsgen.pl" if
+ (!-e $script && -x "$ROOT/static/f")
+ || (-e $script && -w $script && [stat $script]->[9] < [stat "$ROOT/data/script.js"]->[9]);
+}
+