summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-10-07 11:03:59 +0200
committerYorhel <git@yorhel.nl>2009-10-07 11:22:37 +0200
commite0161bd219a3004a3affdecd04d54a85f5cf9e1d (patch)
tree1761fcb2d6c9f5b76dabef82083221e9147eeaca /util
parentbafb8b134744cba74a3a019fefb36091b0e19d13 (diff)
JS: Moved script.js to data/ and added jsgen.pl to process it
While this 'processing' is currently limited to minifying the file if JavaScript::Minifier::XS is available, this change would make it a lot easier to make the strings in the JS code translatable.
Diffstat (limited to 'util')
-rwxr-xr-xutil/jsgen.pl24
-rwxr-xr-xutil/vndb.pl12
2 files changed, 36 insertions, 0 deletions
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]);
+}
+