From 296dcdc148c40473ee48be93a9a8325ef947ea55 Mon Sep 17 00:00:00 2001 From: Nigel Metheringham Date: Sun, 4 Jul 2010 14:20:30 +0100 Subject: [PATCH 1/1] JS and CSS minify addition --- script/gen.pl | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/script/gen.pl b/script/gen.pl index c964689..4c545f5 100755 --- a/script/gen.pl +++ b/script/gen.pl @@ -1,9 +1,12 @@ #!/usr/bin/perl use strict; use warnings; +use CSS::Minifier::XS; use File::Copy; use File::Find; +use File::Slurp; use File::Spec; +use JavaScript::Minifier::XS; use XML::LibXML; use XML::LibXSLT; @@ -52,10 +55,21 @@ sub do_web { ## Skip if the file hasn't changed (mtime based) return if -f "$opt{docroot}/$path" && ( stat("$opt{tmpl}/web/$path") )[9] == ( stat("$opt{docroot}/$path") )[9]; - ## Copy - print "Copying to : docroot:/$path\n"; - copy( "$opt{tmpl}/web/$path", "$opt{docroot}/$path" ) or die "$path: $!"; - + if ( $path =~ /(.+)\.css$/ ) { + print "CSS to : docroot:/$path\n"; + my $content = read_file("$opt{tmpl}/web/$path"); + write_file( "$opt{docroot}/$path", CSS::Minifier::XS::minify($content) ); + } + elsif ( $path =~ /(.+)\.js$/ ) { + print "JS to : docroot:/$path\n"; + my $content = read_file("$opt{tmpl}/web/$path"); + write_file( "$opt{docroot}/$path", JavaScript::Minifier::XS::minify($content) ); + } + else { + ## Copy + print "Copying to : docroot:/$path\n"; + copy( "$opt{tmpl}/web/$path", "$opt{docroot}/$path" ) or die "$path: $!"; + } ## Set mtime utime( time, ( stat("$opt{tmpl}/web/$path") )[9], "$opt{docroot}/$path" ); } -- 2.30.2